一个R脚本

library(ggplot2)
#创建一个示例数据框
# 假设您有一个新的数据集 data
# 创建示例数据
data <- data.frame(
  Group = factor(rep(c("group1", "group2"), each = 2)),
  Type = factor(rep(c("type1", "type2", "type1", "type2"), times = 2)),
  Value = c(5, 8, 7, 9),
  UpperError = c(6, 9, 8, 10),
  LowerError = c(4, 7, 6, 8)
)

# 创建颜色映射
color_mapping <- c("type1" = "red", "type2" = "blue")

# 创建图形
ggplot(data, aes(x = Group, y = Value, group = Type, color = Type)) +
  geom_point(position = position_dodge(width = 0.2)) +
  geom_errorbar(aes(ymin = LowerError, ymax = UpperError), position = position_dodge(width = 0.2), width = 0.1) +
  geom_line(aes(group = Type, linetype = "solid")) +
  scale_color_manual(values = color_mapping) +  # 手动指定颜色映射
  theme_minimal() +
  labs(x = "Group", y = "Value", title = "Two Groups with Error Bars and Connecting Lines")