问题描述
我正在尝试在 facte_wrap 函数中注释第一个图,但它不起作用!我进行了搜索,但找不到导致我出错的答案。提前致谢:)
这是我的代码:
B<-read.csv(choose.files(),header=T)
site<-B[,1]
month<-B[,2]
density<-B[,3]
library(ggplot2)
library(lubridate)
date<-dmy( month,quiet = FALSE,tz = NULL,locale = Sys.getlocale("LC_TIME"),truncated = 0)
A<-ggplot(data = B,aes(x=date,y=density,group=date))+geom_boxplot(aes(fill=site))+theme_classic()+
theme(aspect.ratio=0.75)+facet_wrap(~site)+
theme(strip.background = element_blank(),strip.text.x=element_blank())+
stat_summary(fun=median,geom="point",size = 2.5,aes(shape = site))+
scale_x_date(date_labels = " %b")+labs(x = "\nMonth",y = bquote('Density'~(mg)))+
theme(axis.title.x = element_text(color = 'black',face = 'bold',size = 16,hjust = 0.5))+
theme(axis.title.y = element_text(color = 'black',size=18,hjust = 0.5))+theme(axis.text = font)+
theme(legend.title = element_blank(),legend.position="top",legend.text = element_text(color = "black",size=12))
A+annotate("text",x=as.Date("2016-04-01"),y = 4.5,label="(a)",fontface="bold",size=5)###
This is what works but annotate all plots
ann_text<-data.frame(x=as.Date("2016-04-01"),y = 4,lab="(a)",site=factor("Berke",levels=c("Hudson","Shirud","Berke")))
A+geom_text(data=ann_text,label="(a)")### this one gives me error
这是我的数据:
site Month density
Hudson 1.Apr.2016 0.586165468
Hudson 1.Apr.2016 0.226195982
Hudson 1.Apr.2016 3.614281059
Hudson 1.May.2016 0.527332108
Hudson 1.May.2016 3.029478971
Hudson 1.July.2016 0.563950688
Hudson 1.July.2016 0.261450446
Hudson 1.July.2016 0.418152365
Hudson 1.July.2016 0.15314951
Hudson 1.Aug.2016 0.203491674
Hudson 1.Aug.2016 0.085789449
Hudson 1.Aug.2016 0.377520862
Hudson 1.Aug.2016 0.255077678
Hudson 1.July.2016 0.180572753
Hudson 1.July.2016 0.120347364
Hudson 1.Sep.2016 0.111758245
Hudson 1.Sep.2016 0.174609039
Hudson 1.Sep.2016 0.10579666
Shirud 1.Apr.2016 2.886127158
Shirud 1.Apr.2016 1.22283898
Shirud 1.Apr.2016 1.005639192
Shirud 1.May.2016 0.371793341
Shirud 1.May.2016 1.333296278
Shirud 1.May.2016 2.040265903
Shirud 1.June.2016 0.584321457
Shirud 1.June.2016 4.65204552
Shirud 1.June.2016 2.629888197
Shirud 1.Aug.2016 0.57249892
Shirud 1.Aug.2016 1.541114492
Shirud 1.Aug.2016 0.833501986
Shirud 1.Sep.2016 0.853316575
Shirud 1.Sep.2016 0.148069366
Shirud 1.Sep.2016 0.173536413
Berke 1.June.2016 1.356025618
Berke 1.June.2016 0.391884409
Berke 1.June.2016 1.03214444
Berke 1.June.2016 0.235074894
Berke 1.July.2016 0.167735789
Berke 1.Aug.2016 3.782709228
Berke 1.Aug.2016 0.978743319
Berke 1.Aug.2016 4.558905703
Berke 1.Sep.2016 3.484025326
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)