library(gginteractive)
## Loading required package: ggplot2
## Loading required package: htmltools
p1 <- ggplot(mtcars, aes(x = wt, y = mpg)) + geom_point()

A normal ggplot. Next we pipe to a blank mesh, so that the plot is rendered as svg. In Rstudio this will appear in the viewer, rather than the plot window.

p1 %>% mesh_blank()
10 15 20 25 30 35 2 3 4 5 wt mpg

Now for an actually useful example, exploring the effect of the smoothing parameter span:

spans <- seq(.3, 1.5, by = .1)
p4 <- ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  lapply(spans, function(x) geom_smooth(method = "loess", span = x, se = FALSE))

controls <- 0:length(spans)
names(controls) <- c("none", spans)
p4 %>% mesh_geom("smooth", attr = "opacity",
                 control = radio(controls))
10 15 20 25 30 35 2 3 4 5 wt mpg
none 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 1.1 1.2 1.3 1.4 1.5

The gapminder example:

library(gapminder)

p2 <- ggplot(gapminder, aes(x = gdpPercap, y = lifeExp, color = continent, size = pop)) +
         geom_point()  + scale_x_log10() 

p2 <- p2 %>% mesh_alpha(geom = "point", variable = "year", on = radio0)
p2
40 60 80 1e+03 1e+04 1e+05 gdpPercap lifeExp continent Africa Americas Asia Europe Oceania pop 2.50e+08 5.00e+08 7.50e+08 1.00e+09 1.25e+09
1952 1957 1962 1967 1972 1977 1982 1987 1992 1997 2002 2007 Any

Convert back to a regular ggplot object:

p2 %>% unmesh()

Another example:

(ggplot(gapminder, aes(x = gdpPercap, y = lifeExp, color = continent, size = pop)) +
   geom_point()  + scale_x_log10()) %>%
  mesh_alpha(geom = "point", variable = "continent", on = radio0)
40 60 80 1e+03 1e+04 1e+05 gdpPercap lifeExp continent Africa Americas Asia Europe Oceania pop 2.50e+08 5.00e+08 7.50e+08 1.00e+09 1.25e+09
Africa Americas Asia Europe Oceania Any