在两年之间删除没有数据的日期
我有2021年和2022年的三个月(3月至5月)的平均温度数据,但是当我尝试在GGPLOT中绘制它并在数年之前将其绘制时,它仍然包括2021年6月至2022年2月至2月,在中间留下了一个大空白。图形。我当前的代码看起来像这样:
climate %>%
ggplot(aes(x = Date, y = `Mean Temp (C)`)) +
geom_line(aes(color = Year)) +
facet_grid(. ~ Year)
给出了:
我如何打破X轴以使其在2021年5月底结束并在2022年3月初再次开始?我尝试过(愚蠢地删除)各种版本的scale_x_break
,scale> scale_x_date
和xlim
,但似乎无法使其工作。
旁注:是否有这样的原因在传奇中显示一年?年份专栏仅具有“ 2021”或“ 2022”。
I have three months (March-May) of mean temperature data for years 2021 and 2022, but when I try to plot it in ggplot and separate it by years it still includes June 2021-February 2022 leaving a large blank in the middle of the graph. My current code looks like this:
climate %>%
ggplot(aes(x = Date, y = `Mean Temp (C)`)) +
geom_line(aes(color = Year)) +
facet_grid(. ~ Year)
which gives this:
How can I break the x-axis so that it ends at the end of May 2021 and starts again at the beginning of March 2022? I have tried (and stupidly deleted) various versions of scale_x_break
, scale_x_date
, and xlim
but can't seem to get it to work.
Side note: is there a reason it displays year that way in the legend? The year column only has "2021" or "2022".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
facet_grid
中使用scales =“ free_x”
:output
data
You can use
scales="free_x"
withinfacet_grid
:Output
Data