Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.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_Bar Chart - Fatal编程技术网

我能';我不能让R不按字母顺序排列我的装箱数据

我能';我不能让R不按字母顺序排列我的装箱数据,r,bar-chart,R,Bar Chart,我试图制作一个柱状图以供发布,我试图展示我们医院在课程实施前和课程实施后,手术类型的变化,分别是“BR”和“AR”。手术类型有“开放式”、“腹腔镜式”和“机器人式”。我希望条形图上的“BR”值在“AR”值之前,但我似乎不知道如何让R按顺序读取它们(我对R和编码相当陌生:()。我的数据帧名为df) bin type cases_per_month 1 Open BR 18.35 2 Open AR

我试图制作一个柱状图以供发布,我试图展示我们医院在课程实施前和课程实施后,手术类型的变化,分别是“BR”和“AR”。手术类型有“开放式”、“腹腔镜式”和“机器人式”。我希望条形图上的“BR”值在“AR”值之前,但我似乎不知道如何让R按顺序读取它们(我对R和编码相当陌生:()。我的数据帧名为df)

           bin type cases_per_month
1         Open   BR           18.35
2         Open   AR           15.50
3 Laparoscopic   BR            4.25
4 Laparoscopic   AR            1.95
5      Robotic   BR            0.10
6      Robotic   AR            1.15

ggplot(data=df, aes(x=bin, y=cases_per_month)) + geom_bar(stat="identity")

data <- tapply(df$cases_per_month, list(df$type, df$bin), sum)
barplot(data, beside=T, col=c("black", "grey"),
    main="Average Cases per Month,BR and AR: Ventral", 
    xlab="Case Type", ylab="Average Cases per Month")
legend(locator(1), rownames(data), fill=c("black","grey"))
bin类型案例每月
1开放BR 18.35
2开AR 15.50
3.4.25
4.1.95
5.0.10
6机器人AR 1.15
ggplot(数据=df,aes(x=bin,y=cases\u/月))+geom\u条(stat=“identity”)

数据来吧,你只需要这个

data <- data[2:1, ]

这个有点棘手。我的解决方案是:

# Load ggplot
library(ggplot2)

# Create data frame
bin <- c('Open', 'Open', 'Laparoscopic', 'Laparoscopic', 'Robotic', 'Robotic')
type <- c('BR', 'AR', 'BR', 'AR', 'BR', 'AR')
cases.per.month <- c(18.35, 15.5, 4.25, 1.95, .1, 1.15)
df <- data.frame(bin, type, cases.per.month)

# Reorder levels
df$type <- factor(df$type, c('BR', 'AR'))

# Plot BR and AR types side-by-side
ggplot(df, aes(x = bin, y = cases.per.month, fill = type)) + geom_bar(stat = 'identity', position = 'dodge')
#加载ggplot
图书馆(GG2)
#创建数据帧

bin使用一个
因子
并按您想要的顺序设置
级别
我已经尝试了
数据$type变量
数据
不包含
类型
列。所以R这么说。@ehandrenThank您太感谢了,文耀!这真的很有帮助!我知道这对在座的大多数人来说都是儿戏。再次感谢!
# Load ggplot
library(ggplot2)

# Create data frame
bin <- c('Open', 'Open', 'Laparoscopic', 'Laparoscopic', 'Robotic', 'Robotic')
type <- c('BR', 'AR', 'BR', 'AR', 'BR', 'AR')
cases.per.month <- c(18.35, 15.5, 4.25, 1.95, .1, 1.15)
df <- data.frame(bin, type, cases.per.month)

# Reorder levels
df$type <- factor(df$type, c('BR', 'AR'))

# Plot BR and AR types side-by-side
ggplot(df, aes(x = bin, y = cases.per.month, fill = type)) + geom_bar(stat = 'identity', position = 'dodge')