r - 为 facet_wrap (ggplot2) 中的每个图指定不同的 xlim

标签 r ggplot2

那是我的代码:

ggplot(df, aes(Date, EC))+
  scale_x_date(labels= date_format("%Y"), breaks=date_breaks("year"))+
  geom_point(data=df2, aes(Date, EC), size=2, color="red")+ 
  geom_point()+
  geom_line()+
  xlab(NULL)+
  geom_smooth(method="lm", se=F)+
  facet_wrap(~ID, scales="free_y")+
  theme(axis.text.x = element_text(angle = 90))

这产生了这个结果(我知道这很丑陋,但仅举个例子):
enter image description here

我可以为 facet_wrap 中的每个图指定不同的 xlim(基于日期值)吗?如果我可以根据 min(df$Date) 指定 xlim,那就太好了。

我希望我说清楚了。

最佳答案

这应该解决。尝试一些广泛的数据:

data <- data.frame( grp=rep(c("one","two","three","four"), each=10),
                    x=1:40,
                    y=c( runif(10)*3,
                       ( runif(10)*30 )+10,
                       ( runif(10)*50 )+10,
                       ( runif(10)*10 )-10 ) )

ggplot( data, aes(x, y) ) +
              geom_point(  ) +
              geom_line( ) +
              geom_smooth( method = "loess" ) +
              facet_wrap( ~grp, scales="free" )
ggplot_facet_wrap_scale

关于r - 为 facet_wrap (ggplot2) 中的每个图指定不同的 xlim,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20682138/

相关文章:

r - 如何将数据子集绘制在与完整数据集相同的图表上?

r - 使用 kableExtra 调整长 table

r - 从 R markdown 内联代码中的 tibble 中提取值

r - 在 Shiny Dashboard 中设置标题/标题

r - 在 ggplot 中的 x 轴上显示工作日和时间

r - 如何在堆积条形图ggplot2上组织百分比值

r - 不要丢弃零计数 : dodged barplot

r - 使用cowplot将x和y laxis标签添加到ggplot-grid构建

r - ggplot 错误 : Don't know how to automatically pick scale for object of type function

r - ggplot误差条位置多因素问题