我有一个名为pollen_agg的数据帧.以下是其dput(pollen_agg)的 struct :

pollen_agg <- structure(list(taxa = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 3L, 
3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L), levels = c("G. andrewsii", 
"G. puberulenta", "G. x billingtonii"), class = "factor"), site = structure(c(1L, 
2L, 3L, 4L, 5L, 6L, 1L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 6L), levels = c("BS", 
"HRP", "LHF", "SHP", "SPNP", "SRD"), class = "factor"),
presence.of.hybrids = structure(c(1L, 1L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 2L, 2L, 2L), levels = c("absent", 
"present"), class = "factor"), percent_germination_mean = c(71.3333333, 
71.1111111, 88, 79, 21.1111111, 64, 70.5555556, 51.3333333, 65.8888889, 
45.1111111, 75.2222222, 71, 40.3333333, 81.6666667, 42.5555556, 
64.4444444), percentage_germination_se = c(4.6706332, 0.7286043, 
5.0037023, 2.8738927, 6.2341156, 7.535103, 2.7844365, 21.5432382, 
3.8216408, 8.0377197, 2.5410215, 13.5660251, 3.0061665, 3.7118429, 
0.8678055, 2.8888889)), row.names = c(NA, -16L), class = "data.frame")

我正在try 为这些数据绘制带有误差线的点,下面是我为此使用的代码块:

ggplot(pollen_agg, aes(x = presence.of.hybrids, 
                       y = percent_germination_mean, 
                       color = taxa)) +
  scale_color_manual('Taxa', values = c('#a1d99b', '#9ebcda', '#8856a755')) +
  geom_point(position = position_dodge(width = 0.5), size = 3) +
  geom_errorbar(
    aes(ymin = percent_germination_mean - percentage_germination_se, 
        ymax = percent_germination_mean + percentage_germination_se),
    position = position_dodge(width = 0.5),
    width = 0.2
  ) +
  labs(title = "Percentage Germination",
       x = "Presence of Hybrids",
       y = "Percent Germination",
       color = "Taxa") +
  theme_classic() +
  scale_y_continuous(limits = c(0, 100))

但即使代码中有position_dodge个,我的点数和错误条也不能回避(见下文).

enter image description here

推荐答案

aes(fill = site)添加到ggplot,然后添加guides(fill = "none")以删除其图例.

library(ggplot2)

ggplot(pollen_agg, aes(x = presence.of.hybrids, 
                       y = percent_germination_mean, 
                       color = taxa,
                       fill = site)) +
  scale_color_manual('Taxa', values = c('#a1d99b', '#9ebcda', '#8856a755')) +
  geom_point(position = position_dodge(width = 0.5), size = 3) +
  geom_errorbar(aes(ymin = percent_germination_mean - percentage_germination_se, 
                    ymax = percent_germination_mean + percentage_germination_se),
                position = position_dodge(width = 0.5), width = 0.2) +
  labs(title = "Percentage Germination",
       x = "Presence of Hybrids",
       y = "Percent Germination",
       color = "Taxa") +
  theme_classic() +
  guides(fill = "none") +
  scale_y_continuous(limits = c(0, 100))

创建于2024-01-26,共reprex v2.0.2

R相关问答推荐

导入到固定列宽的R中时出现问题

在ggplot Likert条中添加水平线

在值和NA的行顺序中寻找中断模式

有没有一种方法可以从函数中创建一个值的列表,然后将这些值变成R中的直方图?我一直觉得不行

在"gt"表中添加第二个"groupname_col",而不连接列值

如何在Chart_Series()中更改轴值的 colored颜色 ?

提取具有连续零值的行,如果它们前面有R中的有效值

如何使用STAT_SUMMARY向ggplot2中的密度图添加垂直线

如何在ggplot图中找到第二轴的比例

根据文本字符串中的值粘贴新列

使用较长的查询提取具有部分匹配的列表中的较短目标,

多个模拟序列间的一种预测回归关系

ComplexHEAT:使用COLUMN_SPLIT时忽略COLUMN_ORDER

合并后返回列表的数据帧列表

我如何go 掉盒子图底部的数字?

R -如何分配夜间GPS数据(即跨越午夜的数据)相同的开始日期?

我如何使用tidyselect来传递一个符号数组,比如Pivot_Long?

解析嵌套程度极高的地理数据

如何为混合模型输出绘制不同的线型?

如何使用包含要子集的值的列表或数据框来子集多个列?