Skip to content

Instantly share code, notes, and snippets.

@jennybc
Created May 13, 2014 21:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jennybc/697d3ede1a09682c2fb7 to your computer and use it in GitHub Desktop.
Save jennybc/697d3ede1a09682c2fb7 to your computer and use it in GitHub Desktop.
Writes tabular data and a figure for each country in the Gapminder excerpt
library(plyr)
library(ggplot2)
gDat <- read.delim("gapminderDataFiveYear.txt")
d_ply(gDat, ~ country, function(z) {
the_country <- z$country[1]
the_continent <- z$continent[1]
the_filename <- paste0(the_continent, "_", the_country, ".tsv")
write.table(z, file = the_filename,
quote = FALSE, sep = "\t", row.names = FALSE)
the_filename <- paste0(the_continent, "_", the_country, ".png")
ggplot(z, aes(x = year, y = lifeExp)) +
geom_point() + geom_smooth(se = FALSE, method = "lm") +
ggtitle(the_country)
ggsave(the_filename)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment