Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Use geom_rug(). For
this example (Figure 5-28), we’ll
use the faithful data set, which
contains data about the Old Faithful geyser in two columns—eruptions, which is the length of each
eruption, and waiting, which is the
length of time to the next eruption:
ggplot(faithful,aes(x=eruptions,y=waiting))+geom_point()+geom_rug()
A marginal rug plot is essentially a one-dimensional scatter plot that can be used to visualize the distribution of data on each axis.
In this particular data set, the marginal rug is not as
informative as it could be. The resolution of the waiting variable is in whole minutes, and
because of this, the rug lines have a lot of overplotting. To reduce the overplotting, we can jitter
the line positions and make them slightly thinner by specifying size (Figure 5-29). This helps the viewer see the
distribution more clearly: