R Plotly:气泡图中的较小标记

R Plotly: Smaller markers in bubble plot

我在 Plotly(针对 R)中制作了一个气泡图,但我不断得到重叠的标记。有没有办法 "scale down" 所有标记,以便保留它们的相对大小但没有重叠?我想保持绘图的尺寸相同。这是一个测试用例:

test <- data.frame(matrix(NA, ncol=3, nrow=14))
colnames(test) <- c("Group", "Numbers", "Days")
loop<- 1
for(i in 1:7){
    test[i,] <- c(1, i, loop)
    loop <- loop * 1.5
}
loop <- 1
for(i in 1:7){
    test[i+7,] <- c(2, i, loop)
    loop <- loop * 1.3
}
plot_ly(test, x=Group, y=Numbers, size=Days, mode="markers")

执行此类操作的一种方法是调整 marker 中的 sizeref(和 size)参数:

plot_ly(test, x=Group, y=Numbers, mode="markers",
    marker = list(size = Days, sizeref = 0.15))

plot_ly(test, x=Group, y=Numbers, mode="markers", 
    marker = list(size = Days/2, sizeref = 0.1))

plot_ly(test, x=Group, y=Numbers, size = Days, mode="markers",
    marker = list(sizeref = 2.5)) # Days data in the hoverinfo with this method

来自https://plot.ly/r/reference/

sizeref (number)
default: 1
Has an effect only if marker.size is set to a numerical array. Sets the scale factor used to determine the rendered size of marker points. Use with sizemin and sizemode.

如果您希望悬停文本与您的原始情节相匹配,您可以明确定义它:

plot_ly(test, x=Group, y=Numbers, mode="markers",
    marker = list(size = Days, sizeref = 0.15),
    hoverinfo = "text", 
    text = paste0("(", Group, ", ", Numbers, ")<br>", "Days (size): ", Days))