user1505631
user1505631

Reputation: 529

Add an extra point to a single facet in ggplot

I want to add a single point to only one facet. I tried to set the group in geom_point:

ggplot(data=mpg, aes(displ, hwy)) +
  geom_point() +
  facet_wrap(~class) + geom_point(aes(x=5, y=25, group = "pickup"), colour="blue")

But that put a blue dot in all facets. Is there any way to constrain the point to only one?

Upvotes: 0

Views: 1030

Answers (1)

stefan
stefan

Reputation: 125228

You could achieve your desired result by putting the information for your point in a dataframe which you pass to the data argument of your second geom_point:

library(ggplot2)

ggplot(data=mpg, aes(displ, hwy)) +
  geom_point() +
  facet_wrap(~class) + 
  geom_point(data = data.frame(displ = 5, hwy = 25, class = "pickup"), colour="blue")

Upvotes: 2

Related Questions