我很难让 x 轴看起来适合我的图表。
这是我的数据(通过生成dput()
):
df <- structure(list(Month = structure(1:12, .Label = c("2011-07-31", "2011-08-31", "2011-09-30", "2011-10-31", "2011-11-30", "2011-12-31", "2012-01-31", "2012-02-29", "2012-03-31", "2012-04-30", "2012-05-31", "2012-06-30"), class = "factor"), AvgVisits = c(6.98655104580674,7.66045407330464, 7.69761337479304, 7.54387561322994, 7.24483848458728, 6.32001400498928, 6.66794871794872, 7.207780853854, 7.60281201431308, 6.70113837397123, 6.57634103019538, 6.75321935568936)), .Names = c("Month","AvgVisits"), row.names = c(NA, -12L), class = "data.frame")
这是我要绘制的图表:
ggplot(df, aes(x = Month, y = AvgVisits)) +
geom_bar() +
theme_bw() +
labs(x = "Month", y = "Average Visits per User")
该图表工作正常 - 但是,如果我想调整日期的格式,我相信我应该添加这个:
scale_x_date(labels = date_format("%m-%Y"))
我正在努力使日期标签为“MMM-YYYY”
ggplot(df, aes(x = Month, y = AvgVisits)) +
geom_bar() +
theme_bw() +
labs(x = "Month", y = "Average Visits per User") +
scale_x_date(labels = date_format("%m-%Y"))
当我绘制它时,我继续收到此错误:
stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
geom_line
尽管对and的格式进行了数小时的研究geom_bar
,但我无法修复它。谁能解释我做错了什么?
编辑:作为后续想法:您可以使用日期作为一个因素,还是应该as.Date
在日期列上使用?