简体   繁体   English

R plotly:在极坐标散点图中添加文本

[英]R plotly: Add text in polar scatter plot

Let's say I have a simple scatter plot using R plotly .假设我有一个使用 R plotly的简单散点图。 And I want to put text at each points of scatter plot as shown.我想在散点图的每个点上放置文本,如图所示。

Simple R polar chart :简单的 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

Output Chart :输出图表

在此处输入图片说明

In the same way using plot_ly with scatterpolar , How can I put text at the center of each bubble with some value let's say value of size column.?在使用同样的方式plot_lyscatterpolar ,我怎样才能把文字在每个气泡具有一定的价值假设值中心size列?

Thanks in Advance!提前致谢!

Adding answer, for future reference in SO community.添加答案,以供将来在 SO 社区中参考。 I found the solution using add_trace我使用add_trace找到了解决方案

R code :代码

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

Chart :图表

在此处输入图片说明

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

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