没有一些可重复的数据有点困难,但您应该能够通过添加geom_line()
仅使用该特定国家/地区的数据来实现这一点:
ggplot(data3, aes(year, NY.GDP.MKTP.KD.ZG, color = country)) + geom_line() +
xlab('Year') + ylab('GDP per capita') +
labs(title = "Annual GDP Growth rate (%)") +
theme_bw() +
geom_line(data=subset(data3, country == "China"), colour="black", size=1.5)
使图例与颜色和大小保持一致有点棘手 - 您可以通过手动修改图例来做到这一点override.aes
,但这不一定是最优雅的解决方案:
# Needed to access hue_pal(), which is where ggplot's
# default colours come from
library(scales)
ggplot(data3, aes(year, NY.GDP.MKTP.KD.ZG, color = country)) + geom_line() +
xlab('Year') + ylab('GDP per capita') +
labs(title = "Annual GDP Growth rate (%)") +
theme_bw() +
geom_line(data=subset(data3, country == "World"), colour="black", size=1.5) +
guides(colour=guide_legend(override.aes=list(
colour=c(hue_pal()(11)[1:10], "black"), size=c(rep(1, 10), 1.5))))