- Base R graphics
- ggplot2
- A
data visualization, is composed of geometric shapes, that take on
aesthetics which represent variables from a data set.
`ggplot()`

+`aes()`

+`geom_*()`

or`ggplot(data, aes()) + geom_*()`

- Examples
- More examples
- More examples
- Colors!
- Facet
- Add smoothers
- More themes
- Save ggplot figures
- Putting multiple ggplot2 figures together

- A
data visualization, is composed of geometric shapes, that take on
aesthetics which represent variables from a data set.

R includes three major different packages (systems) for plotting
data: `graphics`

, `lattice`

, and
`ggplot2`

. `graphics`

comes with R and is referred
as base R plotting. It is easy to customize or modify charts with the
`graphics`

package, or to interact with them on the screen
(interactive plot). The `lattice`

package contains an
alternative set of functions for plotting data. `Lattice`

graphics are well suited for splitting data by a conditioning variable
and they used to be quite popular. The third package (or a system) is
`ggplot2`

, with `gg`

stands for
`grammar of graphics`

. `ggplot2`

is probably the
most popular package for plotting nowadays; hundreds of extra packages
build on it to extend its capacity, making it a well developed system
for plotting. We thus will focus mostly on `ggplot2`

.

Here, I will only introduce several commonly used plotting function
from the base R `graphics`

package. They are useful to
quickly plot something for data exploration. I personally use them
frequently during data analysis. However, I now produce almost all
figures in publications through `ggplot2`

.

To show a scatter plot, use the `plot`

function.

```
?plot.default
plot(x, y = NULL, type = "p", xlim = NULL, ylim = NULL, main = NULL, sub = NULL,
xlab = NULL, ylab = NULL, axes = TRUE, ...)
```

Plot is a generic function (you can “plot” many different types of
objects); `plot`

can draw many types of objects, including
vectors, tables, and time series. If you need to plot something
generated by another package, chances are that package will work with
`plot`

to do that. For example, if we have a phylogeny, and
`plot`

can draw it.

`## Loading required package: ape`

When performing data analysis, it’s often very important to understand the shape of a data distribution. Looking at a distribution can tell you whether there are outliers in the data, or whether a certain modeling technique will work on your data, or simply how many observations are within a certain range of values.

The best known technique for visualizing a distribution is the histogram.

Another very useful way to visualize a distribution is a box plot. A box plot is a compact way to show the distribution of a variable. The box shows the interquartile range. The interquartile range contains values between the 25th and 75th percentile; the line inside the box shows the median. The two “whiskers” on either side of the box show the adjacent values. The adjacent values are intended to show extreme values, but they don’t always extend to the absolute maximum or minimum value. The upper adjacent value is the value of the largest observation that is less than or equal to the upper quartile plus 1.5 times the length of the interquartile range; the lower adjacent value is the value of the smallest observation that is greater than or equal to the lower quartile less 1.5 times the length of the interquartile range. When there are values far outside the range we would expect for normally distributed data, those outlying values are plotted separately.