微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

facet_wrap() 不是通过与 geom_rect() 崩溃来绘制的

如何解决facet_wrap() 不是通过与 geom_rect() 崩溃来绘制的

我正在尝试绘制植物的生长曲线。但我想用不同颜色的 geom_rect() 突出显示不同的阶段。我的代码在全部放在一起时会这样做,但是当用 facet_wrap() 将它们分开时,我收到 aes() 错误,有人可以看看它并提出建议吗?

错误:Aesthetics 必须是长度为 1 或与数据相同 (9):填充 运行 rlang::last_error() 以查看错误发生的位置。

Code Output -> Looking for this

代码

Growth_Phase = data.frame(Begin_x=c(0,5,21),End_x=c(5,21,50),Begin_y=c(-Inf,-Inf,-Inf),End_y=c(Inf,Inf,Inf),Period_Label=c("Dark \nGermination","Nursery","Farm"))

Plant_Height = ggplot() + theme_bw() +
  facet_wrap(~Cultivar,nrow=3) +
  geom_rect(data=Growth_Phase,mapping=aes(xmin=Begin_x,xmax=End_x,ymin=Begin_y,ymax=End_y),fill=c("gray","light blue","light green"),color="black",alpha=0.3) +
  stat_summary(Plant_Development,mapping=aes(x=Day,y=Height,group=Type),fun.data=mean_se,geom = "errorbar",size=1,width = 1,na.rm = T) +
  stat_summary(Plant_Development,colour=Type),fun="mean",geom = "line",geom = "point",size=2,shape=16,na.rm = T) +
  geom_label(data=Growth_Phase,aes(x=Begin_x+(End_x-Begin_x)/2,y=18,label=Period_Label),size=3,fontface = "bold") +
  scale_x_continuous(breaks=seq(0,50,5),limits=c(0,50)) + 
  scale_y_continuous(breaks=seq(0,20,20)) + 
  labs(title = "Average plant height",x="Day",color = "",y = "Plant Height (cm)",caption = "Cesar figueroa Lopez") +
  theme(title = element_text(size=18),axis.title.y = element_text(size=18),axis.text.y = element_text(size=18),axis.title.x = element_text(size=18),axis.text.x = element_text(size=18),legend.text = element_text(size=18),legend.title = element_text(size=18),legend.position = "bottom",strip.text = element_text(size=20))
Plant_Height

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。