In a faceted histogram in ggplot2 (see attached) and I want to change the x and y axes breaks at different intervals on individual facets.
DemographicsSimPatients %>%
keep(is.numeric) %>%
gather() %>%
ggplot(aes(value, fill = key)) +
facet_wrap(~ key, scales = "free") +
geom_histogram(bins=10)+
labs(title = "SimPatient Demographics",
y= "Number of Simulated Patients",
x="") +
theme(legend.position = "none")
UPDATE: thank you @stefan for showing me the ggh4x package, however can you please help I don't know how to change both x and y scales: I can only do one at a time and won't let me combine both:
scales <- list(
scale_x_continuous(breaks = c(20, 30, 40, 50, 60, 70)),
scale_x_continuous(breaks = c(0, 50, 100, 150, 200, 250, 300)),
scale_x_continuous(breaks = c(0, 40, 80, 120, 160, 200)),
scale_x_continuous(breaks = c(1, 1.5, 2, 2.5, 3, 3.5, 4)),
scale_x_continuous(breaks = c(120, 130, 140, 150)),
scale_x_continuous(breaks = c(40, 50, 60, 70, 80))
)
FIGURE2 <- FIGURE1 + facet_wrap(vars(key), scales = "free_x") +
facetted_pos_scales(x = scales)
But now I want to addd the following scales to the y axis but don't know how to combine them into one graph?:
scales <- list(
scale_y_continuous(breaks = c(0,25000)),
scale_y_continuous(breaks = c(0,50000)),
scale_y_continuous(breaks = c(0,100000)),
scale_y_continuous(breaks = c(0,75000)),
scale_y_continuous(breaks = c(0,60000)),
scale_y_continuous(breaks = c(0,80000))
)
UPDATE2: Thank you @teunbrand for solving this for me. Last query is how do I add 2 intercepts that are only in my last facet? (on my last facet)? Thank you again. Thank you in advance