如何在R中获得将单个天和几个月合并为一年的图

问题描述 投票:0回答:1

我有一个看起来像这样的df:

'my_data':   365 obs. of  5 variables:
$ Day      : chr  "01" "02" "03" "04" ...
$ Month    : Factor w/ 12 levels "01","02","03",..: 1 1 1 1 1 1 1 1 1 1 ... [[[Range: 1 to 12]]]
$ Year     : chr  "2019" "2019" "2019" "2019" ...
$ XXX      : int  2 4 5 5 7 6 6 7 6 6 ... [[[Range: 1 to 9]]]
$ Weekday  : Factor w/ 7 levels "Monday","Tuesday",..: 2 3 4 5 6 7 1 2 3 4 ...

[目前,我正在尝试在ggplot中获得一张图表,该图表显示$ XXX的所有值在全年中均<= 3和> = 7。我如何定义日期适合各个月份,并且必须连续查看?

任何帮助将不胜感激,

谢谢!

r ggplot2 graph dplyr days
1个回答
0
投票

没有数据集的示例,很难确定要解决的问题是什么,可以使用lubridate并尝试:

library(lubridate)
my_data$Date_full <- ymd(paste(c(Year, Month, Day), sep = "-"))

对于绘图部分,您可以对数据集进行子集化:

library(ggplot2)
ggplot(subset(my_data, XXX =< 3 & XXX >= 7), aes(x = Date_Full, y = XXX))+
   geom_point()

它回答了您的问题吗?

如果不起作用,请提供您的数据集的可复制示例(请参见此链接:How to make a great R reproducible example

© www.soinside.com 2019 - 2024. All rights reserved.