ggplot Legend update

 



## Legend title
legendTitle <- "new title" # or NULL if you do not want to show the title

P +  guides(
title = NULL,
fill=guide_legend (
title = NULL,
keywidth=0.2, # specifying the width of the legend key.
keyheight=0.2, # specifying the height of the legend key.
default.unit="inch")
)

# Legend key label changes

newLabels <- c("Competitors", "Mirixa") # should be in order of color values below.
p + scale_fill_manual(values=c("Khaki", "Tomato"), labels = newLabels)

# Legend position
P + theme (legend.position = "bottom", # or "top", "left", or "right"
legen.dkey = element_rect(color = "white), # legend key background color in case of calling theme_bw()
)

 

Leave a comment