Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

r - Is it yet possible to have different axis breaks / limits for individual facets in ggplot with free scale?

I saw that this related question was asked in 2010 (titled: How do you set different scale limits for different facets?) and would like to know if it is yet possible to have different breaks for different facets?

The reason being is that I want only integer values in the lower chart (with breaks of 50 for the top chart) of following plot: enter image description here

Code to reproduce the image:

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))
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First, your code doesn't produce the same plot as on my machine. Can you provide the sessionInfo()?

I don't think it is possible. Best approximation of your request I could achieve 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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...