Hacking ggvis add_axis() function to operate as a title function
Version 0.4.3 of ggvis
does not have a function to add titles to plots, but still there is a known way to hack the add_axis()
function to work as a title function. If a user expects to explore this device many times, it's advised to wrap it into a function. Besides making the code more readable, it's a quicker way to address the problem.
Getting ready
This recipe does not only teach how to craft the hack function but also to experiment it on the previous plot, so make sure to have sca3
from the earlier recipe loaded into your environment. Alternatively, you can use another ggvis
object of your own.
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), ...