use ggpairs to create this plot

后端 未结 1 499
野的像风
野的像风 2020-11-30 04:32

I have some code in a Shiny app that produces the first plot below. As you can see the font size varies with the size of the correlation coefficient. I would like to produce

相关标签:
1条回答
  • 2020-11-30 04:59

    Edit for GGally 1.0.1

    Since params is now deprecated, use wrap like so:

    ggpairs(df[, 1:2], 
            upper = list(continuous = wrap("cor", size = 10)), 
            lower = list(continuous = "smooth"))
    

    Original answer

    Customization of complicated plots is not always available through parameter list. That's natural: there are way too many parameters to keep in mind. So the only reliable option is to modify the source. This is especially pleasant when the project is hosted on github.

    Here's a simple modification to start with, made in a forked repo. The easiest way to update the code and produce the plot below is to copy and paste the function ggally_cor to your global environment, then override the same function in the GGally namespace:

    # ggally_cor <- <...>
    assignInNamespace("ggally_cor", ggally_cor, "GGally")
    ggpairs(df[, 1:2], 
            upper = list(params = c(size = 10)), 
            lower = list(continuous = "smooth"))
    

    enter image description here

    I removed the text label and added significance indicators. Modifying colour and size is not that easy, though, since these are mapped earlier. I'm still thinking on it, but you get the idea and may move on with your further customizations.

    Edit: I've updated the code, see my latest commit. It now maps size of the label to the absolute value of the correlation. You can do similar thing if you want different colour, though I think this is probably a not very good idea.

    enter image description here

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