![]() |
PNG table |
Creating the Table
After loading the data, let's first use this trick to put line breaks between the levels of the effect variable. Depending on your data, you may or may not need or want to do this.
library(OIdata) data(birds) library(gridExtra) # line breaks between words for levels of birds$effect: levels(birds$effect) <- gsub(" ", "\n", levels(birds$effect))
Next let's make our table:
xyTable <- table(birds$sky, birds$effect)
plot.new() grid.table(xyTable, # change font sizes: gpar.coltext = gpar(cex = 1.2), gpar.rowtext = gpar(cex = 1.2))
Now you can view and save the image just like any other plot.
The code is available in a gist.
Citations and Further Reading
- http://stackoverflow.com/questions/12318120/adding-table-within-the-plotting-region-of-a-ggplot-in-r
- http://stackoverflow.com/questions/12518387/can-i-create-an-empty-ggplot2-plot-in-r