[英]ggplot2 dates x-axis
我正在绘制x轴上带有日期的每月时间序列(dat1,其中包含冷列)。 该日期定义为每月一次:
seq(as.Date("1936/01/01"), as.Date("2013/01/01"), by="months")
使用生成图时
g=ggplot(data=dat1, aes(x=date, y=cold))+ geom_line()+ scale_x_date()
我在x轴上获取的日期是1940、1960、1980,...直到2000年,我想知道是否可以在1940到2010年之间每10年获取一次x轴上的日期。
如何在X轴上更改日期?
在?scale_x_date
帮助页面上:
breaks One of: NULL for no breaks waiver() for the default breaks computed by the transformation object A numeric vector of positions A function that takes the limits as input and returns breaks as output
x轴的日期标签,从1940年到2000年(含):
dat1 <- data.frame(
cold = rep(c(0,25,14,18,22),925/5),
date = seq(as.Date("1936/01/01"), as.Date("2013/01/01"), by="months"))
ggplot(data=dat1, aes(x=date, y=cold))+
geom_line()+
scale_x_date(breaks = seq(dat1$date[lubridate::year(dat1$date)=="1940"][1],
dat1$date[lubridate::year(dat1$date)=="2000"][1],
by="10 years"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.