Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/wcf/4.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,我需要更改条形图中条形图的顺序。默认值为字母顺序,我不需要。我需要的顺序是“小学”,“中学”,“高中” 在表步骤之前,如果我们将“类型”列更改为因子,并将级别指定为“M”中的值,则颜色 century$type <- factor(century$type, levels = M) 绘制条形图 par(mar=c(5.5, 8.5, 5.1, 2.1)) barplot(mytable2, col=colors, border = NA, ylim = range(0,3),

我需要更改条形图中条形图的顺序。默认值为字母顺序,我不需要。我需要的顺序是“小学”,“中学”,“高中”


步骤之前,如果我们将“类型”列更改为
因子
,并将
级别
指定为“M”中的值,则
颜色

century$type <- factor(century$type, levels = M)
绘制条形图

par(mar=c(5.5, 8.5, 5.1, 2.1))
barplot(mytable2, 
 col=colors, 
 border = NA, 
 ylim = range(0,3),
 xlim = range(0,1), 
 
     
     family="Arial", 
     horiz = TRUE, names.arg= M,
     las=1)

数据
century在
步骤之前,如果我们将“类型”列更改为
因子
,并将
级别
指定为“M”中的值

century$type <- factor(century$type, levels = M)
绘制条形图

par(mar=c(5.5, 8.5, 5.1, 2.1))
barplot(mytable2, 
 col=colors, 
 border = NA, 
 ylim = range(0,3),
 xlim = range(0,1), 
 
     
     family="Arial", 
     horiz = TRUE, names.arg= M,
     las=1)

数据
century我认为您需要将
century$type
更改为
century$type您尝试过fct_reorder()吗?我想您需要将
century$type
更改为
century$type您是否尝试过fct_reorder()?可能重复的
par(mar=c(5.5, 8.5, 5.1, 2.1))
barplot(mytable2, 
 col=colors, 
 border = NA, 
 ylim = range(0,3),
 xlim = range(0,1), 
 
     
     family="Arial", 
     horiz = TRUE, names.arg= M,
     las=1)
century <- structure(list(race = structure(c(2L, 2L, 2L, 2L, 2L, 1L, 1L, 
 1L, 1L, 1L), .Label = c("F", "M"), class = "factor"), type = structure(c(3L, 
 2L, 3L, 3L, 3L, 1L, 2L, 3L, 1L, 2L), .Label = c("Elementary School", 
 "High School", "Middle School"), class = "factor")),
  class = "data.frame", row.names = c(NA, -10L))