||
效果图:
# 操作实例-----------------------
dat1 <- read.csv("~/Tudat.csv")
View(dat1)
attach(dat1)
library(ggplot2) # install.packages("ggplot2")
p<-ggplot(data=dat1,aes(x=Gene,y=Ct,fill=grp))
p
# Keep only upper error bars
p+geom_bar(stat="identity", color="black", width = 0.6,position=position_dodge()) +
geom_errorbar(aes(ymin=Ct,ymax=Ct+SD), width=0.2, position=position_dodge(0.6)) ->q
q
# geom_errorbar(width=)表示误差棒的相对宽度
# geom_errorbar(position=position_dodge(0.6))中的0.6 需与
# geom_bar(width=)的取值一样,否则误差棒会错位
## Finished bar plot
# 更改barplot到x轴的距离为0
q+scale_y_continuous(expand = c(0, 0), limits = c(0,150),breaks = seq(0, 150,by=30))
# 改变legend的位置,box,title etc, 数值为相对值,从0到1
last_plot()+ theme(legend.position=c(0.1,0.9),legend.title = element_blank(),legend.background = element_rect(fill=NULL,size = 0.5,linetype = "solid",colour = "black"),panel.background = element_rect(fill = "white",colour="black"),panel.grid.major = element_blank(),panel.grid.minor = element_blank())
# 添加 xy轴labels和标题,添加文本,更改 标题位置为居中
last_plot()+ggtitle("Try mutil-y errorbar")+labs( x = "Gene(ser)",y='Ct(***)')+geom_text(aes(x="G7",y=140,label="(a)"))+theme(plot.title = element_text(hjust = 0.5))
# save tiff 300dpi
# 可能图片会乱码。最好直接保存Metafile to ppt
# 图形ok了
#以下附属内容,仅供参考
ggsave(filename = "Ct-Gene.test.tiff", width = 4,height = 4,dpi = 300)
#### If need, 将需要断y轴的High数据组,以分面facet_grid的形式代替。
last_plot()+facet_grid(~Mark,scale="free",space = "free")
# If need, 绘制x y轴线
last_plot()+theme(axis.line = element_line(color="black", size = 0.5))
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-22 15:11
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社