2017-09-03 9 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は文字と見なされます。おそらく、私は数値に変換するか、datetimeにする必要がありますか?

+1

このプロットを生成するために使用されるあなたの 'df'を入力してください – useR

答えて

1

scale_x_continuousを削除します。あなたの日付が日付であることを確認してください。あなたはas.Date(date)でそれを行うことができます。下記の追加:

+ scale_x_date(date_breaks = "1 month") 

出典: http://ggplot2.tidyverse.org/reference/scale_date.html

関連する問題