ABSTRACT

In addition to using the functions to modify ggplotly()’s return value, the ggplotly() function itself provides some arguments for controlling that return value. ggplotly() translates each ggplot2 layer into one or more plotly.js traces. In this translation, it is forced to make a number of assumptions about trace attribute values that may or may not be appropriate for the use case. Any aspect of a plotly object’s layout can be modified6 via the layout() function. By default, since it doesn’t always make sense to compare values, ggplotly() will usually set layout.hovermode='closest'. Since a single plotly object can only have one layout, modifying the layout of ggplotly() is fairly easy, but it’s trickier to modify the data underlying the graph. Since ggplotly() returns a plotly object, and plotly objects can have data attached to them, it attaches data from ggplot2 layer.