different size facets proportional of x axis on ggplot 2 r

前端 未结 1 1638
耶瑟儿~
耶瑟儿~ 2020-11-28 11:44

The following is a situation:

group1 <- seq(1, 10, 2)
group2 <-  seq(1, 20, 3)
x = c(group1, group2)
mydf <- data.frame (X =x , Y = rnorm (length (x         


        
相关标签:
1条回答
  • 2020-11-28 12:10

    If I understand you correctly, space = "free_x" does what you want in facet_grid. As far as I know, facet_wrap has never supported a space argument, but many facet_wrap commands can be cast as facet_grid commands.

    library(ggplot2)
    
    ggplot(mydf, aes(X, Y)) + geom_point()+ 
    facet_grid (.~ groups, scales = "free_x", space = "free_x")
    

    enter image description here

    And if you want the same style of labelling on the x axes:

    ggplot(mydf, aes(X, Y)) + geom_point()+ 
     scale_x_continuous(breaks = seq(0,20,2)) +
     facet_grid (.~ groups, scales = "free_x", space = "free_x")
    

    enter image description here

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