I am trying to create a scatterplot in ggplot2
with one regression line even though colour is dependent on the 'Survey Type' variable. I would ideally also like to specify which survey type is which colour (community = red, subnational = green, national = blue).
This is the code I'm running which currently gives me 3 separate regression lines, one for each survey type.
ggplot(data=data.male,aes(x=mid_year, y=mean_tc, colour =condition)) +
geom_point(shape=1) +
geom_smooth(method=lm, data=data.male, na.rm = TRUE, fullrange= TRUE)
The condition is:
condition <- (data.male$survey_type)
Even if I move the colour aesthetic to the geom_point function it doesn't work as it gives me an error saying community is not a valid colour name?
My actual data file is really big so I'll just give a small sample here:
data.male dataset:
mid_year mean_tc survey_type
2000 4 Community
2001 5 National
2002 5.1 Subnational
2003 4.3 National
2004 4.5 Community
2005 5.2 Subnational
2006 4.4 National