library(knitr) library(ggvis) opts_chunk$set(comment = "#>", error = FALSE, tidy = FALSE)
If you're familiar with ggplot2, learning ggvis shouldn't be too hard - it borrows from many familiar concepts. Note that ggvis is still very young, and many of the interfaces are likely to change as we learn more about what works well.
Basic naming conversions:
aes()
-> props()
ggplot()
-> ggvis()
ggvis has a function interface so you combine components using %>%
,
not +
as in ggplot2.
Facetting is not currently supported, and when it is supported, it's more like to resemble embedded plots than facetting in ggplot2.
In ggplot2, the definition of a geom was somewhat blurred, because of things
like geom_histogram()
which combined geom_bar()
with stat_bin()
. The
distinction is more clear in ggvis: pure geoms correspond to emit_*
which
emit marks, and combined geoms and stats correspond to layers.
Using ggvis()
without adding any layers is analogous to qplot()
.
Vega provides a smaller set of scales than ggplot2 (just ordinal, quantitative, and time), but they are much more flexible than ggplot2 scales, and offer equivalent functionality.
ggplot2 has a two-level hierarchy - you have data and aes specifications in the plot and in each layer. ggvis provides an unlimited hierarchy - you can have as many levels as you need (and the data will only be computed once)
ggvis makes fewer assumptions about the type of data - data does not have to be a data frame until it has been processed by a transform.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.