[英]How to make a density plot in ggplot2 with dates on the x-axis
I have a dataframe df
with a column time
which contains R date objects and I want to plot a density plot to see which days had the most activity. 我有一个数据帧
df
,其列time
包含R日期对象,我想绘制一个密度图,以查看哪些日期的活动最多。 I don't want to convert to timestamps, because I would prefer more meaningful labels in the x-axis. 我不想转换为时间戳,因为我更喜欢x轴上更有意义的标签。
My attempt 我的尝试
Here is what I am trying: 这是我正在尝试的:
ggplot(df, aes(x = time)) + geom_density(stat="identity") + scale_x_date()
which gives the error 这给出了错误
Error in as.environment(where) : 'where' is missing
Here is the output of dput(df)
: 这是
dput(df)
的输出:
structure(list(time = structure(c(15863, 15887, 15865, 15873, 15885, 15878), class = "Date")), .Names = "time", row.names = 8831395:8831400, class = "data.frame")
For some reason the argument to stat_density is causing ggplot to lose its way among the environments that get set up. 出于某种原因,stat_density的参数导致ggplot在设置的环境中失去方向。 (At least that's where the "where" missing error comes from.) This succeeds:
(至少那是“where”缺失错误的来源。)这成功了:
ggplot(df, aes(x = time)) + geom_density()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.