【发布时间】:2019-10-21 03:29:34
【问题描述】:
我正在尝试使用 plotly 生成加权散点图/气泡图。我的数据集包含 4 列:
1) 基准测试 2) 型号 3) 改进 4) 重量
我试图以 x 轴为基准,以 y 轴为模型。点的大小是权重,颜色是基于改进值的渐变。除了渐变,我可以让它全部工作。
见下面的代码:
BenchmarkQuant <- c("A","A","A","B","B","B","C","C","C")
ModelQuant <- c("X","Y","Z","X","Y","Z","X","Y","Z")
ModelImprovement <- c(runif(9))
SumExposure <- c(runif(9))*100
data <- as.data.frame(cbind(BenchmarkQuant,ModelQuant,ModelImprovement,SumExposure))
data$SumExposure <- as.numeric(data$SumExposure)
p <- plot_ly(data,
x = ~BenchmarkQuant,
y = ~ModelQuant,
type = 'scatter',
mode = 'markers',
size = ~SumExposure,
color = (ModelImprovement), #These are the 2 lines causing issues
colors = 'Reds', #These are the 2 lines causing issues
#Choosing the range of the bubbles' sizes:
sizes = c(20, 75),
marker = list(opacity = 0.5, sizemode = 'diameter')) %>%
layout(title = 'Model Comparison',
xaxis = list(showgrid = FALSE),
yaxis = list(showgrid = FALSE),
showlegend = TRUE)
p
我收到以下错误消息:
Error in Summary.factor(c(1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L), na.rm = TRUE) :
‘range’ not meaningful for factors
In addition: Warning message:
`line.width` does not currently support multiple values.
运行上述代码时,如果我不包含关于颜色的 2 行,则它可以工作,除非没有渐变。
【问题讨论】:
标签: r plotly scatter-plot r-plotly bubble-chart