简体   繁体   English

R plotly:气泡大小的粒度不够?

[英]R plotly: not enough granularity for the size of the bubbles?

In the bubble graph generated by the code below, I don't have enough granularity for the sizes of the bubble.在下面代码生成的气泡图中,我没有足够的粒度来确定气泡的大小。 There is a ratio of 20,000 between the smallest (size 100) bubble and the largest bubble (size 2,000,000).最小(大小 100)气泡和最大气泡(大小 2,000,000)之间的比率为 20,000。
As a consequence the bubble of size 100 has the same area than the bubble of size 12,000.因此,大小为 100 的气泡与大小为 12,000 的气泡具有相同的面积。

How could I increase the granularity for the sizes of the bubble?如何增加气泡大小的粒度?

I played a bit with the parameter sizes of plot_ly but it didn't give anything good (I do not totally understand how to use this parameter)我玩了一下 plot_ly 的参数大小,但没有给出任何好处(我不完全理解如何使用这个参数)
A quick fix would be to use the logarithm of the size instead of the size itself but I would like to keep the proportionality.一个快速的解决方法是使用大小的对数而不是大小本身,但我想保持比例。
A solution with plot_ly would be my first choice but maybe ggplotly is the way to do it.使用 plot_ly 的解决方案将是我的第一选择,但也许 ggplotly 是这样做的方法。

df <- data.frame(c(1,2,3,4,5,6,7,8), 
c(5,20,-10,40,-3,6,10,-15),c(1e2,1.2e4,9e4,4.2e5,2e6,1.5e6,5.4e5,8e5))
colnames(df) <- c("X", "Y", "size")

p=plot_ly(df, x = ~X, y = ~Y, type="scatter", text = paste("size:", 
df$size), mode = "markers", size = ~abs(df$size), 
marker=list(sizemode='diameter'))
p

I don't see how it could be done in plot_ly .我不知道如何在plot_ly完成。 Scaling does not fix the problem.缩放并不能解决问题。

But ggplot2 gives you a nice difference between 100 and 12000:但是 ggplot2 为您提供了 100 和 12000 之间的一个很好的差异:

a <- ggplot(df, aes(x=X, y=Y, size = size)) + geom_point(colour = "dodgerblue3") + theme_bw()
ggplotly(a)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM