翻转水平条形图()(基数 R)中条形图(y 轴)的顺序
Flip the order of the bars (y axis) in a horizontal barplot() (base R)
我一直在寻找我可能遇到的基本问题的解决方案,但一直没有找到!
我正在处理以下数据 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"
)))
我正在处理此数据的水平堆叠条形图,但我希望反转条形的顺序(例如,will 可以是最顶层的条形,然后是向量的每个元素,直到“总计” ,最底部的栏)。出于某种原因, 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))
使用 order 和 col 的想法相同:
barplot(uk_twit_dm_semantic[,order(ncol(uk_twit_dm_semantic):1)],col=c("red","blue"), border="white", horiz=TRUE,legend=rownames(uk_twit_dm_semantic))
我一直在寻找我可能遇到的基本问题的解决方案,但一直没有找到!
我正在处理以下数据 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"
)))
我正在处理此数据的水平堆叠条形图,但我希望反转条形的顺序(例如,will 可以是最顶层的条形,然后是向量的每个元素,直到“总计” ,最底部的栏)。出于某种原因, 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))
使用 order 和 col 的想法相同:
barplot(uk_twit_dm_semantic[,order(ncol(uk_twit_dm_semantic):1)],col=c("red","blue"), border="white", horiz=TRUE,legend=rownames(uk_twit_dm_semantic))