R plotly : Smaller markers in bubble plot

标签 r plotly markers bubble-chart

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

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")

booo overlapping 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.

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

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))

关于R plotly : Smaller markers in bubble plot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38400343/

相关文章:

javascript - 时间模式下的 Plot.ly : fixed grid size

python - 如何在 Python Poetry 中指定对操作系统的依赖关系?

r - 我正在尝试根据 ZevRoss 博客使用 LeafletR 包制作交互式 map 。但是代码有错误

r - 在 R 中,在字符串数据框列中的 % 符号之前提取数字值

javascript - Plotly 中的多个 X 轴

python - 如何使用 VSCode 调试 JupyterDash 应用程序?

javascript - 计算 MarkerCluster 中的元素数量

matlab - 更改 scatter3 中标记的大小

r - R 中按组运行的数百个线性回归

r - 在分隔符字符数量可变的列上使用 tidyr::separate