[英]How to sort x-axis names by sorting y-axis in R without ggplot2?
说这是我的数据:
Alpha Number
a 5
b 2
c 7
d 1
e 9
f 3
g 4
barplot(sort(Number,decreasing = TRUE))
当我像预期的那样使用axis(1,at = c$b, labels = c$b)
添加x轴值时,它只是按字母顺序显示,如表中所示。 相反,我需要的是根据y轴中的排序值添加x轴,而无需使用ggplot2。
我也尝试过barplot(Number[order(Number,decreasing = TRUE),]
但是没有用。
由于“字母”列不是数字,因此“ Number~Alpha
”无效。
谢谢。
此处无需使用axis
,您可以在barplot
函数中指定标签:
barplot(sort(d$Number,decreasing = TRUE),names.arg=d$Alpha[order(d$Number,decreasing=T)])
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.