gpt4 book ai didi

R plotly : Smaller markers in bubble plot

转载 作者:行者123 更新时间:2023-12-01 16:02:56 25 4
gpt4 key购买 nike

我在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com