是的,color 应该是 Country Name 而不是 class,y 应该是 SupDem
library(ggplot2)
ggplot(df, aes(Year, SupDem, colour = `Country Name`)) +
geom_line()
或者,如果您想要更现代的样式,例如:
library(ggplot2)
ggplot(df, aes(Year, SupDem, colour = `Country Name`)) +
geom_line(size = 1) +
geom_point(size = 3) +
scale_color_manual(values = c('orange', 'deepskyblue4')) +
theme_minimal(base_size = 16)
创建于 2022 年 10 月 4 日,reprex v2.0.2
以可重复格式从问题中获取的数据
df <- structure(list(`Country Name` = c("Turkiye", "Turkiye", "Turkiye",
"US", "US", "US"), Year = c(1990L, 1991L, 1993L, 1990L, 1991L,
1993L), SupDem = c(5L, 45L, 50L, 80L, 85L, 84L)), class = "data.frame",
row.names = c(NA, -6L))