Mapping ggplot geoms and aesthetic parameters

[This article was first published on R on YIHAN WU, 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.



The sheer variety of geom_* in ggplot2 is overwhelming and astounding, especially with the control over the many aesthetics such as shape and color. For example, the ggplot2 cheat sheet is packed (link).

I frequently forget which aes parameters exist for each geom_* and need a quick look at the help pages. Using the information from the cheatsheet, I was able to quickly summarize the aes parameters available for each geom_* (link).

And with the help of igraph and edgebundleR, a htmlwidget based on the D3 Javascript library, I created an interactive network visualizing the connection between geoms and aes parameters.

library(igraph)
library(edgebundleR)
library(dplyr)
library(purrr)
suppressPackageStartupMessages(library(widgetframe))

parameters <- readLines("../../static/files/geom_aes.csv")
split_up <- function(x){
  params <- unlist(strsplit(x, ","))
  return(data.frame("from" = params[1], "to" = params[2:length(params)]))
}

relationship <- map_df(parameters, split_up)
head(relationship)

Perhaps not surprisingly, alpha is the most common aes parameter, followed closely by color and size.

knitr::kable(head(sort(table(relationship$to), decreasing = T), n = 10))
Var1Freq
alpha33
color30
size30
x29
linetype26
y24
fill20
weight9
ymax8
ymin7

geom_boxplot has the greatest number of aes parameters which can be controlled.

knitr::kable(head(sort(table(relationship$from), decreasing = T), n = 10))
Var1Freq
geom_boxplot13
geom_text11
geom_bin2d10
geom_dotplot10
geom_rect9
geom_contour8
geom_crossbar8
geom_density8
geom_errorbar8
geom_histogram8

Hover above the geom_* name to highlight the links to the aes parameters.

frameWidget(edgebundle(graph_from_data_frame(relationship), tension = 0.45, cutoff = 0.1, width = NULL, fontsize = 14,
  padding = 110, nodesize = c(5, 20), directed = FALSE), height = "600")
## Warning in graph_from_data_frame(relationship): In `d' `NA' elements were
## replaced with string "NA"

To leave a comment for the author, please follow the link and comment on their blog: R on YIHAN WU.

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.

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)