简体   繁体   English

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

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

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

And the section for plotTs uses facet_wrap function in ggplot2 , the example has a 5 year interval breakdown on automatic. 和用于plotTs的部分使用facet_wrap功能在GGPLOT2,示例有自动5年的时间间隔击穿。 My data is only 17 years, so my intervals are very useless with 5 year plots. 我的数据只有17年,所以我的间隔对于5年的情节是非常无用的。 First year is 1996 and last 2013, so is there to specify the breakdown of intervals specific to my case? 第一年是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")

Since wq is using ggplot2, you could use scale_x_date() . 由于wq使用ggplot2,因此可以使用scale_x_date() Consider this: 考虑一下:

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")

you can play with date_breaks() and date_labels . 您可以使用date_breaks()date_labels For more information on scale_x_date() see http://docs.ggplot2.org/current/scale_date.html 有关scale_x_date()更多信息,请参见http://docs.ggplot2.org/current/scale_date.html

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

相关问题 如何在 ggplot2 中使用 facet_wrap(~day) 设置轴每日时间限制 - How to set axis daily time limits with facet_wrap(~day) in ggplot2 如何在函数中编写 facet_wrap (ggplot2) - How to write a facet_wrap (ggplot2) within a function ggplot2:如何在facet_wrap中为每个构面分别设置轴断点? - ggplot2: How can I set axis breaks separately for each facet in facet_wrap? 为 facet_wrap (ggplot2) 中的每个图指定不同的 xlim - specify different xlim for each plot in facet_wrap (ggplot2) 使用 ggplot2 和 facet_wrap 显示不同的轴标签 - Showing different axis labels using ggplot2 with facet_wrap R ggplot2 facet_wrap 中的 x 轴标签 - R ggplot2 x-axis labels in facet_wrap R ggplot2:如何根据带有 facet_wrap 的变量的值命名 y 轴? - R ggplot2: How can I name the y axis depending on the value of a variable with facet_wrap? ggplot2 每个面线具有不同 y 轴的面:如何从 facet_grid 和 facet_wrap 中获得“最佳”? - ggplot2 facets with different y axis per facet line: how to get the "best" from both facet_grid and facet_wrap? 使用 facet_wrap ggplot2 时如何自动制作从 1 到 max(n) 的渐变轴 - How to automatically make an axis with a gradation from 1 to max(n) when using facet_wrap ggplot2 如何使用 facet_wrap 在 ggplot2 中包含所有 x 轴标签,包括缺失数据? - How to have all x-axis labels, including missing data, in ggplot2 with facet_wrap?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM