散点图上的彩色线 - R

Colour line on scatter plot - R

我为阿根廷和巴西绘制了二氧化碳排放散点图。我怎样才能让它们有不同的颜色?目前它都是绿色的。 谢谢 路易斯

df%>%
  dplyr:: filter(Country %in% c("Argentina", "Brazil")) %>%   
  filter(Year<=2019 & Year>=1950) %>%   
  ggplot(aes(x = Year, y = CO2_annual_tonnes)) + 
    geom_point(na.rm =TRUE, shape=20, size=2, colour="green") + 
    labs (x = "Year", y = "CO2Emmissions (tonnes)")

试试这个:

library(ggplot2)
library(dplyr)
df%>% 
  dplyr:: filter(Country %in% c("Argentina", "Brazil")) %>%    
  filter(Year<=2019 & Year>=1950) %>%    
  ggplot(aes(x = Year, y = CO2_annual_tonnes, colour=factor(country))) + 
  geom_point(na.rm =TRUE, shape=20, size=2) + 
  labs (x = "Year", y = "CO2Emmissions (tonnes)")