
上QQ阅读APP看书,第一时间看更新
How to do it...
- Set the alpha parameter to apply alpha blending to ggplot:
> library(ggplot2)
> sca1 <- ggplot( iris, aes( x = Petal.Length, y = Petal.Width))
> sca1 + geom_point( alpha = .5 ,
aes(shape = Species, colour = Species))
The following figure 2.7 shows alpha blending working:

Figure 2.7 - alpha blending with ggplot2.
- Setting alpha parameter with plotly will also apply alpha blending:
> library(plotly)
> sca9 <- plot_ly( iris, x = ~Petal.Length, y = ~Petal.Width,
> type = 'scatter', mode = 'markers', alpha = .5, symbol = ~Species)
> sca9
- ggvis applies alpha blending when opacity argument is set:
> library(ggvis)
> sca3 <- ggvis(iris, x = ~Petal.Length, y = ~Petal.Width)
> sca3 %>% layer_points(opacity := .5, shape = ~Species, fill = ~Species)
Notice that opacity had to be declared using := instead of =.