Using scales
Besides changing the appearance of axes and legends, we can rescale the mapping of the data and how it should be displayed on the plot with the scale function. In this recipe, we introduce how to scale data in ggvis
.
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 rescale data in ggvis
:
First, create a bar plot and then replace the linear scale with a power scale:
> house %>% ggvis(~Status, ~Price, fill=~Status) %>% layer_bars() %>% scale_numeric("y", trans = "pow", exponent = 0.2)
We can change the fill color with the
scale_nominal
function:> house %>% ggvis(~Status, ~Price, fill=~Status) %>% layer_bars() %>% scale_nominal("fill", range = c("pink", "green", "lightblue"))
How it works…
In the previous...