2017-09-03 154 views
0

繪製折線圖時,我對x軸有問題。如下圖所示,我的標籤太多了。ggplot2中的縮放x軸

Line graph

我嘗試只包括使用seq()一些標籤來補救方案,但我會遇到這樣的錯誤:

ggplot(df, aes(x = date, y = measure, group = 1)) + 
    geom_line() + 
    theme_bw() + 
    theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) + 
    xlab("X-Axis") + 
    ylab("Y-Axis") + 
    scale_x_continuous(breaks = round(seq(min(df$date), max(df$date), by = 221.2), 1)) 

#> Error in seq.default(min(df$date), max(df$date), : 
#> 'from' must be a finite number 
#> In addition: Warning message: 
#> In seq.default(min(df$date), max(df$date), : 
#> NAs introduced by coercion 

有什麼建議?如果有幫助,df$date被認爲是一個角色。也許,我應該將其轉換爲數字或作爲日期時間?

+1

請提供用於生產該地塊您'df' – useR

回答