[英]How can I change the number of breaks of x axis for each graph individually for each facet in a facet_grid in R?
如何为 facet_grid 中的每个构面单独更改每个图形的 x 轴中断数? 我想为每个方面分别修改 x 轴。 我试过 scale_x_continuos(breaks =..., n.breaks = ...) 但我不能。 我还使用 theme_replace 删除了 theme_set(theme_paleo(8)) 并尝试使用 theme(axis.x.text =, axis.ticks =, etc etc) 但没有积极的结果,请任何可以帮助我的人。
这是此链接中地层图的示例: https ://cran.r-project.org/web/packages/tidypaleo/vignettes/strat_diagrams.html
代码:
library(tidyverse)
library(tidypaleo)
theme_set(theme_paleo(8))
data("alta_lake_geochem")
alta_lake_geochem
alta_plot <- ggplot(alta_lake_geochem, aes(x = value, y = depth)) +
geom_lineh() +
geom_point() +
scale_y_reverse() +
facet_geochem_gridh(vars(param)) +
labs(x = NULL, y = "Depth (cm)")
alta_plot
一个选项是ggh4x
包,它通过facetted_pos_scales
允许为每个方面单独设置比例。 在下面的代码中,我使用facetted_pos_scales
设置第一个和第三个方面的中断,而对于所有其他方面,使用默认值 ( NULL
)。
注 1: facetted_pos_scales
需要通过scales="free_x"
释放 x 比例。
注意 2:为了使facetted_pos_scales
与scale_y_reverse
一起工作,我也必须将facetted_pos_scales
移动到scale_y_reverse
内。
library(tidyverse)
library(tidypaleo)
library(ggh4x)
theme_set(theme_paleo(8))
data("alta_lake_geochem")
ggplot(alta_lake_geochem, aes(x = value, y = depth)) +
geom_lineh() +
geom_point() +
facet_geochem_gridh(vars(param), scales = "free_x") +
labs(x = NULL, y = "Depth (cm)") +
facetted_pos_scales(
x = list(
scale_x_continuous(breaks = 1:8),
NULL,
scale_x_continuous(n.breaks = 10),
NULL
),
y = list(
scale_y_reverse()
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.