我希望在R中使用ggplot重新创建以下条形图,但到目前为止我还没有运气(请忽略白线,我不得不清空确切的数据):
我的数据安排如下,我认为这是适当的:
figure_1 <- tribble(
~"ResponseOption", ~"StimuliFormat", ~"rfg", ~"emmean", ~"SE",
"RF_Ratings", "Picture", "Recollection", 2, 0.03,
"RFBG", "Picture", "Recollection", 1, 0.03,
"RFG", "Picture", "Recollection", 7, 0.03,
"RF_Ratings", "Word", "Recollection", 04, 0.03,
"RFBG", "Word", "Recollection", 3, 0.03,
"RFG", "Word", "Recollection", 5, 0.03,
"RF_Ratings", "Picture", "Familiarity", 2, 0.03,
"RFBG", "Picture", "Familiarity", 1, 0.03,
"RFG", "Picture", "Familiarity", 7, 0.03,
"RF_Ratings", "Word", "Familiarity", 04, 0.03,
"RFBG", "Word", "Familiarity", 3, 0.03,
"RFG", "Word", "Familiarity", 5, 0.03,
"RF_Ratings", "Picture", "Guessing", 2, 0.03,
"RFBG", "Picture", "Guessing", 1, 0.03,
"RFG", "Picture", "Guessing", 7, 0.03,
"RF_Ratings", "Word", "Guessing", 04, 0.03,
"RFBG", "Word", "Guessing", 3, 0.03,
"RFG", "Word", "Guessing", 5, 0.03)
但是我不知道如何在x轴上使用2个分组变量(单词/图片+ RFG / RFBG / RFRatings)。我可以制作3个独立的条形图,并以某种方式(?)将它们连接在一起,但我一直在寻找一种更优雅的解决方案,可以将两个x轴分组变量输入到ggplot中。
任何帮助或指导将不胜感激!
答案 0 :(得分:3)
使用facet_wrap
,最终可以通过使用strip.position
参数在底部传递刻面标签,并使用strip.placement = "outside"
将其添加到绘图区域之外来获得类似的绘图:
ggplot(figure_1, aes(x = StimuliFormat, y = emmean, fill = rfg))+
geom_col(position = position_dodge())+
geom_errorbar(aes(ymin = emmean-SE, ymax = emmean+SE), width =0.2, position = position_dodge(0.9))+
facet_wrap(~ResponseOption, strip.position = "bottom")+
theme_classic()+
theme(strip.placement = "outside")+
labs(x = "", y = "Proportion of hits")
它回答了您的问题吗?