R plotly:在极坐标散点图中添加文本
R plotly: Add text in polar scatter plot
假设我有一个使用 R plotly
的简单散点图。
我想在散点图的每个点上放置文本,如图所示。
简单R极坐标图:
library(plotly)
p <- plot_ly(
type = 'scatterpolar',
r = c(0,1,2,2),
theta = c(0,45,90,120),
size = c(10, 20, 30, 40),
sizes = c(100, 300),
mode = 'markers'
)
p
输出图表:
以与 plot_ly
和 scatterpolar
相同的方式使用,我如何将文本放在每个气泡的中心,让我们说 size
列的值。?
提前致谢!
添加答案,以供将来在 SO 社区中参考。
我使用 add_trace
找到了解决方案
R码:
library(plotly)
p <- plot_ly(
type = 'scatterpolar',
r = c(0,1,2,2),
theta = c(0,45,90,120),
size = c(10, 20, 30, 40),
sizes = c(100, 300),
mode = 'markers'
) %>%
add_trace(
r = c(0,1,2,2),
theta = c(0,45,90,120),
mode = "text",
text = c(10, 20, 30, 40),
textfont = list(color = '#000000', size = 12)
)
p
图表:
假设我有一个使用 R plotly
的简单散点图。
我想在散点图的每个点上放置文本,如图所示。
简单R极坐标图:
library(plotly)
p <- plot_ly(
type = 'scatterpolar',
r = c(0,1,2,2),
theta = c(0,45,90,120),
size = c(10, 20, 30, 40),
sizes = c(100, 300),
mode = 'markers'
)
p
输出图表:
以与 plot_ly
和 scatterpolar
相同的方式使用,我如何将文本放在每个气泡的中心,让我们说 size
列的值。?
提前致谢!
添加答案,以供将来在 SO 社区中参考。
我使用 add_trace
R码:
library(plotly)
p <- plot_ly(
type = 'scatterpolar',
r = c(0,1,2,2),
theta = c(0,45,90,120),
size = c(10, 20, 30, 40),
sizes = c(100, 300),
mode = 'markers'
) %>%
add_trace(
r = c(0,1,2,2),
theta = c(0,45,90,120),
mode = "text",
text = c(10, 20, 30, 40),
textfont = list(color = '#000000', size = 12)
)
p
图表: