I really like composite plots, where there’s a top part that describes a phenomenon and a bottom part with a synthetic time view of the overall process.
I’ve recently discovered this beautiful representation of educational differentials by gender, by Sara Lopus and Margaret Frye, and the beauty of this dataviz is that it tells a story on its own. (Click on the link for the publication)
I have used a random generated data to reproduce the graph in ggplot and used
gridExtra package to bind grobs, the top and bottom components.
grid.arrange(top, bottom, heights=c(10,5), widths=c(20), padding=0)
I have saved the map as a .png file png package and used
rasterGrob from package
grid to create a raster image graphical object.
Lately, some of the graphs I have been working on have “strange/erratic” values, so I thought to plot those values in a different color and rather than adding an extra legend line I have decided to add a note to explain the difference. Among the many options available, I have found a very quick and harmless way to add annotations to ggplot graphs. It uses the library “gridExtra”, which employs user-level functions that work with “grid” graphics and draw tables.
2. and save your graph as “my_graph”:
my_graph<- qplot(wt, mpg, data = mtcars)
gridExtra and add the text to the graph. Note that
x, hjust and
vjust give the position of the text in the outer margins. If you want to annotate INSIDE the graph, use
g <- arrangeGrob(p, sub = textGrob("I pledge my life and honor to the Night's Watch, \nfor this night and all the nights to come.", x=0, hjust=-0.1, vjust=0.1,gp = gpar(fontface = "italic", fontsize = 10)))
5. save the graph
ggsave("my_graph_with_note.pdf", g, width=5,height=5)
here is the graph I have been working on: