使 plotly 注释字体加粗

dan*_*dan 4 fonts r plotly

我想添加annotationscatterR'splotly包生成的绘图中,并以粗体显示文本。

我想:

library(plotly)
library(dplyr)

set.seed(1)
df <- data.frame(x=rnorm(10),y=rnorm(10))
plotly::plot_ly(x =~ df$x, y =~ df$y,marker = list(size=12), type = 'scatter',mode = "markers") %>%
  plotly::add_annotations(text=1:10,showarrow=T,arrowhead=1,x=df$x,y=df$y,font=list(size=10))
Run Code Online (Sandbox Code Playgroud)

这使: 在此处输入图片说明

试图添加face="bold"font规范list

plotly::plot_ly(x =~ df$x, y =~ df$y,marker = list(size=12), type = 'scatter',mode = "markers") %>%
  plotly::add_annotations(text=1:10,showarrow=T,arrowhead=1,x=df$x,y=df$y,font=list(size=10,face="bold"))
Run Code Online (Sandbox Code Playgroud)

并没有真正改变任何东西: 在此处输入图片说明

所以问题是如何让该文本注释以粗体显示。

PS 在我的真实数据中,我想注释点簇,因此注释作为一个单独的层出现。

Tob*_*bel 5

只需将文本输入为 HTML,如下所示:

plotly::plot_ly(x =~ df$x, y =~ df$y,marker = list(size=12), type = 'scatter',mode = "markers") %>%
  plotly::add_annotations(text=sprintf("<b>%s</b>", 1:10),showarrow=T,arrowhead=1,x=df$x,y=df$y,font=list(size=10))
Run Code Online (Sandbox Code Playgroud)