Showing multiple axis labels using ggplot2 with facet_wrap in R

前端 未结 2 386
面向向阳花
面向向阳花 2021-01-04 18:26

I\'ve got a nice facet_wrap density plot that I have created with ggplot2. I would like for each panel to have x and y axis labels instead of only having the y

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-04 18:50

    Short answer: You can't do that. It might make sense with 3 graphs, but what if you had a big lattice of 32 graphs? That would look noisy and bad. GGplot's philosophy is about doing the right thing with a minimum of customization, which means, naturally, that you can't customize things as much as other packages.

    Long answer: You could fake it by constructing three separate ggplot objects and combining them. But it's not a very general solution. Here's some code from Hadley's book that assumes you've created ggplot objects a, b, and c. It puts a in the top row, with b and c in the bottom row.

    grid.newpage()
    pushViewport(viewport(layout=grid.layout(2,2)))
    vplayout<-function(x,y)
        viewport(layout.pos.row=x,layout.pos.col=y)
    print(a,vp=vplayout(1,1:2))
    print(b,vp=vplayout(2,1))
    print(c,vp=vplayout(2,2))
    

提交回复
热议问题