没有人知道如何使用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
,但它不工作。
谢谢!
你必须提供比数据较好的可重复的例子,你的完整代码。 – Arun 2013-04-05 16:12:44
好吧,我只是改善了问题的细节... – user2165907 2013-04-05 16:30:25
检查@Didzis'编辑他在'Date'列解释问题的地方。 – Arun 2013-04-05 16:44:40