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))