How do you set different scale limits for different facets?

前端 未结 2 1257
不思量自难忘°
不思量自难忘° 2020-12-10 10:25

Some sample data:

dfr <- data.frame(
  x = rep.int(1:10, 2),
  y = runif(20),
  g = factor(rep(letters[1:2], each = 10))
)

A simple scat

相关标签:
2条回答
  • 2020-12-10 11:05

    I don't think this is possible yet in ggplot2. This discussion from January suggests the issue is under consideration.

    0 讨论(0)
  • 2020-12-10 11:05

    To contract the scale on the left plot remove the points that lie outside the range. E.g. this will reduce the y scale on the right plot to values between 0 and 0.5:

    p <- ggplot(dfr, aes(x, y)) +   
         geom_point(subset=.(g == "a" | (y > 0 & y <.5))) +
         geom_blank(aes(y = ymin)) + geom_blank(aes(y = ymax)) +
         facet_wrap(~ g, scales = "free_y")
    

    See also my answer to this question.

    0 讨论(0)
提交回复
热议问题