代碼
df<-read.table("clipboard",header = T)
df
errorbar_up<-function(x){
mean(x)+sd(x)
}
errorbar_down<-function(x){
mean(x)-sd(x)
}
library(ggplot2)
library(ggsignif)
ggplot(data=df,aes(x,y))+
stat_summary(geom = "bar",
fun=mean,
aes(fill=x))+
stat_summary(geom="errorbar",
fun.min = errorbar_down,
fun.max = errorbar_up,
width=0.2)+
geom_signif(comparisons = list(c("A","B"),
c("A","D"),
c("B","D")),
test = 't.test',
y_position = c(10,17,16),
map_signif_level = T)+
scale_y_continuous(expand = c(0,0),limits = c(0,18))+
theme_bw()+
scale_fill_manual(values = c("steelblue",
"yellowgreen",
"violetred1"))+
theme(legend.title = element_blank())+
labs(x="AAAAA",
y="BBBBB",
title = "CCCCC",
caption = "DDDDD")+
theme(panel.grid = element_blank())
數(shù)據(jù)
之前自己都是先把數(shù)據(jù)算好阵苇,然后用ggplot2作圖事扭,最近在學(xué)stat系列的函數(shù)啤斗,可以試著直接用原始數(shù)據(jù)來畫圖了棉饶,這樣方便很多
歡迎大家關(guān)注我的公眾號
小明的數(shù)據(jù)分析筆記本
小明的數(shù)據(jù)分析筆記本 公眾號 主要分享:1厦章、R語言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡單小例子;2照藻、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)袜啃、基因組學(xué)、群體遺傳學(xué)文獻(xiàn)閱讀筆記幸缕;3群发、生物信息學(xué)入門學(xué)習(xí)資料及自己的學(xué)習(xí)筆記!