GGPLOT-重新订购条
亲爱的编码社区成员,
正如我的查询标题所示,我想更改下图中条形的顺序
(即让两个“立即”条形出现在“延迟”的) :
ggplot(propho.effect.frame, aes(session, fit, color=modality, fill=modality)) + geom_bar(stat='identity',position="dodge") + geom_errorbar(aes(ymin=fit-se, ymax=fit+se), width=0.4, position=position_dodge(width=0.9)) + theme_bw(base_size=12) + labs(y="score", title="Phonological Production Task")
## INITIAL DATAFRAME ##############################################
PID session group list modality stim score
1 AL201 immediate A Y NOLM FAHRRAD 0
2 AL201 immediate A Y NOLM BUCH 1
3 AL201 immediate A X OLM SCHAF 0
4 AL201 immediate A X OLM STUHL 0
5 AL201 immediate A Y NOLM AFFE 0
6 AL201 immediate A Y NOLM KERZE 0
7 AL201 immediate A X OLM KIRCHE 0
8 AL201 immediate A X OLM NAGEL 0
9 AL201 immediate A X OLM PFANNE 0
10 AL201 immediate A Y NOLM KLEID 0
11 AL201 immediate A X OLM HAHN 0
12 AL201 immediate A X OLM KAMM 0
13 AL201 immediate A Y NOLM PILZ 1
14 AL201 immediate A Y NOLM BIRNE 0
15 AL201 immediate A X OLM VOGEL 0
16 AL201 immediate A X OLM SCHALE 0
17 AL201 immediate A X OLM PFEIL 0
18 AL201 immediate A Y NOLM TROMMEL 0
19 AL201 immediate A X OLM LEITER 0
20 AL201 immediate A Y NOLM KORB 0
>
## propho.effect.frame (cf. ggplot code) ##########################
modality session fit se lower upper
1 NOLM delayed 0.3525117 0.08066153 0.2140540 0.5211437
2 OLM delayed 0.6472552 0.07339121 0.4942436 0.7750446
3 NOLM immediate 0.3271910 0.07654911 0.1974255 0.4901584
4 OLM immediate 0.5659339 0.07947359 0.4088293 0.7108196
尝试应用论坛上类似查询的建议但没有成功(例如 propho $session <- Factor(propho$session,levels = c("immediate","delayed")
) ,我来找你是希望找到答案,
谢谢大家 。与我分享。
Dear Members of the Coding Community,
As the title of my query suggests I'd like to change the order of the bars in the following plot
(i.e. having both "immediate" bars appear before the "delayed" ones) :
ggplot(propho.effect.frame, aes(session, fit, color=modality, fill=modality)) + geom_bar(stat='identity',position="dodge") + geom_errorbar(aes(ymin=fit-se, ymax=fit+se), width=0.4, position=position_dodge(width=0.9)) + theme_bw(base_size=12) + labs(y="score", title="Phonological Production Task")
## INITIAL DATAFRAME ##############################################
PID session group list modality stim score
1 AL201 immediate A Y NOLM FAHRRAD 0
2 AL201 immediate A Y NOLM BUCH 1
3 AL201 immediate A X OLM SCHAF 0
4 AL201 immediate A X OLM STUHL 0
5 AL201 immediate A Y NOLM AFFE 0
6 AL201 immediate A Y NOLM KERZE 0
7 AL201 immediate A X OLM KIRCHE 0
8 AL201 immediate A X OLM NAGEL 0
9 AL201 immediate A X OLM PFANNE 0
10 AL201 immediate A Y NOLM KLEID 0
11 AL201 immediate A X OLM HAHN 0
12 AL201 immediate A X OLM KAMM 0
13 AL201 immediate A Y NOLM PILZ 1
14 AL201 immediate A Y NOLM BIRNE 0
15 AL201 immediate A X OLM VOGEL 0
16 AL201 immediate A X OLM SCHALE 0
17 AL201 immediate A X OLM PFEIL 0
18 AL201 immediate A Y NOLM TROMMEL 0
19 AL201 immediate A X OLM LEITER 0
20 AL201 immediate A Y NOLM KORB 0
>
## propho.effect.frame (cf. ggplot code) ##########################
modality session fit se lower upper
1 NOLM delayed 0.3525117 0.08066153 0.2140540 0.5211437
2 OLM delayed 0.6472552 0.07339121 0.4942436 0.7750446
3 NOLM immediate 0.3271910 0.07654911 0.1974255 0.4901584
4 OLM immediate 0.5659339 0.07947359 0.4088293 0.7108196
After trying to apply the suggestions of similar queries on the forum without success (e.g. propho$session <- factor(propho$session, levels = c("immediate","delayed")
) , I come to you in hope of finding an answer.
Thank you all in advance for any insights you could share with me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
factor
与ordered = t
更改 ggplot 解释订购的方式。您的原始绘图代码可以保持不变:You can use
factor
withordered = T
to change the way that ggplot interprets the ordering. Your original plotting code can remain the same: