There are two main plotting functions in ggplot2: qplot and ggplot. Yes, ggplot2 combines elements with + symbols! This may seem non-standard, although it has the advantage of allowing ggplot2 plots to be proper R objects, which can modified, inspected, and re-used (I provide some examples at the end). At a minimum, you must specify the data, some aesthetics, and a geom. There are also statistics, scales, and annotation options, among others. Geom_point(): we want a scatter plot this is called a “geom”Īes(): specifies the “aesthetic” elements a legend is automatically createdįacet_grid(): specifies the “faceting” or panel layout Ggplot(): start an object and specify the data Let's look at some illustrative ggplot2 code: If it takes you hours to code a plot in base graphics, you're unlikely to throw it out and explore other ways of visualizing the data, and you're unlikely to explore all the dimensions of the data. Good graphical displays of data require rapid iteration and lots of exploration. Some people get really good at customizing ggplot and stick with it for all their plots, but since you've already learned the ways of base graphics in FISH554 I think you'll benefit from the strategy in this figure: I try and exploit the grey shaded areas: I use ggplot2 for data exploration and once I've decided on a small number of key plots, I'll use base graphics to make fully-customized plots if needed. Base graphics are fully customizable but can take longer to set up. Right panel: ggplot2 excels at rapid visual exploration of data, but has some limitations in how it can be customized. Left panel: It's remarkably easy to plot high-dimensional data in ggplot2 with, for example, colours, sizes, shapes, and panels. data dimensions and customization level for base graphics (blue) and ggplot2 (red). The following figure shows figure creation time vs. I tend to use ggplot2 and base graphics for what they excel at: ggplot2 for rapid data exploration and base graphics for polished and fully-customized plots for publication. With base graphics, you have complete control over every pixel in a plot but it can take a lot of time and code to produce a plot.Īlthough ggplot2 can be fully customized, it reaches a point of diminishing returns. Think of base graphic functions as drawing with data (examples of base graphic functions are plot(), points(), and lines(). The emphasis of ggplot2 is on rapid exploration of data, and especially high-dimensional data. Ggplot2 is an R package by Hadley Wickham and Winston Chang that implements Wilkinson's Grammar of Graphics. Know how to find help on ggplot2 when you run into problems.Have an idea about how to start customizing ggplot2 figures.Make quick exploratory plots of your multidimensional data.Understand the basic grammar of ggplot2 (data, geoms, aesthetics, facets).When you want to check your work, or if you get stuck on an exercise, just click on the button R source and you'll see the R source code that created a figure. It was written as a self-study component for the FISH554 class at the University of Washington. This page will help you teach yourself how to rapidly explore data with the ggplot2 R package.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |