简体   繁体   中英

R plotly: Add text in polar scatter plot

Let's say I have a simple scatter plot using R plotly . And I want to put text at each points of scatter plot as shown.

Simple R polar chart :

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.?

Thanks in Advance!

Adding answer, for future reference in SO community. I found the solution using 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 :

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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