1

我正在尝试绘制此数据的误差线:

type id tn subtype cl means   se
TRA  1  4       A X1 600.5  2.3
TRA  1  4       A X2 550.5  5.2
TRA  1  4       A X3 620.5 19.3
TRA  1  4       A X4 590.5  3.1
TRA  1  4       A X5 610.5 10.1
TRA  1  4       A X6 580.5 13.2
TRA  1  4       B X1 605.5  3.2
TRA  1  4       B X2 555.5  1.2
TRA  1  4       B X3 615.5 12.4
TRA  1  4       B X4 580.5 12.1
TRA  1  4       B X5 600.5  3.4
TRA  1  4       B X6 585.5  5.3

该数据是使用以下代码生成的:

data <- c()

data[["type"]] <- c(rep(c("TRA"), 12))
data[["id"]] <- c(rep(c(1), 12))
data[["tn"]]  <- c(rep(c(4), 12))
data[["subtype"]] <- c("A", "A", "A", "A", "A", "A", "B", "B", "B", "B", "B", "B")
data[["cl"]] <- c("X1", "X2", "X3", "X4", "X5", "X6", "X1", "X2", "X3", "X4", "X5", "X6")
data[["means"]] <- c(600.5, 550.5, 620.5, 590.5, 610.5, 580.5, 605.5, 555.5, 615.5, 580.5, 600.5, 585.5)
data[["se"]] <- c(2.3, 5.2, 19.3, 3.1, 10.1, 13.2, 3.2, 1.2, 12.4, 12.1, 3.4, 5.3)
data <- as.data.frame(as.list(data))

当我尝试仅使用一个cl(例如 A)来绘制误差线时。我正确地得到了带有误差线的图。但是它确实使用 A 和 B 发生,结果是 在此处输入图像描述

剧情代码:

ggplot(data, aes(x=cl, y=means, fill=subtype))  +
  geom_bar(stat="identity", color="black", position=position_dodge()) +
  geom_errorbar(aes(ymin=means-se, ymax=means+se), width=.3, color="darkblue")

我试过:

data$means <- factor(data$means)

现在甚至不显示错误栏。

我究竟做错了什么?

4

0 回答 0