ggplot2: Creating labels and different colors on my plot

I need help!
I guess I can't attach the photo of the graph... but here's the deal.
"FRPM.x" is drawing from a data set, and "FRPM.y" is drawing from a different data set, but they're both being used to create geom_smooth and geom_point plots for 2 counties. I want the two datasets AND the two counties to have different colors, and to specify the difference in the legend, but I don't know how to separate them. Right now, both the lines for "Marin" have the same color, and both the lines for "Sonoma" have the same color, so it's hard to tell what is what.

I'm also very new to R and this is my first time using this forum, so pardon any lack of clarity!
Big thanks!

bigTabs <-left_join(tabs,tabs2,by=c("year","County.Name"))

bigTabs <- bigTabs[bigTabs$County.Name %in% countyList,]

bigplot <- ggplot(bigTabs, aes(x=year))+
  geom_smooth(method="lm", aes(color=County.Name,y=FRPM.x))+
  geom_smooth(method="lm", aes(color=County.Name,y=FRPM.y))+
  scale_x_continuous(breaks=seq(2010, 2019), limits=c(2010,2019))+
  ggtitle("FRPM by Year")+
  labs(x="Year", y="FRPM")+


To help us help you, could you please turn this into a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

longertabs <- bigTabs  %>% pivot_longer(
) %>% mutate(keyvar = paste0(County.Name," ",name))

bigplot <- ggplot(longertabs, aes(x=year,y=value,color=keyvar))+
  scale_x_continuous(breaks=seq(2010, 2019), limits=c(2010,2019))+
  scale_color_manual(values=list("county a FRPM.x"="red",
                                 "county a FRPM.y"="yellow",
                                 "county b FRPM.x"="black",
                                 "county b FRPM.y"="blue"))+
  ggtitle("FRPM by Year")+
  labs(x="Year", y="FRPM")+

Thanks so much! This did the trick and helped loads!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.