R Data Visualization Recipes
上QQ阅读APP看书,第一时间看更新

How to do it...

  1. Draw a scatterplot using ggplot2 and sum the geom_rug() layer:
> set.seed(50) ; library(ggplot2)
> rug <- ggplot(iris,
aes(x = Petal.Length,
y = Petal.Width,
colour = Species))
> rug <- rug +
geom_jitter(aes( shape = Species), alpha = .4) +
geom_rug(position = 'jitter' , show.legend = F, alpha = .4)
> rug

The result is demonstrated by the following illustration:

Figure 2.8 - Jittered scatterplot with rugs.

  1. Using plotly's ggplotly() function, this illustration becomes interactive:
> plotly::ggplotly(rug)

Let's see the nuts and bolts.