我一直在寻找解决我的基本问题的方法,但还没有找到!
我正在处理以下数据uk_twit_dm_semantic
:
structure(c(0.02, 0.98, 0, 1, 0.2, 0.8, 0.82, 0.18, 0.98, 0.02,
0.05, 0.95, 0.41, 0.59, 0.81, 0.19, 0.32, 0.68, 0.9, 0.1, 0.45,
0.55), .Dim = c(2L, 11L), .Dimnames = list(c("EE", "ER"), c("will can",
"will shall", "would could", "would might", "will might", "would should",
"will should", "will would", "will could", "will may", "Total"
)))
我正在研究此数据的水平堆叠条形图,但我希望条形图的顺序颠倒(例如,将可以是最上面的条形图,后跟向量的每个元素,直到“总计”,即最底部的栏)。由于某种原因 horiz=TRUE 给了我相反的顺序。如何翻转订单?
barplot(uk_twit_dm_semantic, col=coul, border="white", horiz=TRUE,legend=rownames(uk_twit_dm_semantic))
祝一切顺利
卡梅伦
最佳答案
一个想法可能是在启动绘图代码行之前反转数据框的列顺序
# 1- Reversing order of columns
uk_twit_dm_semantic_rev <- uk_twit_dm_semantic[, rev(colnames(uk_twit_dm_semantic))]
# 2- Launching the plot with reversed columns
barplot(uk_twit_dm_semantic_rev, col=coul, border="white", horiz=TRUE, legend=rownames(uk_twit_dm_semantic_rev))
关于r - 翻转水平 barplot() 中条形的顺序(y 轴)(基础 R),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70695968/