(See bottom of post for updates)
Initial post, 2014-07-29 11:43:38Z
I saw this graphics on the Economist's website and wondered if it's possible to produce a geom_bar()
with this kinda illustrative icons imbedded? (dummy data below)
Dummy data,
require(ggplot2)
# Generate data
df3 <- data.frame(units = c(1.3, 1.8, 2.7, 4.2, 4.7, 6.7, 20),
what = c('Wikipedia', 'London Olympic Park', 'Aircraft carrier',
'The Great Pyramid', 'Stonehenge', 'Burj Khalifas',
'Empire State Building'))
# make gs an ordered factor
df3$what <- factor(df3$what, levels = df3$what, ordered = TRUE)
#plots
ggplot(df3, aes(what, units)) + geom_bar(fill="white", colour="darkgreen",
alpha=0.5, stat="identity") + coord_flip() + scale_x_discrete() +
scale_y_continuous(breaks=seq(0, 20, 2)) + theme_bw() +
theme(axis.title.x = element_blank(), axis.title.y = element_blank())
Update #1, 2014-07-29 15:07:51Z
Apparently Robert Grant has started to build an R function to produce bar-charts with pictograms, it can be found at Github. Thanks to Andrie for that information. I'm currently working to see if Robert's function can do what I am looking for.
Please chime in if you have any advice on how to answer my question using Robert's function.
Update #2, 2014-08-02 12:35:19Z
Here is a simple illustration of how Grant's R-pictogram-function work
# in case you don't alredy have RCurl
# install.packages("RCurl", dependencies = TRUE)
source_github <- function(u) {
# load package
require(RCurl)
# read script lines from website and evaluate
script <- getURL(u, ssl.verifypeer = FALSE)
eval(parse(text = script),envir=.GlobalEnv)
}
Got this script form this SO answer
source_github("https://raw.githubusercontent.com/robertgrant/pictogram/master/pictogram.R")
# install.packages("png", dependencies = TRUE)
require(png)
img <- readPNG(system.file("img", "Rlogo.png", package="png"))
pictogram(icon = img, n = c( 12, 35, 7),
grouplabels=c("12 R logos","35 R logos","7 R logos"))
This gives you this kinda plot