r - 翻转水平 barplot() 中条形的顺序(y 轴)(基础 R)

标签 r plot graph bar-chart

我一直在寻找解决我的基本问题的方法,但还没有找到!

我正在处理以下数据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))

enter image description here

祝一切顺利

卡梅伦

最佳答案

一个想法可能是在启动绘图代码行之前反转数据框的列顺序

# 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/

相关文章:

java - 如何为域轴和范围轴设置相同的比例 JFreeChart

android - android中的Achart引擎自定义点样式

algorithm - 从一个源出发经过 N 条边的最短路径

r - 如何在没有天数的情况下以 Y-m 格式转换日期

r - ggplot2 增加图例项之间的差距

javascript - 如何在 chart.js 中使用 json 数据

plot - 如何在 Google Colaboratory 中删除绘图背景和网格

algorithm - Dijkstra 的终止条件

R dplyr - 在所有列中都不同

r - 按升序/降序快速对 data.table 进行排序