繁体   English   中英

如何在ggplot2中的facet_wrap函数上指定时间间隔轴?

[英]How does one specify time interval axis on facet_wrap function in ggplot2?

我正在使用此软件包进行数据分析: https : //cran.r-project.org/web/packages/wq/vignettes/wq-package.html

和用于plotTs的部分使用facet_wrap功能在GGPLOT2,示例有自动5年的时间间隔击穿。 我的数据只有17年,所以我的间隔对于5年的情节是非常无用的。 第一年是1996年,最后一个是2013年,那么是否要具体说明我的案例的间隔时间?

plotTs(y[, 1:4], dot.size = 1.3, ylab = "Chlorophyll in San Francisco Bay",
      strip.labels = paste("Station", 21:24), ncol = 1, scales = "free_y")

由于wq使用ggplot2,因此可以使用scale_x_date() 考虑一下:

data(sfbay)
sfb <- wqData(sfbay, c(1, 3:4), 5:12, site.order = TRUE,
               type = "wide", time.format = "%m/%d/%Y")

y <- tsMake(sfb, focus = "chl", layer = c(0, 5))
y[1:4, ]
plotTs(y[, 1:4], dot.size = 1.3, ylab = "Chlorophyll in San Francisco Bay",
       strip.labels = paste("Station", 21:24), ncol = 1, scales = "free_y") + 
scale_x_date(date_breaks = "7 years", date_labels = "%Y")

您可以使用date_breaks()date_labels 有关scale_x_date()更多信息,请参见http://docs.ggplot2.org/current/scale_date.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM