R for Data Science Cookbook by David Chiu

R for Data Science Cookbook by David Chiu

Author:David Chiu
Language: eng
Format: epub
Publisher: Packt Publishing


Figure 26. Adjusting the scale of the bar plot

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"))

Figure 27. Changing the fill color of the bar plot

How it works…

In the previous recipe, we introduced how to change the axis property with the add_axis function. However, the add_axis function only modifies the appearance of the axis; it does not alter the mapping data. To scale both the axis and the mapping data, one can use the scale_* function.

In this example, we begin by making a bar plot with the layer_bar function. We then use scale_numeric to replace the linear scale with a power scale. This rescales both the y axis and the height of the bars. Besides rescaling continuous values with the scale_numeric function, one can change the property of a discrete value with scale_nominal. At the end of the previous recipe, we demonstrated how to use scale_nominal to refill the bar with a given color vector.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.