Adding legend title and main title in ggplot2

前端 未结 1 1441
北荒
北荒 2021-02-20 18:39

Hi I am trying to use ggplot2 to do the following

1) Change the legend name to \"asset\" 2) Add a title to the top 3) Change the border of each panel to a more solid da

相关标签:
1条回答
  • 2021-02-20 19:13

    1) You can change the legend name to "Asset" by putting "Asset" as the first parameter in the scale_color_manual function.

    scale_colour_manual("Asset",values = ...)
    

    2) You can do

    p<-p+labs(title="PUT TITLE HERE")
    

    for the title

    3) You can add an additional argument to theme() to change the background color (which will make a border appear around the box)

    p<-p+theme(panel.background = element_rect(fill=NA, col="black"))
    

    source: How to place divisions between facet grid lines

    You could also try adding p=p+theme_bw() earlier in the expression, but that might change too many things.

    4) For the grid labels, you have 2 options (well, more, but these are the easiest). Firstly, you can rename the levels of your data. If you don't want to do that, you can make a labeller function to pass as an argument in facet_grid(). See the example here:

    https://stackoverflow.com/a/12104207/1362215

    For the color of the panel, you can also use theme() for that

    p<-p+theme(strip.background = element_rect(fill = 'purple'))#turns boxes purple
    
    0 讨论(0)
提交回复
热议问题