I am struggling to add a modified legend to my ggplot.
I have a data set:
birdspp smallsaplings mediumsaplings largesaplings
95 5.044642857 2.384615385 1.30952381
97 3.482269504 1.873684211 1.390625
63 6.285714286 2 2.4
57 5.216216216 1.666666667 1.125
Which I've created a graph with:
Using the code:
library(ggplot2)
library(dplyr)
library(tidyr)
sapling %>%
gather(sapling_type, mean_number, -birdspp)
sapling %>%
gather(sapling_type, mean_number, -birdspp) %>%
ggplot(aes(mean_number, birdspp)) +
geom_point(aes(color = sapling_type)) +
geom_smooth(aes(group =sapling_type, color = sapling_type, fill = sapling_type), method = "lm", show.legend=FALSE) +
labs(x="Mean Sapling Density", y="Number of Bird Species") +
theme_classic()
As you can see the legend is not very neat.
I've tried turning show.legend = FALSE on and adding this:
+ scale_colour_discrete(name ="Sapling Size",
breaks=c("smallsaplings", "mediumsaplings", "largesaplings"),
labels=c("smallsaplings", "mediumsaplings", "largesaplings")) +
scale_shape_discrete(name ="Sapling Size",
breaks=c("smallsaplings", "mediumsaplings", "largesaplings"),
labels=c("smallsaplings", "mediumsaplings", "largesaplings"))
But haven't had any luck. Any suggestions would be appreciated.
Thank you.