Plotting discrete and continuous scales in same ggplot

前端 未结 3 1135
一整个雨季
一整个雨季 2021-02-19 22:59

I would like to plot some different data items using ggplot2, using two different colour scales (one continuous and one discrete from two different df\'s). I can plot either exa

3条回答
  •  情书的邮戳
    2021-02-19 23:34

    You can do this. You need to tell grid graphics to overlay one plot on top of the other. You have to get margins and spacing etc, exactly right, and you have to think about the transparency of the top layers. In short... it's not worth it. As well as possibly making the plot confusing.

    However, I thought some people might like a pointer on how to acheive this. N.B. I used code from this gist to make the elements in the top plot transparent so they don't opaque the elements below:

    grid.newpage()
    pushViewport( viewport( layout = grid.layout( 1 , 1 , widths = unit( 1 , "npc" ) ) ) ) 
    print( p1 + theme(legend.position="none") , vp = viewport( layout.pos.row = 1 , layout.pos.col = 1 ) )
    print( p2 + theme(legend.position="none") , vp = viewport( layout.pos.row = 1 , layout.pos.col = 1 ) )
    

    See my answer here for how to add legends into another position on the grid layout.

    enter image description here

提交回复
热议问题