GGPLOT-重新订购条

发布于 2025-01-20 13:08:52 字数 2300 浏览 0 评论 0原文

亲爱的编码社区成员,

正如我的查询标题所示,我想更改下图中条形的顺序

(即让两个“立即”条形出现在“延迟”的) :

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")

enter image description here

## 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╭ゆ眷念 2025-01-27 13:08:52

您可以使用factorordered = t更改 ggplot 解释订购的方式。您的原始绘图代码可以保持不变:

propho.effect.frame$session <- factor(propho.effect.frame$session, c('immediate', 'delayed'), ordered = T)

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")

”在此处输入图像描述

You can use factor with ordered = T to change the way that ggplot interprets the ordering. Your original plotting code can remain the same:

propho.effect.frame$session <- factor(propho.effect.frame$session, c('immediate', 'delayed'), ordered = T)

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")

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文