带误差条的分组图
Grouped graph with error bars
我需要用 ggplot2 在 R 中重现这个图
有人知道怎么做吗?
谢谢。
假设您正在处理误差条的均值和标准差,您可以这样做(我创建了一个数据框,我认为它可能看起来像您的数据框):
library(tidyverse)
df <- data.frame(num = runif(160, min = 0, max = 1),
class = c(rep(c(rep("t-logistic", 4), rep("NSC", 4),
rep("Poisson", 4), rep("PCC", 4), rep("Sparse PCC", 4),
rep("Sup. PCC", 4), rep("Sparse PLS", 4), rep("SVM", 4)), 5)),
cat = c(rep(c("A", "B", "C", "D"), 40)))
df1 <- df %>%
group_by(class, cat) %>%
summarize(mean = mean(num), sd = sd(num))
ggplot(df1, aes(class, mean, color = cat))+
geom_point(position = position_dodge(width = 0.6))+
geom_errorbar(aes(class, ymin = (mean - 2*sd), ymax = (mean + 2*sd)),
position = position_dodge(width = 0.6))+
theme_bw()
这会给你这张图:
我需要用 ggplot2 在 R 中重现这个图
有人知道怎么做吗? 谢谢。
假设您正在处理误差条的均值和标准差,您可以这样做(我创建了一个数据框,我认为它可能看起来像您的数据框):
library(tidyverse)
df <- data.frame(num = runif(160, min = 0, max = 1),
class = c(rep(c(rep("t-logistic", 4), rep("NSC", 4),
rep("Poisson", 4), rep("PCC", 4), rep("Sparse PCC", 4),
rep("Sup. PCC", 4), rep("Sparse PLS", 4), rep("SVM", 4)), 5)),
cat = c(rep(c("A", "B", "C", "D"), 40)))
df1 <- df %>%
group_by(class, cat) %>%
summarize(mean = mean(num), sd = sd(num))
ggplot(df1, aes(class, mean, color = cat))+
geom_point(position = position_dodge(width = 0.6))+
geom_errorbar(aes(class, ymin = (mean - 2*sd), ymax = (mean + 2*sd)),
position = position_dodge(width = 0.6))+
theme_bw()
这会给你这张图: