Hi,
I am trying to make a box plot with the following codes.
NDVI_ts <- read.table("merge_2_NC.csv", header = TRUE)
NDVI_ts
library(ggplot2)
library(scales)
library(tidyverse)
library(ggpubr)
NormalvsCancer<-interaction(NDVI_ts$Data, sep="\t")
######Outfile name as input file
pdf("boxplot.pdf")
##########
xlabs <- paste(levels(NDVI_ts$Data),"\n(N=",table(NDVI_ts$Data),")",sep="")
#ggplot(df,aes(x=group,y=x,color=group))+geom_boxplot()+scale_x_discrete(labels=xlabs)
p2 = ggplot(NDVI_ts, aes(x=NormalvsCancer, y=Read_count)) +
geom_point(aes(fill=NormalvsCancer), size=5, shape=21, colour="grey20",
position=position_jitter(width=0.2, height=0.1)) +
geom_boxplot(aes(fill = Data), width = 0.6, outlier.colour=NA, fill=NA) +
scale_x_discrete(labels=xlabs) +
theme_bw() + theme(axis.text.x = element_text(angle = 360, hjust = 1)) +
stat_compare_means(aes(group = Data), label = "p.format")
print(p2)
dev.off()
I am getting the output image like this:
Everything is ok except in bladder_normal(19). Here N=0, whereas it is showing 1.
The csv input file is this.
Data No_matched Read_count
Bladder_tumor(414) 1 2
Bladder_tumor(414) 1 1
Bladder_tumor(414) 1 1
Bladder_tumor(414) 1 1
Bladder_tumor(414) 1 1
Bladder_tumor(414) 1 1
Bladder_tumor(414) 1 10
Bladder_tumor(414) 1 24
Bladder_tumor(414) 1 3
Bladder_tumor(414) 1 8
Bladder_tumor(414) 1 1
Bladder_tumor(414) 1 2
Bladder_tumor(414) 1 1
Bladder_tumor(414) 1 2
Bladder_tumor(414) 1 1
Bladder_tumor(414) 1 1
Bladder_tumor(414) 1 1
Bladder_normal(19) 0 0
Any help is much appreciated.
Thanks
Changed the link to display the image properly. What is the actual question now, I do not really get it?
OP is bypassing
factor
s using a logic doesn't make sense to me. OP, instead oftry
Even better, split the first column into two columns (category and count) so you're dealing with atomic data.
Ok, thanks. I will try this.
I want to get the count of normal and tumor samples as N. If the number of matched with N is "0" then it should get reflected that Bladder normal(19) N=0 and tumor N=17.
I think you have the header wrong, shouldn't it be NormalvsCancer. Anyhow, N=1 means one sample
Actually, there is no normal sample but I want to show the number of normal sample is "0".
Your xlabs don't match up with the actual data. Split the first column so you have a clean data.frame and build the axis labels in a better manner.
I got lost.
table(NDVI_ts$Data)
shouldn't return 1 forBladder_normal(19)
?It does and should because
table
does simply quantifies characters :)I don't understand the use of
NormalvsCancer<-interaction(NDVI_ts$Data, sep="\t")
Why don't you just use Data? interaction function returns unordered values and is irrelevant here.Thanks for pointing it out. I will correct it.