How can I change the number of breaks of x axis for each graph individually for each facet in a facet_grid? I would like to modify the x-axis separately for each facet. I have tried with scale_x_continuos(breaks =..., n.breaks = ...) but I can't. I also removed the theme_set(theme_paleo(8)) with theme_replace and tried with theme(axis.x.text =, axis.ticks =, etc etc) but without positive result, anyone who can help me please.
This is the example for stratigraphic diagrams in this link: https://cran.r-project.org/web/packages/tidypaleo/vignettes/strat_diagrams.html
Code:
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
CodePudding user response:
One option is the ggh4x
package which via facetted_pos_scales
allows to set the scales individually for each facet. In the code below I use facetted_pos_scales
to set the breaks for the first and the third facet, while for all other facets the default is used (NULL
).
Note 1: facetted_pos_scales
requires to the free the x scale via scales="free_x"
.
Note 2: To make facetted_pos_scales
work with scale_y_reverse
I had to move scale_y_reverse
inside facetted_pos_scales
too.
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()
)
)