Is it still possible to have different axial gaps / limits for individual faces in ggplot with a free scale?

I saw that this related question was asked in 2010 (titled: How do you set different scale borders for different faces? ) And would like to know, but different breaks are possible for different faces?

The reason is that I want to get only integer values ​​in the bottom chart (with breaks of 50 for the top chart) of the following chart: enter image description here

Code for image playback:

dat <- data.frame(date=seq(0, 729, 1), Var1=round(seq(from=0, length.out=730, by=0.2)), Var2=round(seq(from=5, length.out=730, by=0.01)) ) dat.m <- melt(dat, id.var="date") ggplot(dat.m, aes(date, value)) + scale_x_continuous(name="Time") + expand_limits(y=0) + ylab("Variable") + geom_step() + facet_grid(variable~., scales="free_y")+ scale_y_continuous(breaks = seq(0, 150, by = 1)) 
+1
source share
1 answer

Firstly, your code does not create the same plot as on my machine. Can you provide sessionInfo() ?

I do not think that's possible. I could achieve the best approximation of your request in a simple way:

 ggplot(dat.m, aes(date, value)) + scale_x_continuous(name="Time") + expand_limits(y=0) + ylab("Variable") + geom_step() + facet_grid(variable~., scales="free_y")+ scale_y_continuous(breaks = c(seq(0, 12, by = 2),seq(0, 150, by = 50))) 

enter image description here

+1
source

Source: https://habr.com/ru/post/1243946/


All Articles