2
在此先感谢您的帮助。我一直在寻找堆栈溢出和谷歌与这个问题,并没有取得成功。如何做并排条形图ggplot并保留原始排序
我需要一个并排的单词水平条形图和它的频率在两个文件中。
我的数据帧是如下:
head(comp,10)
WORD FREQ RDFREQ
170 project 67 5
20 business 64 14
117 management 53 13
59 development 34 4
211 support 27 6
215 systems 25 10
102 information 22 2
201 software 21 6
203 solutions 20 2
220 technical 20 2
我已经使用熔体创建如下面的频率帧:
dfp1 <- melt(comp, value.factor = TRUE)
head(dfp1,20)
WORD variable value
1 project FREQ 67
2 business FREQ 64
3 management FREQ 53
4 development FREQ 34
5 support FREQ 27
6 systems FREQ 25
7 information FREQ 22
8 software FREQ 21
9 solutions FREQ 20
10 technical FREQ 20
11 applications FREQ 19
12 planning FREQ 18
我到情节代码是
g <- ggplot(dfp1, aes(x = WORD, y= value, order=- as.integer(value)))
g <- g + geom_bar(aes(fill = variable), position = "dodge", stat="identity")
g <- g + coord_flip()
g <- g + theme(axis.text.y = element_text(size=12))
g <- g + labs(x = "Keyword", y = "Count",
title = paste("File1 vs File2")
)
print(g)
的我得到的图是按WORD排序的,而不是频率的降序。再次感谢并期待着答复。
包* forcats *函数在这里很有用。见[这个答案](https://stackoverflow.com/a/41417136/2461552) – aosmith
太棒了。非常感谢@aosmith。 –