Graphics Reference
In-Depth Information
Figure A-3. A line graph made with plot() and lines()
The resulting graph has a few quirks. The second (blue) line runs below the visible range, be-
cause the yrange was set only for the first line, when the plot() function was called. Addition-
ally, the x-axis is numbered instead of categorical.
Now let's take a look at the corresponding code and graphs with ggplot2. With ggplot2, the
structure of the data is always the same: it requires a data frame in “long” format, as opposed
to the “wide” format used previously. When the data is in long format, each row represents one
item. Instead of having their groups determined by their positionsin the matrix, the items have
their groups specified in a separate column. Here is simpledat , converted to long format:
simpledat_long
Aval Bval value
A1 B1
10
A1 B2
9
A2 B1
7
Search WWH ::




Custom Search