[英]Reorder discrete variables in ggplot2
I'm trying to reorder the discrete variables that I have in ggplot2. 我正在尝试对ggplot2中的离散变量重新排序。 I would like to display it like WTT, KOT, WTD, KOD in that order in the graph however, I am currently getting KOD,KOT,WTD,WTT in the graph.
我想在图中按此顺序显示它,例如WTT,KOT,WTD,KOD,但是,我目前在图中获得KOD,KOT,WTD,WTT。 I have tried using match to manually order the dataframe but I don't see a change in the graph itself.
我尝试使用match手动对数据框进行排序,但看不到图形本身的变化。
The data looks something like this: 数据看起来像这样:
type mean
WTT 100
KOT 110
WTD 1000
KOD 1300
The means will vary and I only care that the correct factors are paired to each other in a graph. 平均值会有所不同,我只关心正确的因素在图中相互配对。
And the code I am primarily using is the following: 我主要使用的代码如下:
graph = ggplot(data = data_subset,aes(y = Mean, x = Type, color = Type))
直接的方法是重新分级您的type
变量:
graph = ggplot(data = data_subset,aes(y = Mean, x = factor(Type, levels = c("WTT", "KOT", "WTD", "KOD"), color = Type))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.