pixel art of ggplot2 faceting using geofacet
[This article was first published on R on Guangchuang YU, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I just discovered an interesting ggplot2
extension, geofacet
, that supports arranging facet panels that mimics geographic topoloty.
After playing with it, I realized that it is not only for visualizing geo
-related data, but also can be fun for presenting data to mimics pixel art.
Here is an example using the Turkey shape:
Turkey <- read.csv("http://pages.iu.edu/~cdesante/turkey.csv") Turkey = Turkey[, -3] colnames(Turkey)[2:1] = c("row", "col") Turkey$row = max(Turkey$row) - Turkey$row +1 Turkey$name <- Turkey$code <- paste0('turkey', 1:nrow(Turkey)) require(ggplot2) require(geofacet) x <- split(eu_gdp, eu_gdp$code) x <- x[sample.int(length(x), nrow(Turkey), replace=T)] for (i in 1:length(x)) { x[[i]]$code = Turkey$code[i] } y <- do.call(rbind, x) p1 <- ggplot(y, aes(gdp_pc, year))+ geom_line(color="steelblue") + facet_geo(~code, grid=Turkey, scales='free') print(p1)
p1 + theme_void() + theme(strip.text.x = element_blank())
To leave a comment for the author, please follow the link and comment on their blog: R on Guangchuang YU.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.