[英]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.