Graphics Reference
In-Depth Information
Chapter4.Line Graphs
Line graphs are typically used for visualizing how one continuous variable, on the y-axis, changes
in relation to another continuous variable, on the x-axis. Often the xvariable represents time, but
it may also represent some other continuous quantity, like the amount of a drug administered to
experimental subjects.
As with bar graphs, there are exceptions. Line graphs can also be used with a discrete variable
on the x-axis. This is appropriate when the variable is ordered (e.g., “small”, “medium”, “large”),
but not when the variable is unordered (e.g., “cow”, “goose”, “pig”). Most of the examples in
this chapter use a continuous xvariable, but we'll see one example where the variable is conver-
ted to a factor and thus treated as a discrete variable.
Making a Basic Line Graph
Problem
You want to make a basic line graph.
Solution
Use ggplot() with geom_line() , and specify what variables you mapped to x and y ( Fig-
ure 4-1 ) :
ggplot(BOD, aes(x = Time, y = demand)) + geom_line()
Search WWH ::




Custom Search