In the following example how can i add a title to the legend in plot_ly for R ?
mtcars %>% plot_ly(x = ~disp, y = ~mpg, color = ~factor(cyl), size = ~wt) %>% add_markers(
hoverinfo = "text",
text = ~paste("Displacement = ", disp, "\nMiles Per Gallon = ", mpg) ) %>% layout(title ="Custom Hover Text")
thanks
As a general rule, there are two ways to add text labels to figures: Certain trace types, notably in the scatter family (e.g. scatter , scatter3d , scattergeo etc), support a text attribute, and can be displayed with or without markers. Standalone text annotations can be added to figures using fig.
Plotly Show Legend To disable the Legend, we can use the update_layout() function and set the showlegend parameter to false.
Plotly legends are interactive. Click on the legend entries to hide and show traces. The legendgroup key groups legend entries so that clicking on one legend entry will hide or show all of the traces in that group.
This functionality has since been included within the layout
function in the legend
option. There's a sub-option called title
within which you can supply a list that includes the text.
mtcars %>%
plot_ly(x = ~disp, y = ~mpg, color = ~factor(cyl), size = ~wt) %>%
add_markers(hoverinfo = "text",
text = ~paste("Displacement = ", disp, "\nMiles Per Gallon = ", mpg) ) %>%
layout(title = "Custom Hover Text",
legend = list(title = list(text = "<b>Cylinders</b>"))) # TITLE HERE
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With