如何包括抖动和地理点

How can I include jitter and geopoint

提问人:Madelein Victor 提问时间:7/15/2023 更新时间:7/15/2023 访问量:8

问:

我目前正在编写一个代码,该代码涉及表示在防护林带(是,否)上收集的物种总重量的平均标准偏差,此外,我希望误差线表示平均值的置信区间。但是我得到了误差线,但是我想添加抖动图和几何点。(请参阅我之前的图片问题,同样的问题)

如果它排除了抖动和地理点,则不会产生任何输出。我怎样才能以不同的方式做到这一点?

法典:

# Calculate the mean and standard deviation for each level of the variable
mean_sd_yes <- data %>%
  filter(`Type of plot with shelterbelt` == "Yes") %>%
  group_by("Yes") %>%
  summarise(mean_weight = mean(Weight, na.rm = TRUE),
            sd_weight = sd(Weight, na.rm = TRUE))

#confidence interval
mean_sd_yes$ci_lower <- mean_sd_yes$mean_weight - qt(0.975, 12 - 1) * mean_sd_yes$sd_weight / sqrt(12)
mean_sd_yes$ci_upper <- mean_sd_yes$mean_weight + qt(0.975, 12 - 1) * mean_sd_yes$sd_weight / sqrt(12)

mean_sd_no <- data %>%
  filter(`Type of plot with shelterbelt` == "No") %>%
  group_by("No") %>%
  summarise(mean_weight = mean(Weight, na.rm = TRUE),
            sd_weight = sd(Weight, na.rm = TRUE))

#confidence interval
mean_sd_no$ci_lower <- mean_sd_no$mean_weight - qt(0.975, 8 - 1) * mean_sd_no$sd_weight / sqrt(8)
mean_sd_no$ci_upper <- mean_sd_no$mean_weight + qt(0.975, 8 - 1) * mean_sd_no$sd_weight / sqrt(8)

# Create a separate dataframe for the points
points_df_yes <- data %>%
  filter(`Type of plot with shelterbelt` == "Yes") %>%
  group_by("Yes", sd) %>%
  summarise ("Yes", sd)

points_df_no <- data %>%
  filter(`Type of plot with shelterbelt` == "No") %>%
  group_by("No", sd) %>%
  summarise ("No", sd)

# Plot the mean and error bars
ggplot(mean_sd, aes(x = `Type of plot with shelterbelt`, y = sd_weight)) +
  geom_errorbar(data = mean_sd_yes, aes(x = "Yes",
                                        ymin = ci_lower,
                                        ymax = ci_upper),
                width = 0.2) +
  geom_errorbar(data = mean_sd_no, aes(x= "No",
                                       ymin = ci_lower,
                                       ymax = ci_upper),
                width = 0.2) +
  geom_jitter(data = points_df_yes, aes(x = "Yes", y = sd), position = position_jitter(0.2), color = "darkgray") +
  geom_jitter(data = points_df_no, aes(x = "No", y = sd), position = position_jitter(0.2), color = "darkgray") +
  geom_pointrange(aes(ymin = ci_lower, ymax = ci_upper), data = mean_sd_yes ) +
  geom_pointrange(aes(ymin = ci_lower, ymax = ci_upper), data = mean_sd_no ) +
  labs(x = "Type of plot with shelterbelt", y = "Mean Weight")
平均 置信区 间误差条 地理点 抖动

评论


答: 暂无答案