ggplotly_with_legend.Rd
This function creates a Plotly version of a ggplot2 object and adds a legend with the user-friendly name of the color variable as its title.
ggplotly_with_legend(plot, color, mapping_table)
A ggplot object.
A string specifying the column name to be used as the color variable.
A named list with as name the original colum name and as value the display name
A plotly object with a formatted legend.
df <- data.frame(x_var = rnorm(100),
y_var = rnorm(100),
color_var = sample(c("Red", "Blue"),
100,
replace = TRUE))
xlab_setting <- ggplot2::xlab("x label")
ylab_setting <- ggplot2::ylab("y label")
ggplot_instellingen <- ggplot2::geom_point()
scale_y <- ggplot2::scale_y_continuous()
plot <- basic_plot(df, "x_var", "y_var", "color_var", xlab_setting,
ylab_setting, ggplot_instellingen, "none", scale_y)
mapping_table <- list(color_var = "user friendly name var")
plotly_object <- ggplotly_with_legend(plot, "color_var", mapping_table)