Display name
Display name

Reputation: 4501

Can ggplot draw an outline around each legend entry?

In R how do I get ggplot to draw an outline around each legend point? The NA legend entry below looks like "nothing", for lack of a border around said point.

miss <- factor(sample(c(NA, 1:5), nrow(mtcars), replace = TRUE))
ggplot(mtcars, aes(mpg, wt)) +
  geom_point(aes(color = miss)) +
  scale_color_grey(na.value = "white") + 
  geom_point(shape = 1, color = "black") + 
  theme_bw()

legend without border outlines

Upvotes: 0

Views: 302

Answers (1)

Duck
Duck

Reputation: 39613

Maybe you are looking for this. You can consider as an option using shape=21 and enable fill option:

library(ggplot2)
#Code
miss <- factor(sample(c(NA, 1:5), nrow(mtcars), replace = TRUE))
ggplot(mtcars, aes(mpg, wt)) +
  geom_point(shape=21,aes(fill = miss),color='black') +
  scale_fill_grey(na.value = "white") + 
  theme_bw()

Output:

enter image description here

Upvotes: 3

Related Questions