ggplot2: Adjust the symbol size in legends

后端 未结 4 1148
情话喂你
情话喂你 2020-11-30 02:36

How should I change the size of symbols in legends? I checked the document of theme but found no answer.

Here is an example:

library(gg         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 03:39

    Marius's answer did not work for me as of R version 3.2.2. You can still call guide_legend() with the same override.eas argument but you will need to specify color instead of shape in the wrapper function.

    So if you're running a later version of R, try this instead:

    g + guides(color = guide_legend(override.aes = list(size=5)))
    

    EDIT

    As pointed out by @Ibo in the comment, this may have been due to the color scale in the ggplot object. If the ggplot object has contains a color scale, the mapping of size (size=5) has to be set on the color instead.

提交回复
热议问题