
上QQ阅读APP看书,第一时间看更新
How to do it...
- Wrap the add_axis() function with several arguments declared to work as a title function:
> library(ggvis)
> ggvis_title <- function(vis, plot_title, title_size = 18, shift = 0, ...){
add_axis(vis, 'x', ticks = 0, orient = 'top',
properties = axis_props( axis = list(strokeWidth = 0),
labels = list(strokeWidth = 0),
grid = list(strokeWidth = 0),
title = list(fontSize = title_size, dy = -shift, ...)),
title = plot_title)
}
- Try it on the previous plot:
> sca3 %>% ggvis_title('simple ggvis scatterplot')
The result looks like the following image:

Figure 2.2 - titled ggvis scatterplot.
Now to the explanations.