首页 > 解决方案 > Plotly marker size

问题描述

I am having trouble getting the plotly marker size to work correctly.

test <- data.frame(a = c(1,2,3,5,3,4,2,6,4,5),
                   b = c(12,14,11,10,3,7,5,8,15,2),
                   c = c("d","e","d","f","e","d","f","e","e","f"),
                   d = c(5,5,10,15,10,15,5,10,5,15))
plot_ly()%>%
add_trace(data = test, x = ~a, y = ~b, mode = 'markers', type = 'scatter',
          color = ~c, colors = c("red", "blue", "green"),
          marker = list(size = ~d), text = ~d, hoverinfo = 'text')

I added a text box with the column that is supposed to be used as the marker size and it works correctly, so any help with what is going wrong with the size would be appreciated.

标签: rplotly

解决方案


希望这会有所帮助,其中尺寸由以下定义d

test <- data.frame(a = c(1,2,3,5,3,4,2,6,4,5),
                   b = c(12,14,11,10,3,7,5,8,15,2),
                   c = c("d","e","d","f","e","d","f","e","e","f"),
                   d = c(5,5,10,15,10,15,5,10,5,15))
plot_ly()%>%
  add_trace(data = test, x = ~a, y = ~b, mode = 'markers', type = 'scatter',
            color = ~c, colors = c("red", "blue", "green"),
            size = ~d, text = ~d, hoverinfo = 'text')

推荐阅读