Graphics Reference
In-Depth Information
Figure 10-4. Left: legend with opaque background and outline; right: with no background or out-
lines
You can also remove the border around its elements so that it blends in ( Figure 10-4 , right):
p + theme(legend.position = c( .85 , .2 )) +
theme(legend.background = element_blank()) + # Remove overall border
theme(legend.key = element_blank())
# Remove border around each item
Changing the Order of Items in a Legend
Problem
You want to change the order of the items in a legend.
Solution
Set the limits in the scale to the desired order ( Figure 10-5 ):
# The base plot
p <- ggplot(PlantGrowth, aes(x = group, y = weight, fill = group)) + geom_boxplot()
p
# Change the order of items
p + scale_fill_discrete(limits = c( "trt1" , "trt2" , "ctrl" ))
Search WWH ::




Custom Search