Line Graphs (ggplot)

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


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


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().


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.


An Example: Fully Loaded

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

Back | Next