Grid.arrange(g4,g5,g6,nrow=3) #see picture below, left G6 <- gp2 + theme(legend.key = element_rect(size = 10)) G5 <- gp2 + theme(legend.key = element_rect(size = 3)) G4 <- gp2 + theme(legend.key = element_rect(size = 1)) #Notice that the legend symbol squares get bigger (that's what does). However, this doesn't work quite so well otherwise (e.g., if you need the grey background on your legend symbol): g1 <- gp + theme( = unit(0, 'lines')) G3bw <- gpbw + theme( = unit(3, 'lines')) G1bw <- gpbw + theme( = unit(0, 'lines')) This is real easy if you are using theme_bw(): gpbw <- gp + theme_bw() Gp <- ggplot(data = mtcars, aes(mpg, cyl, colour = factor(cyl))) + Looks like the best approach (in 2018) is to use under the theme object. Theme(legend.key = element_rect(color = NA, fill = NA), # the effect is global & persistent throughout the R session # this step is not needed anymore per tjebo's comment below See this issue for more info # function to increase vertical spacing between legend keys In order to increase the distance between legend keys, modification of the legend-draw.r function is needed. The below is obsolete, but is left for curious people.įor vertical legends, setting only increases the size of the legend keys, not the vertical space between them ggplot(mtcars) + Title.position = "left", title.vjust = 1, Guides(fill = guide_colorbar(title = "HP", Geom_point(aes(fill = hp), pch = I(21), size = 5)+ Title.position = "left", title.vjust = 1))Įxample: for scale_fill_xxx & guide_colorbar ggplot(mtcars, aes(mpg, wt)) + Guides(fill = guide_legend(title = "Cyl", Legend.text = element_text(margin = margin(t = 10))) + Guides(fill = guide_legend(byrow = TRUE))Įxample: Move the legend key labels to the bottom and increase vertical spacing ggplot(mtcars, aes(factor(cyl), fill = factor(cyl))) + Ggplot(mtcars, aes(y = factor(cyl), fill = factor(cyl))) + Note: If you only want to expand the spacing to the right of the legend text, use stringr::str_pad()Įxample: Increase vertical spacing (mind byrow = TRUE) library(ggplot2) Scale_fill_brewer("Cyl", palette = "Dark2") + Ggplot(mtcars, aes(factor(cyl), fill = factor(cyl))) + Example below.Įxample: Increase horizontal spacing between legend keys library(ggplot2) #Separation studio 4 where is the spread icon updateUpdate Dec 2021 - to make work, you will need to set byrow = TRUE in the corresponding guide_legend. Ggplot2 v3.0.0 released in July 2018 has working options to modify, and legend.text.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |