[英]How to make a density plot in ggplot2 with dates on the x-axis
我有一个数据帧df
,其列time
包含R日期对象,我想绘制一个密度图,以查看哪些日期的活动最多。 我不想转换为时间戳,因为我更喜欢x轴上更有意义的标签。
我的尝试
这是我正在尝试的:
ggplot(df, aes(x = time)) + geom_density(stat="identity") + scale_x_date()
这给出了错误
Error in as.environment(where) : 'where' is missing
这是dput(df)
的输出:
structure(list(time = structure(c(15863, 15887, 15865, 15873, 15885, 15878), class = "Date")), .Names = "time", row.names = 8831395:8831400, class = "data.frame")
出于某种原因,stat_density的参数导致ggplot在设置的环境中失去方向。 (至少那是“where”缺失错误的来源。)这成功了:
ggplot(df, aes(x = time)) + geom_density()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.