Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with legend.position = "bottom" #7

Open
lukelich opened this issue Jan 8, 2022 · 3 comments
Open

Problem with legend.position = "bottom" #7

lukelich opened this issue Jan 8, 2022 · 3 comments

Comments

@lukelich
Copy link

lukelich commented Jan 8, 2022

Hi,
when I try using legend.position = "bottom", as shown in your vignette, the legend keeps staying vertical at the bottom with some weird dimension (image attached).
Rplot01
I'm using ggcorrplot2_0.1.1, ggplot2_3.3.5, RColorBrewer_1.1-2.
This example shows what happens:

library(ggcorrplot2)
data(mtcars)
library(psych)
ct <- corr.test(mtcars, adjust = "none")
corr <- ct$r
ggcorrplot(corr) + 
theme( legend.position = "bottom")

I think I worked out the problem, in scale_fill_graidientn (and colour)

scale_fill_gradientn(colours = col2(200), limits = c(-1, 1),
                                guide = guide_colorbar(
                                  title = "",
                                  nbin = 1000,
                                  ticks.colour = "black",
                                  frame.colour = "black",
                                  barwidth = 1.5,
                                  barheight = 15))

barwidth and barheight are hindering any changes to the legend. Thus, when I try to flip it, it keeps barheight = 15 making that strange legend. Just removing those two lines fixed the problem.

Luca

@LDSamson
Copy link
Contributor

LDSamson commented May 7, 2022

Note that it is also possible to change the legend width and height within the theme() function:

theme(legend.position = ..., legend.key.height = .., legend.key.width =..)

@caijun would you be interested in adding an option 'legend.position' in the function ggcorrplot that addresses this? I tried it out on a local branch on my pc already, if you want I can upload that version somewhere next week.

@caijun
Copy link
Owner

caijun commented May 7, 2022

LDSamson As the function ggcorrplot() returns a ggplot2 object, the legend can be customized by overriding the scale_fill_gradientn(). I think @lukelich has found the solution. I prefer not to exposure too many parameters in the function, which will increase the diffculity in usage. I am more interested in this issue.

@LDSamson
Copy link
Contributor

I can understand that you want to keep the package as simple as possible, with not too many parameters in the function, I think that is a good design choice.

Just a thought: another option would be to leave out the barwidth and barheight parameters so that the ggcorrplot legend is a bit more flexible. The script would be less complex and adding theme(legend.position = "bottom/top/left/right") would behave as expected, and you can always add an option . But I also would understand if you would prefer the customized legend key size.

I will have a look at the other issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants