I\'m creating a ggplot and I want to colour data points by the transect they came from. However when I do this using the colour=transect
argument I end up with a re
This could be achieved by making color
a local asthetic of the geom_point
layer:
library(ggplot2)
set.seed(42)
leaf.data <- data.frame(
distance.from.ecotone..m. = runif(30, 0, 30),
mean.herbivory.... = runif(30, -5, 15),
transect = factor(sample(1:5, 30, replace = TRUE))
)
ggplot(data=leaf.data, aes(x=distance.from.ecotone..m., y=mean.herbivory....)) +
geom_point(aes(colour=transect)) +
geom_smooth(method = "lm", na.rm = TRUE, fullrange= TRUE)+
labs(x="Distance from Ecotone (m)", y="Mean Herbivory per Tree (%)",
title="Herbivory as a Function of Distance from an Ecotone")
#> `geom_smooth()` using formula 'y ~ x'