使用GGR模式编辑图形

使用GGR模式编辑图形,r,ggplot2,R,Ggplot2,我写了一些代码来制作一个图表(如下两个) p只需更新stat\u summary的geom参数,而不是在绘图顶部添加geom\u col\u模式 #replicate of your dataframe for_plots <- data.frame(matrix(nrow = 100, ncol=0)) for_plots$condition <- sample(rep(c("Animal", "Smoking"), 100), 100) f

我写了一些代码来制作一个图表(如下两个)


p只需更新
stat\u summary
geom
参数,而不是在绘图顶部添加
geom\u col\u模式

#replicate of your dataframe
for_plots <- data.frame(matrix(nrow = 100, ncol=0))
for_plots$condition <- sample(rep(c("Animal", "Smoking"), 100), 100)
for_plots$smoking_status <- sample(rep(c("Smokers", "Ex"), 100), 100)
n_smoking <- length(which(for_plots$condition == "Smoking"))
for_plots$conflict[for_plots$condition=="Smoking"] <- sample(seq(0.8, 1.3, length.out = n_smoking), n_smoking)
n_animal <- length(which(for_plots$condition == "Animal"))
for_plots$conflict[for_plots$condition=="Animal"] <- sample(seq(0.5, 1, length.out = n_animal), n_animal)
#复制数据帧

谢谢,这正是我想要的!
#replicate of your dataframe
for_plots <- data.frame(matrix(nrow = 100, ncol=0))
for_plots$condition <- sample(rep(c("Animal", "Smoking"), 100), 100)
for_plots$smoking_status <- sample(rep(c("Smokers", "Ex"), 100), 100)
n_smoking <- length(which(for_plots$condition == "Smoking"))
for_plots$conflict[for_plots$condition=="Smoking"] <- sample(seq(0.8, 1.3, length.out = n_smoking), n_smoking)
n_animal <- length(which(for_plots$condition == "Animal"))
for_plots$conflict[for_plots$condition=="Animal"] <- sample(seq(0.5, 1, length.out = n_animal), n_animal)
p <- ggplot(for_plots, aes(x = factor(condition), y = conflict, fill = smoking_status)) + 
  stat_summary(aes(pattern=smoking_status),
               fun = "mean", position = "dodge", 
               geom = "bar_pattern", pattern_fill="black", colour="black") + #edited part
  theme_classic() +
  scale_fill_manual(labels = c("Smokers", "Ex"),
                    values = c("blue", "gold"), guide = "legend", (title = "Smoking status")) +
  scale_color_manual(labels = c("Smokers", "Ex"),
                     values = c("blue", "gold"), guide = "legend", (title = "Smoking status")) +
  labs(x = 'Condition', y = 'Conflict (AUC)') + 
  scale_pattern_manual(values=c("none", "stripe"))+ #edited part
  scale_x_discrete(labels = c('Animal','Smoking')) +
  coord_cartesian(ylim=c(0,1.5)) +
  scale_y_continuous(expand = c(0,0)) 

p + 
  stat_summary(fun.data = mean_se, geom = "errorbar", width = .08, position = position_dodge(0.9))