简体   繁体   中英

Adding title to plotly legend in R

I'd like to add a legend-title to my plotly graph (made in R). This doesn't seem possible in any straightforward fashion.

If nothing else works, I might add an annotation to the graph right above where the legend entries are shown. That said, I'm not sure where to anchor said notation.

I'm not sure how to proceed. Thanks.

You can anchor the legend title to the legend by specifying the same y coordinate for both and using yanchor to place each element on the correct side:

plot_ly( ... ) %>%
  add_annotations( text="MyTitle", xref="paper", yref="paper",
                  x=1.02, xanchor="left",
                  y=0.8, yanchor="bottom",    # Same y as legend below
                  legendtitle=TRUE, showarrow=FALSE ) %>%
  layout( legend=list(y=0.8, yanchor="top") )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM