Graphics Reference
In-Depth Information
Figure 4-4. Line graph with points
Discussion
Sometimes it is useful to indicate each data point on a line graph. This is helpful when the density
of observations is low, or when the observations do not happen at regular intervals. For example,
in the BOD data set there is no entry for Time =6, but this is not apparent from just a bare line
graph (compare Figure 4-3 with Figure 4-4 ).
In the worldpop data set, the intervals between each data point are not consistent. In the far past,
the estimates were not as frequent as they are in the more recent past. Displaying points on the
graph illustrates when each estimate was made ( Figure 4-5 ):
library(gcookbook) # For the data set
ggplot(worldpop, aes(x = Year, y = Population)) + geom_line() + geom_point()
# Same with a log y-axis
ggplot(worldpop, aes(x = Year, y = Population)) + geom_line() + geom_point() +
scale_y_log10()
Search WWH ::




Custom Search