I cannot figure out how to add multiple barcharts (or, even better, piecharts) to one plot.
The simplest case would be to add two barcharts at different x,y locations onto a plane.
An application example would be to illustrate both the number of people living in a certain area, and the number of migrants (for lack of better example) living there as well. By packaging this population information with spatial information, I hope to convey the corresponding information efficiently.
Solutions involving ggmaps are fine, however, I do not require them (displaying the data without a map layer in the background is acceptable).
To be more precise, here is some code, that is not working as I would like it to. In particular, the bar-charts are replaced by rectangles, which are not stacked, but overlap each other, leading to wrongly displayed information.
Furthermore, at each location, the total height of each bar in the bar chart (or size of the pie, for that matter) should correspond to the sum of both parts.
require(ggplot2)
x <- c(1,2,3)
y <- c(3,2,4)
pop <- c(1,7,8)
mig <- c(1,5,2)
df <- rbind(x,y,pop,mig)
df <- t(df)
df <- data.frame(df)
# bring data in long format
require(reshape2)
tmp <- melt(df, id.vars = c("x","y"))
p <- ggplot(tmp, aes(x=x, y=y, fill = variable))
p <- p + geom_rect(aes(xmin = x, xmax = x + 0.1,
ymin = y, ymax = y + value
))
print(p)
Eventually, this should serve as an input into a larger animation, that visualizes temporal development of the variables.