In only 4 lines of code, the graph above is created with data straight from the World Bank. This example requires the ggplot2 library as well as the new WDI library. WDI is used to return a data frame that is passed to ggplot to produce the graph.
DF <- WDI(country=c("US","CA","MX"), indicator="NY.GDP.MKTP.KD.ZG", start=1990, end=2008)
ggplot(DF, aes(year, NY.GDP.MKTP.KD.ZG, color=country))+geom_line(stat=”identity”)+theme_bw()+xlab(“Year”)+opts(title=”Annual GDP Growth rate (%)”)+ylab(“”)
There is a reference manual that describes the use of ggplot2 in greater detail. Oh – one other note. I generally save charts using the png command. This did not work with ggplot2, I needed to create the chart in R and then executed the following command: