3 回答

TA貢獻1909條經(jīng)驗 獲得超7個贊
在繪制之前,您應該通過熔化數(shù)據(jù)(參見下面的熔化數(shù)據(jù)的樣子)來獲取特定格式的數(shù)據(jù)。否則,你所做的似乎沒問題。
require(reshape2)
df <- read.csv("TestData.csv", header=T)
# melting by "Label". `melt is from the reshape2 package.
# do ?melt to see what other things it can do (you will surely need it)
df.m <- melt(df, id.var = "Label")
> df.m # pasting some rows of the melted data.frame
# Label variable value
# 1 Good F1 0.64778924
# 2 Good F1 0.54608791
# 3 Good F1 0.46134200
# 4 Good F1 0.79421221
# 5 Good F1 0.56919951
# 6 Good F1 0.73568570
# 7 Good F1 0.65094207
# 8 Good F1 0.45749702
# 9 Good F1 0.80861929
# 10 Good F1 0.67310067
# 11 Good F1 0.68781739
# 12 Good F1 0.47009455
# 13 Good F1 0.95859182
# 14 Good F1 1.00000000
# 15 Good F1 0.46908343
# 16 Bad F1 0.57875528
# 17 Bad F1 0.28938046
# 18 Bad F1 0.68511766
require(ggplot2)
ggplot(data = df.m, aes(x=variable, y=value)) + geom_boxplot(aes(fill=Label))
boxplot_ggplot2
編輯:我意識到你可能需要分面。這也是一個實現(xiàn):
p <- ggplot(data = df.m, aes(x=variable, y=value)) +
geom_boxplot(aes(fill=Label))
p + facet_wrap( ~ variable, scales="free")
ggplot2_faceted
編輯2:如何添加x-labels,y-labels,title,改變legend heading,添加jitter?
p <- ggplot(data = df.m, aes(x=variable, y=value))
p <- p + geom_boxplot(aes(fill=Label))
p <- p + geom_jitter()
p <- p + facet_wrap( ~ variable, scales="free")
p <- p + xlab("x-axis") + ylab("y-axis") + ggtitle("Title")
p <- p + guides(fill=guide_legend(title="Legend_Title"))
p
ggplot2_geom_plot
編輯3:如何將geom_point()點對齊到箱形圖的中心?它可以使用position_dodge。這應該工作。
require(ggplot2)
p <- ggplot(data = df.m, aes(x=variable, y=value))
p <- p + geom_boxplot(aes(fill = Label))
# if you want color for points replace group with colour=Label
p <- p + geom_point(aes(y=value, group=Label), position = position_dodge(width=0.75))
p <- p + facet_wrap( ~ variable, scales="free")
p <- p + xlab("x-axis") + ylab("y-axis") + ggtitle("Title")
p <- p + guides(fill=guide_legend(title="Legend_Title"))
p

TA貢獻1847條經(jīng)驗 獲得超11個贊
既然你沒有提到一個情節(jié)包,我在這里建議使用Lattice
版本(我認為ggplot2答案比格子更多,至少因為我在這里)。
## reshaping the data( similar to the other answer) library(reshape2) dat.m <- melt(TestData,id.vars='Label') library(lattice) bwplot(value~Label |variable, ## see the powerful conditional formula data=dat.m, between=list(y=1), main="Bad or Good")
- 3 回答
- 0 關(guān)注
- 901 瀏覽
添加回答
舉報