This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 3.2.2
#setting work dir
setwd("D:/RData/boxplot/headCircum")
data = read.table("data.txt",head=T,sep = "\t")
getP = function(df,level){
x = df[df$class==level[1],1]
for(i in 2:length(level)){
data = df[df$class==level[i],1]
print(paste(level[i], wilcox.test(x, data)$p.value, sep = " : "))
}
}
levels = sort(unique(data$class))
#calculate the P value
getP(data, levels)
## [1] "Mac-DNM : 5.48339286048554e-05"
## [1] "Mac-rare : 0.931437227873241"
## [1] "Mic-DNM : 0.365602449046511"
## [1] "Mic-rare : 0.112435047464225"
#countint the number of each class
for(i in levels){
print(paste(i, nrow(data[data$class==i, ]), sep = " : "))
}
## [1] "background : 2317"
## [1] "Mac-DNM : 10"
## [1] "Mac-rare : 20"
## [1] "Mic-DNM : 12"
## [1] "Mic-rare : 63"
Here is my code for plotting:
ggplot(data,aes(factor(class), zscore, fill=factor(class)))+
geom_boxplot()+
scale_y_continuous(limits=c(-5,5))+
theme(axis.title = element_blank(),
axis.text = element_text(size = 14,color = "black"),
axis.ticks = element_line(colour = "black"),
axis.ticks.x = element_blank(),
legend.position = "top",
panel.grid = element_blank(),
panel.background = element_rect(fill = "white",colour = "black"),
legend.key = element_rect(fill = "white"),
legend.title = element_blank())
## Warning: Removed 28 rows containing non-finite values (stat_boxplot).