【问题标题】:R plotly: not enough granularity for the size of the bubbles?R plotly:气泡大小的粒度不够?
【发布时间】:2018-07-25 05:49:44
【问题描述】:

在下面代码生成的气泡图中,对于气泡的大小,我没有足够的粒度。最小(大小 100)气泡和最大气泡(大小 2,000,000)之间的比率为 20,000。
因此,大小为 100 的气泡与大小为 12,000 的气泡具有相同的面积。

如何增加气泡大小的粒度?

我玩了一下 plot_ly 的 sizes 参数,但效果不佳(我不完全了解如何使用此参数)
一个快速的解决方法是使用大小的对数而不是大小本身,但我想保持比例。
使用 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

【问题讨论】:

    标签: r plotly scatter-plot ggplotly r-plotly


    【解决方案1】:

    我看不出如何在plot_ly 中完成。缩放并不能解决问题。

    但是 ggplot2 在 100 和 12000 之间给出了很好的区别:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-18
      • 2021-11-26
      • 2023-04-08
      • 2015-11-09
      • 2011-12-23
      • 1970-01-01
      • 2016-07-31
      • 1970-01-01
      相关资源
      最近更新 更多