Is there a package/geom for making Pictorial Fraction Charts?

I am looking for some sort of package that helps create pictoral fraction charts, as illustrated here: http://datavizproject.com/data-type/fraction-of-pictograms/.

I've seen waffle but I am not sure how it integrates with ggplot2 style-syntax with facets and aesthetics.

Does something like this exist?

waffle is not compatible with ggplot2, but I wouldn't have thought facets would be appropriate for these kind of pictograms.

If you really wanted to, you could generate something like this using custom shapes with ggplot2 and some of your own functions for the placement of the shapes.

Somebody produced a package using custom shapes (might have been dogs or cats or whatever), but I cannot find it right now.

You can do that with ggimage, but I haven't looked through any other possible extensions (ggimage suited my very important use case just fine, so I stopped there!)


minimal_nba_means_1617

:point_up: end of 2016-17 season, in case anyone was suffering righteous indignation!

2 Likes

I was wondering the same thing... and came to the same conclusion. There's not much yet, and it's a shame. Do you know of any classification of these types of charts ? It seems to me that with 6 or 7 chart types we can cover around 90% of those, it's pretty much always the same and shouldn't be that hard to wrap into a package.

Actually I've started to work on a package to do just that. I looked at ggproto but I don't understand it much so I took the easier route. It would be nice to be able to use ggplot aesthetics though... and then plug them into gganimate for more fun.

I came across package pictogram during my journey. Maybe it will help.

I imagine this is pretty close. If I then used a ggimage for the shapes, I'd bet it could look really good. But hiding the mutates and geom_point would be awesome if someone knows how.

suppressPackageStartupMessages(library(tidyverse))

tibble(a=runif(4),b=letters[1:4], p=list(seq(.01,1,.01))) %>%
unnest() %>%
mutate(q = ifelse(a>p,1,0),
label = paste(b,scales::percent(a)),
x = ((p-0.01)*100)%%10,
y = ((p-0.01)*100)%/%10) %>%
ggplot() +
geom_point(mapping=aes(x=x, y=y, color = q, fill=q, shape = factor(q))) +
scale_y_continuous(name="") +
scale_x_continuous(name="") +
scale_shape_manual(values = c(25,24)) +
guides(fill=FALSE, shape=FALSE, color=FALSE) +
facet_wrap(~label, nrow = 2) +
theme_void()

I'd like to do something like:
tibble(a=runif(4),b=letters[1:4]) %>%
ggplot() +
geom_pictorial(aes(value = a), grid_dimension = c(10,10), shapes = c(image1, image2))

You could write a function of the form:

geom_pictorial <- function(aesthetic, grid_dimension, shapes, ...){
  ...
}

Check out the code on github for some other ggplot extensions for help.

1 Like