遵循gerrorbar中缺失的美学

kkih6yb8  于 2023-02-14  发布在  其他
关注(0)|答案(1)|浏览(112)

也许现在修改代码已经太晚了。我不得不在ggplot2中重做我的图,但是我做不到。我的错误条没有显示,我不明白为什么。

dev.new()
    ggplot() +
      geom_point(data = conf_intervals, aes(y = mean_ALA, x = mean_LIN, shape=trophic, 
                                            color=feeding_type_2,
                                            size = 3, 
                                            alpha = 0.5)) + scale_shape_manual("Trophic level", values = c(15:19)) +
    geom_errorbar(data = conf_intervals,aes(mean_ALA, ymin = mean_ALA - se_ALA,
                                            ymax = mean_ALA + se_ALA,)) +
    geom_errorbarh(data = conf_intervals,aes(mean_LIN, ymin = mean_LIN - se_LIN,
                                             ymax = mean_LIN + se_LIN)) +
    geom_point(data = CSIA_inverts_basal, aes(y=ALA.d13C, x=LIN.d13C, color=feeding_type_2))
      labs (title="Biplot of compound stable isotopes- Centroids with 95 % CI", subtitle="LIN VS. ALA",
            y=expression({delta}^13*C[ALA]~'\211'~VPDB),
            x=expression({delta}^13*C[LIN]~'\211'~VPDB)) + 
      # guides(color = FALSE, shape = FALSE) +
      theme_classic()
    • 错误:geom_errorbarh需要以下缺少的美观性:y运行rlang::last_error()以查看错误发生的位置。此外:警告信息:忽略未知的美学:x**

下面是我的示例数据:

dput(head(CSIA_inverts_basal))
structure(list(d13C.VPDB = c(-35.10487341, -34.85465717, -34.67216423, 
-34.06032315, -33.68548439, -33.4811546), d15.NAIR = c(-6.321847159, 
-5.384989361, -2.638749276, -4.986045928, -5.946279778, -6.648526348
), ALA.d13C = c(-43.2375195, -44.77813854, -42.1921855, -41.58363894, 
-39.156857, -40.33135344), LIN.d13C = c(-40.864145, -42.32043061, 
-41.4247005, -36.08156681, -39.45744387, -37.76516617), combi = structure(c(1L, 
1L, 1L, 1L, 1L, 1L), levels = c("epilithon", "fresh.leaves", 
"gammarus", "grazing.ephemeroptera", "predatory.plecoptera", 
"salmonid.eyes", "shreddering.plecoptera", "submerged.leaves"
), class = "factor"), feeding_type = c("epilithon", "epilithon", 
"epilithon", "epilithon", "epilithon", "epilithon"), sampling.time = c("summer", 
"fall", "summer", "fall", "fall", "fall"), year = c(2018L, 2016L, 
2018L, 2016L, 2016L, 2016L), split = structure(c(2L, 2L, 2L, 
2L, 2L, 2L), levels = c("consumer", "resource"), class = "factor"), 
    split_2 = c("epilithon", "epilithon", "epilithon", "epilithon", 
    "epilithon", "epilithon"), split_3 = c("epilithon", "epilithon", 
    "epilithon", "epilithon", "epilithon", "epilithon"), feeding_type_2 = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L), levels = c("Epilithon", "Fresh leaves", 
    "Grazer", "Salmonid (Eyes)", "Predator", "Submerged leaves", 
    "Shredder"), class = "factor"), trophic = structure(c(1L, 
    1L, 1L, 1L, 1L, 1L), levels = c("Base", "Non-predatory invertebrate", 
    "Predatory invertebrate", "Predator"), class = "factor")), row.names = 2:7, class = "data.frame")

dput(conf_intervals)
structure(list(trophic = structure(c(1L, 1L, 1L, 2L, 2L, 3L, 
4L), levels = c("Base", "Non-predatory invertebrate", "Predatory invertebrate", 
"Predator"), class = "factor"), feeding_type_2 = structure(c(1L, 
2L, 6L, 3L, 7L, 5L, 4L), levels = c("Epilithon", "Fresh leaves", 
"Grazer", "Salmonid (Eyes)", "Predator", "Submerged leaves", 
"Shredder"), class = "factor"), mean_ALA = c(-42.1, -39.7, -38.7, 
-45.7, -40.3, -42.8, -42.7), mean_LIN = c(-39.2, -40, -37.2, 
-40.8, -35.9, -36.7, -37.9), se_ALA = c(1.1, 1.1, 1.1, 2.2, 1.2, 
1.9, 0.4), se_LIN = c(1.1, 1.1, 0.6, 1.8, 0.9, 1.3, 0.6), N_ALA = c(12L, 
14L, 10L, 9L, 14L, 7L, 17L), LIN_N = c(12L, 14L, 10L, 9L, 14L, 
7L, 17L)), class = "data.frame", row.names = c(NA, -7L))

有人能帮帮我吗?

2ic8powd

2ic8powd1#

geom_errorbarh没有x的美感。它有yxminxmax。我怀疑你在errorbar调用中也混淆了x和y变量,所以仔细检查一下。另外,你应该把alphasize移到aes之外,这样它们就不会出现在图例中。
确保你的代码格式更易于阅读和调试也是一个好主意,限制你的行长度和使用传递给初始ggplot调用的数据的继承也有助于简化一些事情。

ggplot(conf_intervals) +
  geom_point(aes(y = mean_ALA, x = mean_LIN, shape = trophic, 
                 color = feeding_type_2), size = 3, alpha = 0.5) + 
  scale_shape_manual("Trophic level", values = c(15:19)) +
  geom_errorbar(aes(mean_LIN, ymin = mean_ALA - se_ALA,
                    ymax = mean_ALA + se_ALA)) +
  geom_errorbarh(aes(y = mean_ALA, xmin = mean_LIN - se_LIN,
                     xmax = mean_LIN + se_LIN)) +
  geom_point(data = CSIA_inverts_basal, 
             aes(y = ALA.d13C, x = LIN.d13C, color = feeding_type_2)) +
  labs(title = "Biplot of compound stable isotopes- Centroids with 95 % CI", 
       subtitle = "LIN VS. ALA",
       y = expression({delta}^13*C[ALA]~'\211'~VPDB),
       x = expression({delta}^13*C[LIN]~'\211'~VPDB)) + 
  theme_classic()

相关问题