Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a way to do it, but it's a little ugly.</p> <p>When I first looked at it, I wondered if it could be done using geom_text, but although it gave a representation, it didn't really fit the motif structure. This was a first attempt:</p> <pre><code>require(ggplot2) big_votes_movies = movies[movies$votes &gt; 100000,] p &lt;- ggplot(big_votes_movies, aes(x=rating, y=votes, label=year)) p + geom_text(size=12, aes(colour=factor(year), alpha=0.3)) + geom_jitter(alpha=0) + scale_x_continuous(limits=c(8, 9.5)) + scale_y_continuous(limits=c(90000,170000)) </code></pre> <p><img src="https://i.stack.imgur.com/jI10O.png" alt="text images"></p> <p>So then I realised you had to actually render the images within the grid/ggplot framework. You can do it, but you need to have physical images for each year (I created rudimentary images using ggplot, just to use only one tool, but maybe Photoshop would be better!) and then make your own grobs which you can add as custom annotations. You then need to make your own histogram bins and plot using apply. See below (it could be prettied up fairly easily). Sadly only works with cartesian co-ords :(</p> <p><img src="https://i.stack.imgur.com/H40pm.png" alt="plot"></p> <pre><code>require(ggplot2) require(png) require(plyr) require(grid) years&lt;-data.frame(year=unique(big_votes_movies$year)) palette(rainbow(nrow(years))) years$col&lt;-palette() # manually set some different colors # create a function to write the "year" images writeYear&lt;-function(year,col){ png(filename=paste(year,".png",sep=""),width=550,height=300,bg="transparent") im&lt;-qplot(1,1,xlab=NULL,ylab=NULL) + theme(axis.text.x = element_blank(),axis.text.y = element_blank()) + theme(panel.background = element_rect(fill = "transparent",colour = NA), plot.background = element_rect(fill = "transparent",colour = NA), panel.grid.minor = element_line(colour = "white")) + geom_text(label=year, size=80, color=col) print(im) dev.off() } #call the function to create the placeholder images apply(years,1,FUN=function(x)writeYear(x["year"],x["col"])) # then roll up the data summarydata&lt;-big_votes_movies[,c("year","rating","votes")] # make own bins (a cheat) summarydata$rating&lt;-cut(summarydata$rating,breaks=c(0,8,8.5,9,Inf),labels=c(0,8,8.5,9)) aggdata &lt;- ddply(summarydata, c("year", "rating"), summarise, votes = sum(votes) ) aggdata&lt;-aggdata[order(aggdata$rating),] aggdata&lt;-ddply(aggdata,.(rating),transform,ymax=cumsum(votes),ymin=c(0,cumsum(votes))[1:length(votes)]) aggdata$imgname&lt;-apply(aggdata,1,FUN=function(x)paste(x["year"],".png",sep="")) #work out the upper limit on the y axis ymax&lt;-max(aggdata$ymax) #plot the basic chart z&lt;-qplot(x=10,y=10,geom="blank") + scale_x_continuous(limits=c(8,9.5)) + scale_y_continuous(limits=c(0,ymax)) #make a function to create the grobs and call the annotation_custom function callgraph&lt;-function(df){ tiles&lt;-apply(df,1,FUN=function(x)return(annotation_custom(rasterGrob(image=readPNG(x["imgname"]), x=0,y=0,height=1,width=1,just=c("left","bottom")), xmin=as.numeric(x["rating"]),xmax=as.numeric(x["rating"])+0.5,ymin=as.numeric(x["ymin"]),ym ax=as.numeric(x["ymax"])))) return(tiles) } # then add the annotations to the plot z+callgraph(aggdata) </code></pre> <p>and here's the plot with photoshopped images. I just save them over the generated imaages, and ran the second half of the script so as not to regenerate them.</p> <p><img src="https://i.stack.imgur.com/h8mNV.png" alt="enter image description here"></p> <p>OK - and then because it was bothering me, I decided to install extrafont and build the prettier graph using just R:</p> <p><img src="https://i.stack.imgur.com/13kfj.png" alt="pretty"></p> <p>and here's the code:</p> <pre><code> require(ggplot2) require(png) require(plyr) require(grid) require(extrafont) #font_import(pattern="Show") RUN THIS ONCE ONLY #load the fonts loadfonts(device="win") #create a subset of data with big votes big_votes_movies = movies[movies$votes &gt; 100000,] #create a custom palette and append to a table of the unique years (labels) years&lt;-data.frame(year=unique(big_votes_movies$year)) palette(rainbow(nrow(years))) years$col&lt;-palette() #function to create the labels as png files writeYear&lt;-function(year,col){ png(filename=paste(year,".png",sep=""),width=440,height=190,bg="transparent") im&lt;-qplot(1,1,xlab=NULL,ylab=NULL,geom="blank") + geom_text(label=year,size=70, family="Showcard Gothic", color=col,alpha=0.8) + theme(axis.text.x = element_blank(),axis.text.y = element_blank()) + theme(panel.background = element_rect(fill = "transparent",colour = NA), plot.background = element_rect(fill = "transparent",colour = NA), panel.grid.minor = element_line(colour = "transparent"), panel.grid.major = element_line(colour = "transparent"), axis.ticks=element_blank()) print(im) dev.off() } #call the function to create the placeholder images apply(years,1,FUN=function(x)writeYear(x["year"],x["col"])) #summarize the data, and create bins manually summarydata&lt;-big_votes_movies[,c("year","rating","votes")] summarydata$rating&lt;-cut(summarydata$rating,breaks=c(0,8,8.5,9,Inf),labels=c(0,8,8.5,9)) aggdata &lt;- ddply(summarydata, c("year", "rating"), summarise, votes = sum(votes) ) aggdata&lt;-aggdata[order(aggdata$rating),] aggdata&lt;-ddply(aggdata,.(rating),transform,ymax=cumsum(votes),ymin=c(0,cumsum(votes))[1:length(votes)]) #identify the image placeholders aggdata$imgname&lt;-apply(aggdata,1,FUN=function(x)paste(x["year"],".png",sep="")) ymax&lt;-max(aggdata$ymax) #do the basic plot z&lt;-qplot(x=10,y=10,geom="blank",xlab="Rating",ylab="Votes \n",main="Big Movie Votes \n") + theme_bw() + theme(panel.grid.major = element_line(colour = "transparent"), text = element_text(family="Kalinga", size=20,face="bold") ) + scale_x_continuous(limits=c(8,9.5)) + scale_y_continuous(limits=c(0,ymax)) #creat a function to create the grobs and return annotation_custom() calls callgraph&lt;-function(df){ tiles&lt;-apply(df,1,FUN=function(x)return(annotation_custom(rasterGrob(image=readPNG(x["imgname"]), x=0,y=0,height=1,width=1,just=c("left","bottom")), xmin=as.numeric(x["rating"]),xmax=as.numeric(x["rating"])+0.5,ymin=as.numeric(x["ymin"]),ymax=as.numeric(x["ymax"])))) return(tiles) } #add the tiles to the base chart z+callgraph(aggdata) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload