R语言 道奇在小提琴情节中失败

r6l8ljro  于 2023-01-18  发布在  其他
关注(0)|答案(1)|浏览(171)

我想画出一致效应(不一致减一致)作为每个刺激年龄和React类型组合的小提琴图。这是我的代码到目前为止的样子。我还不满意这种表示。我如何才能改变它,以便对于四个条件中的每一个(大人皱眉,大人微笑,小孩皱眉,孩子笑)我得到的小提琴对应的情节横排在对方旁边?提前感谢帮助。附件是代码和 Dataframe 的摘录。
violin plot

dataset$congruency_effect <- ifelse(dataset$congruency == "congruent", dataset$avgAmplitude, -dataset$avgAmplitude)

p <- ggplot(dataset, aes(x = stimulusResponse, y = congruency_effect, fill = congruency_effect, group = stimulusAge)) + 
  geom_violin() +
  geom_point(position = position_dodge(width = 0.75), size = 3, stat = "summary", fun.y = "mean") +
  scale_fill_manual(values = c("#F8766D", "#00BFC4")) +
  ggtitle("Conventional EEG 350-450 ms") +
  scale_y_continuous(limits = c(-5, 5)) +
  facet_wrap(~stimulusAge, scales = "free_x")

EEG_Conventional450_age_response <- p + theme(
  # Set the plot title and axis labels to APA style
  plot.title = element_text(face = "bold", size = 16),
  axis.title = element_text(face = "bold", size = 14),
  # Set the axis tick labels to APA style
  axis.text = element_text(size = 12),
  # Set the legend title and labels to APA style
  legend.title = element_text(face = "bold", size = 14),
  legend.text = element_text(size = 12),
  # Set the plot and panel backgrounds to white
  panel.background = element_rect(fill = "white"),
  plot.background = element_rect(fill = "white")
)

EEG_Conventional450_age_response

excerpt data frame

  • ggplot中参数的几种排列
igetnqfo

igetnqfo1#

这与分组美学有关。去掉它,你的情节就会起作用。

library(ggplot2)

set.seed(42)
dataset <- data.frame(stimulusResponse =  rep(c("frown", "smile"), each = 20), 
                      congruency_effect = rnorm(40), 
                      stimulusAge = rep(c("baby", "adult"), 20))

## removed group = stimulusAge
ggplot(dataset, aes(x = stimulusResponse, y = congruency_effect)) + 
  geom_violin() +
  geom_point(position = position_dodge(width = 0.75), size = 3, stat = "summary") +
  facet_wrap(~stimulusAge, scales = "free_x")

相关问题