ggplot2 R 中的箱线图
Boxplots in ggplot2 R
我的目标是用 ggplot2
可视化一些数据框。
我有几个 data.frames 看起来像这样
我的目标是像这样的箱线图,只是更好。
我设法使用
获得单个箱线图
plt <- ggplot(data, aes(RF, data$RF)) +
geom_boxplot()
plt
但这不是我想要的。
您显示的箱线图是使用 base-r 图形创建的。单个命令
boxplot(data)
会做的。
如果你想使用 ggplot
,你必须先 melt
数据帧然后绘图。
library(reshape2)
datPlot <- melt(data)
ggplot(datPlot,aes(variable,value)) + geom_boxplot()
library(ggplot2)
library(reshape)
airquality_m = melt(airquality)
ggplot(airquality_m, aes(variable, value )) + geom_boxplot()
我没有美化情节,但我猜你明白了。
我想这就是你想要的:
library(ggplot2)
library(reshape)
myddt_m = melt(mydata)
names(myddt_m)=c("Models","CI")
ggplot(myddt_m, aes(Models, CI,fill=Models )) + geom_boxplot()+guides(fill=FALSE)+labs( x="", y="C-Index")
我的目标是用 ggplot2
可视化一些数据框。
我有几个 data.frames 看起来像这样
我的目标是像这样的箱线图,只是更好。
我设法使用
获得单个箱线图plt <- ggplot(data, aes(RF, data$RF)) +
geom_boxplot()
plt
但这不是我想要的。
您显示的箱线图是使用 base-r 图形创建的。单个命令
boxplot(data)
会做的。
如果你想使用 ggplot
,你必须先 melt
数据帧然后绘图。
library(reshape2)
datPlot <- melt(data)
ggplot(datPlot,aes(variable,value)) + geom_boxplot()
library(ggplot2)
library(reshape)
airquality_m = melt(airquality)
ggplot(airquality_m, aes(variable, value )) + geom_boxplot()
我没有美化情节,但我猜你明白了。
我想这就是你想要的:
library(ggplot2)
library(reshape)
myddt_m = melt(mydata)
names(myddt_m)=c("Models","CI")
ggplot(myddt_m, aes(Models, CI,fill=Models )) + geom_boxplot()+guides(fill=FALSE)+labs( x="", y="C-Index")