使用面板数据的新功能,如何仅绘制所需的列的选定部分?
例如:
my.ts.plot <- ggplot(summary.df, aes(x = Year)) +
geom_line(aes(y = Trade.to.GDP, colour = Code)) +
scale_x_continuous(breaks = seq(min(summary.df$Year), max(summary.df$Year), 5)) +
theme(axis.text.x = element_text(angle = 90, vjust=0.5)) +
scale_color_discrete(name = "Countries by Code") +
labs(title = "Trade to GDP Ratio by COuntry (1970-2017)",
y = "Trade to GDP Ratio (Export + Import/ GDP)",
x = "")
my.ts.plot
使用此代码,我最终在图表中为不需要的每个国家/地区绘制线条。
我应该写些什么来只绘制我想要的少数几个不涉及我事先转换数据的国家(例如,CHN,美国,AUS)?
您可以在使用summary.df
和ggplot
来调用[
时直接将%in%
子集:
my.ts.plot <- ggplot(summary.df[summary.df$Country %in% c("CHN","USA","AUS"),], aes(x = Year)) +
geom_line(aes(y = Trade.to.GDP, colour = Code)) +
scale_x_continuous(breaks = seq(min(summary.df$Year), max(summary.df$Year), 5)) +
theme(axis.text.x = element_text(angle = 90, vjust=0.5)) +
scale_color_discrete(name = "Countries by Code") +
labs(title = "Trade to GDP Ratio by COuntry (1970-2017)",
y = "Trade to GDP Ratio (Export + Import/ GDP)",
x = "")
您需要将$Country
更改为包含您所在国家/地区的列的名称。