ggplot2 を使用して日付形式で軸の目盛りを回転させる方法を知っている人はいますか? x 軸の角度が 45° の "Date-Month" (例: "1985-5") のラベルを取得したいと考えています。
データサンプル:
Station Date Ptot
A 1980-02 16
A 1980-03 19
A 1980-04 40
A 1980-05 48
A 1980-06 NA
A 1980-07 18.5
A 1980-08 24.6
B 1980-07 50.8
B 1980-08 28.9
B 1980-09 32.9
B 1980-10 47.9
B 1980-11 16.3
私はこれを試しました:
library(ggplot2)
library(scales)
plot <- ggplot(data=na.omit(data), aes(x=Date, y=Ptot, group=Station))+
geom_line()+
facet_grid(Station~.)+
scale_x_date(breaks = "year", labels=date_format("%Y-%m"))+
xlab("Year")+
ylab("Prec (mm)")+
labs(colour = "Station")+
theme(axis.text.x = element_text(angle = 45, hjust = 1))+
theme_bw()
plot
しかし、うまくいきません。
ありがとう!