Mapping ggplot geoms and aesthetic parameters

November 16, 2018

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

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.


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)

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))
Var1 Freq
alpha 33
color 30
size 30
x 29
linetype 26
y 24
fill 20
weight 9
ymax 8
ymin 7

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

knitr::kable(head(sort(table(relationship$from), decreasing = T), n = 10))
Var1 Freq
geom_boxplot 13
geom_text 11
geom_bin2d 10
geom_dotplot 10
geom_rect 9
geom_contour 8
geom_crossbar 8
geom_density 8
geom_errorbar 8
geom_histogram 8

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