pixel art of ggplot2 faceting using geofacet

June 26, 2017

(This article was first published on R on Guangchuang YU, and kindly contributed to R-bloggers)

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))

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')

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 on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...

If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)