ah bon
ah bon

Reputation: 10011

Modify part of legend's colour in ggplot2

I have plotted with the following code:

library(ggplot2)
ggplot(data = mpg, aes(x = displ, y = cty))+
  geom_point(aes(size = hwy, color = cyl, shape = drv))+
  guides(colour = guide_colourbar(order = 1),
         alpha = guide_legend(order = 2),
         size = guide_legend(order = 3))

Now I want to change the legend's colour from black to grey (as shown in the image below), how could I do that? Thanks.

enter image description here

Upvotes: 0

Views: 48

Answers (1)

Allan Cameron
Allan Cameron

Reputation: 173803

You can do:

library(ggplot2)

ggplot(data = mpg, aes(x = displ, y = cty))+
  geom_point(aes(size = hwy, color = cyl, shape = drv))+
  guides(colour = guide_colourbar(order = 1),
         alpha = guide_legend(order = 2),
         size = guide_legend(order = 3, override.aes = list(color = "gray")))

enter image description here

Upvotes: 1

Related Questions