Reputation: 781
I am trying to create a legend item for a geom_rect legend. But the legends also shows a shape as well instead of a simple grey rectangle (see example below).
Is there a way to create a legend item that only shows the grey rectangle for the geom_rect and a filled shape for the data points?
library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width))+
geom_rect(mapping=aes(xmin=5.5,
xmax=6.5,
ymin=2.5,
ymax=3.5,fill="historic range"))+
geom_point(aes(Sepal.Length, Sepal.Width,fill="Data points",shape="Data points")) +
scale_fill_manual(values=c("darkgreen","grey"),labels=c("Data points","historic range")) +
scale_shape_manual(values=c(22),labels=c("Data points"))
Upvotes: 2
Views: 2591
Reputation: 24262
Try this
library(ggplot2)
ggplot(iris, aes(Sepal.Length, Sepal.Width)) +
geom_rect(aes(xmin=5.5, xmax=6.5, ymin=2.5, ymax=3.5, fill="Historic range")) +
geom_point(aes(x=Sepal.Length, y=Sepal.Width, shape="Data points"), fill='red') +
scale_fill_manual(values="grey", labels=c("Historic range")) +
scale_shape_manual(values=c(22), labels=c("Data points"))
Upvotes: 3