Line Graphs (ggplot)

ggplot line graph example are provided to illustrate different format options.

Data

The Orange data frame ships with R and depicts the growth of fruit trees as a function of age (days).  The data object has 35 rows and 3 columns in long data format.

Basic Line Plot Syntax

Plot57

Line Plot Aesthetics

Line chart aesthetics control selected x and y data, color (by name), linetype and size, transparency or alpha level.  Line symbols or points are added using geom_point().

Plot58Plot59b

Layered Line Plots

It is common to layer line plots and geom_line() on top of other data plotted using another geom or plot top. In this case, it is essential when you add the new line data to be layered into the chart using the data = argument. This will avoid a common error: ggplot2 doesn’t know how to deal with data of class uneval.  The following example layers point and line data while avoiding the common error.

moving_average

An Example: Fully Loaded

The following chart combines several plot layers and many finished aesthetics, and is followed by code

Back | Next

Leave a Reply

Your email address will not be published. Required fields are marked *

twenty − 4 =