[英]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.