Search code examples
rggplot2histogrampie-chartscatter-plot

Plot histograms or pie charts in a scatter plot


I need to repeat the thing done in: tiny pie charts to represent each point in an scatterplot using ggplot2 but I stumbled into the problem that the package ggsubplot is not available for 3.3.1 R version.

Essentially I need a histogram or a pie chart in predefined points on the scatterplot. Here is the same code that is used in the cited post:

foo <- data.frame(X=runif(30),Y=runif(30),A=runif(30),B=runif(30),C=runif(30))
foo.m <- melt(foo, id.vars=c("X","Y"))
ggplot(foo.m, aes(X,Y))+geom_point()
ggplot(foo.m) +
    geom_subplot2d(aes(x = X, y = Y, subplot = geom_bar(aes(variable, 
value, fill = variable), stat = "identity")), width = rel(.5), ref = NULL)

The code used libraries reshape2, ggplot2 and ggsubplot.

The image that I want to see is in the post cited above

UPD: I downloaded the older versions of R (3.0.2 and 3.0.3) and checkpoint package, and used:

checkpoint("2014-09-18")

as was described in the comment bellow. But I get an error:

Using binwidth 0.0946
Using binwidth 0.0554
Error in layout_base(data, vars, drop = drop) : 
At least one layer must contain all variables used for facetting

Which I can't get around, because when I try to include facet, the following error comes up:

Error: ggsubplots do not support facetting

Solution

  • It doesn't look like ggsubplot is going to fix itself any time soon. One option would be to use the checkpoint package, and essentially "reset" your copy of R to a time when the package was compatible. This post suggests using a time point of 2014-09-18.