【发布时间】:2013-03-28 03:22:06
【问题描述】:
有谁知道如何使用 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
但它不起作用。
谢谢!
【问题讨论】:
-
您必须提供比数据和完整代码更好的可重现示例。
-
好的,我只是改进了问题中的细节......
-
检查@Didzis 的编辑,他解释了您的
Date列的问题。