r - 使情节注释字体加粗
问题描述
我想添加annotation
到由's包scatter
生成的绘图中,并让文本以粗体显示。R
plotly
我正在努力:
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))
试图添加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"))
所以问题是如何让文本注释以粗体显示。
PS 在我的真实数据中,我想注释点簇,因此注释作为单独的层出现。
解决方案
只需将文本输入为 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))
推荐阅读
- javascript - this2.'function' 不是函数 - React Native
- python - 如何在不检测具有相同数字的数字的情况下从列表中检查数字?
- c# - 以编程方式防止在 SQL c# 中插入重复记录
- firebase - 无需通过 javascript 进行身份验证的 Firestore 安全规则
- pandas - Pandas 中日期时间的 Groupby Year 和 Month
- javascript - 刷新 MEN 堆栈网页而不刷新整个页面
- javascript - Java aes加密代码,如何通过nodejs实现?
- html - 在 HTML 文本框中上传文件选项/图标
- excel - 使用目标格式将范围从工作表复制到另一个工作表?
- excel - 如何使用 Excel Interop (VB.net) 获取 CustomDocumentProperties?