2017-09-03 34 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.

相關問題