ggplot - y 轴的顺序与数据集的顺序不同
ggplot - order of y axis is not like the one of the dataset
我得到了以下数据集:
Skalen
Werte
1
Allgemeine Beanspruchung
1.55
2
Emotionale Beanspruchung
1.59
3
Soziale Beanspruchung
1.79
4
Konflikte/Leistungsdruck
1.76
5
Übermüdung
1.79
6
Energielosigkeit
2.13
7
Somatische Beanspruchung
1.52
8
Erfolg
2.74
9
Soziale Erholung
3.26
10
Somatische Erholung
3.41
11
Allgemeine Erholung
3.84
12
Schlaf
4.29
13
Gestörte Pause
1.07
14
Emotionale Erschöpfung
1.36
15
Verletzungsanfälligkeit
1.59
16
In-Form-sein
3.28
17
Persönliche Verwirklichung
2.42
18
Selbstwirksamkeitsüberzeugung
3.29
19
Selbstregulation
3.41
然后我使用这段代码将其绘制为垂直线图
ggplot(data=df_ebf, aes(x=Skalen, y=Werte,group="")) +
geom_line() +
geom_point() +
coord_flip()
结果是这样的:
这些值属于 y 轴上的正确描述。但是顺序是按字母顺序颠倒的。我希望顺序与数据集中的顺序相同。
我找到了解决这个问题的不同方法。
我用
更改了数据框中变量的顺序
df <- df %>%
map_df(rev)
然后使用 Jon Spring 在 ggplot 命令中建议的第一个函数
ggplot(data=df, aes(x=forcats::fct_inorder(Skalen), y=Werte, group="")) +
geom_line() +
geom_point() +
coord_flip()
现在我在情节中得到了正确的顺序。
感谢支持!
我得到了以下数据集:
Skalen | Werte | |
---|---|---|
1 | Allgemeine Beanspruchung | 1.55 |
2 | Emotionale Beanspruchung | 1.59 |
3 | Soziale Beanspruchung | 1.79 |
4 | Konflikte/Leistungsdruck | 1.76 |
5 | Übermüdung | 1.79 |
6 | Energielosigkeit | 2.13 |
7 | Somatische Beanspruchung | 1.52 |
8 | Erfolg | 2.74 |
9 | Soziale Erholung | 3.26 |
10 | Somatische Erholung | 3.41 |
11 | Allgemeine Erholung | 3.84 |
12 | Schlaf | 4.29 |
13 | Gestörte Pause | 1.07 |
14 | Emotionale Erschöpfung | 1.36 |
15 | Verletzungsanfälligkeit | 1.59 |
16 | In-Form-sein | 3.28 |
17 | Persönliche Verwirklichung | 2.42 |
18 | Selbstwirksamkeitsüberzeugung | 3.29 |
19 | Selbstregulation | 3.41 |
然后我使用这段代码将其绘制为垂直线图
ggplot(data=df_ebf, aes(x=Skalen, y=Werte,group="")) +
geom_line() +
geom_point() +
coord_flip()
结果是这样的:
这些值属于 y 轴上的正确描述。但是顺序是按字母顺序颠倒的。我希望顺序与数据集中的顺序相同。
我找到了解决这个问题的不同方法。 我用
更改了数据框中变量的顺序df <- df %>%
map_df(rev)
然后使用 Jon Spring 在 ggplot 命令中建议的第一个函数
ggplot(data=df, aes(x=forcats::fct_inorder(Skalen), y=Werte, group="")) +
geom_line() +
geom_point() +
coord_flip()
现在我在情节中得到了正确的顺序。
感谢支持!