2017-09-03 44 views
0

我似乎无法获得我需要在x轴上出现的所有日期。日期跨度从1996 - 2017年,但我只能让R显示2000 - 2015年。我对R相当陌生,对类似问题的其他答案没有多大帮助。将所有元素添加到x轴,R

breaks <- seq(1996,2017,1) 
with(gamePlot, hist(gamePlot$Date, breaks, 
         las=2, 
         col=rainbow(20), 
         xlim=c(1996,2017), 
         cex.axis=0.6, 
         xlab="Year Released", 
         main="Frequency of top rated games by year")) 

enter image description here

回答

0

尝试增加plot=TRUEhist

with(gamePlot, hist(gamePlot$Date, breaks, 
         las=2, 
         col=rainbow(20), 
         xlim=c(1996,2017), 
         plot=TRUE, 
         cex.axis=0.6, 
         xlab="Year Released", 
         main="Frequency of top rated games by year")) 
0

选项1(推荐):您ggplot转换日期列日期对象与as.Date(),然后用+ scale_x_date(date_labels = "", date_breaks = "")来使用参数date_labelsdate_breaks格式化日期。 See this for reference.

选项2:如果你要保持你的日期列作为一个整数向量(现在是这样的),你可以使用+ scale_x_discrete(limits = c(date1, date2, date3 ...)和参数limits指定休息。您可能必须将该int列转换为factor()的因子才能使其工作。 See this for reference.

相关问题