【问题标题】:How to plot ggplot2 scatter plot with dodged points OR points that are pie-chart?如何绘制带有闪避点或饼图点的 ggplot2 散点图?
【发布时间】:2021-07-04 02:58:48
【问题描述】:

我在一个地块的 5 个样本中发现了 4 个物种。我想在 ggplot2 中用 x 轴上的纬度,y 轴上的经度来可视化它们;并且它们的丰度基本上是按物种着色的大小。我尝试工作并得到以下结果

lat <- c(1,2,3,4,5)
long <- c(13,2,7,5,15)
sp1 <- c(0,10,4,3,2)
sp2 <- c(20,10,14,0,1)
sp3 <- c(10,0,2,3,7)
sp4 <- c(2,0,0,0,12)

df <- data.frame(lat, long, sp1, sp2, sp3, sp4)
library(tidyr)
df.long <- gather(df,
                     key = "species",
                     value = "abundance",
                    sp1, sp2, sp3, sp4)

我想知道,如何将这些点错开以如下图左侧所示?或者,我还尝试在 PIE 大小反映整体丰度的那些点上绘制饼图。我什至不知道这在 R 中是否可行 ..但我在这里开枪。欢迎任何帮助!

【问题讨论】:

    标签: r ggplot2 pie-chart


    【解决方案1】:

    如果要使用闪避位置,设置position = position_dodge()并指定宽度:

    library(ggplot2)
    ggplot(df.long, aes(x = lat, y = long, color = species, size = abundance)) +
      geom_point(position = position_dodge(width = 0.5)) 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-12-22
      • 1970-01-01
      • 2019-02-16
      • 2023-03-09
      • 1970-01-01
      • 2019-07-19
      相关资源
      最近更新 更多