Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/65.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 条形图中的排序条_R - Fatal编程技术网

R 条形图中的排序条

R 条形图中的排序条,r,R,因此,我对条形图中的条形图顺序存在问题,我希望所有功能组(fu5)彼此对齐,我已经研究了级别和所有其他形式,但我确实不明白它们为什么不与这些组对齐 以下是我到目前为止使用的代码(我使用的是RStudio,并上传了一个csv文件): 任何帮助都会很好 只要fu5是一个因子,重新排序函数就可以做到这一点。但请注意as.integer以检索因子的数字顺序 library(ggplot2) df = read.csv(text=" sp5,fu5,o5 spa,c,1 spd,c,2 spb,a,3

因此,我对条形图中的条形图顺序存在问题,我希望所有功能组(
fu5
)彼此对齐,我已经研究了级别和所有其他形式,但我确实不明白它们为什么不与这些组对齐

以下是我到目前为止使用的代码(我使用的是RStudio,并上传了一个csv文件):


任何帮助都会很好

只要fu5是一个因子,重新排序函数就可以做到这一点。但请注意as.integer以检索因子的数字顺序

library(ggplot2)
df = read.csv(text="
sp5,fu5,o5
spa,c,1
spd,c,2
spb,a,3
spc,b,4
", stringsAsFactors = TRUE)

ggplot(df, aes(x = reorder(sp5, as.integer(fu5)), y = o5, fill = fu5)) + 
  geom_col() + 
  theme(axis.text.x = element_text(angle = 60, hjust = 1))

欢迎@Elanor。提供样本数据总是好的。请查看发布的好问题
library(ggplot2)
df = read.csv(text="
sp5,fu5,o5
spa,c,1
spd,c,2
spb,a,3
spc,b,4
", stringsAsFactors = TRUE)

ggplot(df, aes(x = reorder(sp5, as.integer(fu5)), y = o5, fill = fu5)) + 
  geom_col() + 
  theme(axis.text.x = element_text(angle = 60, hjust = 1))