我正在尝试改变这个盒子图中x轴的顺序。
现在的顺序是放大镜,显微镜和视频,我想把它改为显微镜,放大镜,然后视频
数据帧示例如下所示
Label Mental Physical Temporal Performance Effort Frustration sum
Microscope 10 10 10 10 10 10 60
Microscope 10 10 10 10 10 10 60
Loupe 20 20 20 20 20 20 120
Loupe 20 20 20 20 20 20 120
Video 15 15 15 20 20 20 105
Video 15 15 15 20 20 20 105 这是我现在的boxplot,boxplot1
这是我的ggplot代码
mydata <- read.csv("boxplotyiyu2.csv",header=TRUE)
dfm <- melt(mydata, id.var = "Label")
ggplot(data = dfm, aes(x=variable, y=value)) + geom_boxplot(aes(fill=Label),width=0.5)+ xlab("Demand") + ylab("NASA-TLX Scores")我试过了,但结果不正确。
dfm$variable <- factor(dfm$variable,levels = c("Microscope","Loupe","Video"))另一个问题是如何修改多个箱线图的y轴。我有这七个箱形图,但我想更改每个小图的y轴。boxplot2
(数据框与上面类似,只需替换mental,physical...with角度数据)
我拥有的代码是
df.m <- melt(mydata, id.var = "Label")
p <- ggplot(data = df.m, aes(x=variable, y=value))
p <- p + geom_boxplot(aes(fill=Label))
p <- p + facet_wrap( ~ variable, scales="free")
p <- p + xlab("Angle") + ylab("Degree")请帮我个忙!真的很感谢!
发布于 2017-02-14 11:06:08
您将需要使用factor函数重新定义因子的顺序。
#Sample data
Label<-c("Microscope", "Microscope", "Loupe", "Loupe", "Video", "Video")
mydata<-data.frame(Label)
#print out
levels(mydata$Label)
mydata$Label<-factor(mydata$Label, levels=c("Microscope", "Loupe", "Video"))
#print out
levels(mydata$Label)有关更多信息,请参阅cookbook-r.com:http://www.cookbook-r.com/Manipulating_data/Changing_the_order_of_levels_of_a_factor/
https://stackoverflow.com/questions/42216352
复制相似问题