Understanding basic syntax and grammar
The ggvis
uses similar grammar and syntax to ggplot2
, and we can use this basic syntax to create figures. In this recipe, we cover how to use ggvis
syntax and grammar to build advanced plots.
Getting ready
Ensure you have installed and loaded ggvis
into your R session. Also, you need to complete the previous steps by storing house
in your R environment.
How to do it…
Please perform the following steps to create plots with ggvis
:
First, create a scatterplot by mapping Size to the x axis and Price to the y axis. Furthermore, we can assign different colors or shapes to points with different statuses:
> house %>% ggvis(~Size, ~Price, fill=~Status, size=10, shape=~Status) %>% layer_points()
Also, we can use the
add_props
function to change the fill color to red:> house %>% ggvis(~Size, ~Price, fill=~Status, size=10, shape=~Status) %>% layer_points() %>% add_props(fill...