简体   繁体   English

在R中为情节图例添加标题

[英]Adding title to plotly legend in R

I'd like to add a legend-title to my plotly graph (made in R). 我想在我的情节图(用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: 您可以通过为两者指定相同的y坐标并使用yanchor将每个元素放置在正确的一侧来将图例标题锚定到图例:

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") )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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