首页 > 解决方案 > 向构面添加阴影区域

问题描述

我对 R 真的很陌生,并试图自己学习它,但现在我被困在了一个地方。我试图在一个方面添加一个阴影区域,但它为每个方面添加了一个阴影区域。我只想强调从 2017-08-08 到 2017-08-16 的时间,但我不知道该怎么做。

我现在的代码如下所示:

ggplot(data = Andmed3, aes(x= Aeg, y = arch, group = Prooviala)) + 
  stat_summary(geom = "errorbar",fun.data = mean_se, aes(group = Prooviala, color = Prooviala)) + 
  stat_summary(fun = mean,geom="line",lwd=1,aes (group= Prooviala, color = Prooviala)) + 
  stat_summary(geom = "point", fun = mean, shape = 16, size = 2, aes(color = Prooviala)) + 
  facet_grid(~Periood, scales = "free_x", space = "free_x") + 
  labs(x = "Kuupäev", y = "Arhede 16S rRNA geenikoopiate arv")+ 
  theme_bw() +  
  theme(axis.text.x = element_text(angle = 30, hjust = 1)) + 
  scale_x_datetime(date_breaks = "1 week", date_labels = " %e %b %y") + 
  geom_rect(aes(xmin = as.POSIXct('2017-08-08', format = '%Y-%m-%d'),xmax = as.POSIXct('2017-08-16', format = '%Y-%m-%d'),ymin = -Inf,ymax = Inf), alpha = 0.2, fill = 'grey')

在此处输入图像描述

我需要我的图表看起来像我的第二张照片,但只有在第一个方面突出显示背景。

在此处输入图像描述

有人可以帮我写代码吗?

谢谢你!

标签: rggplot2

解决方案


推荐阅读