第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在一個圖中繪制多個箱圖

在一個圖中繪制多個箱圖

守著星空守著你 2019-08-26 14:55:23
在一個圖中繪制多個箱圖我將數(shù)據(jù)保存為.csv12列的文件。第2至11列(標記為F1, F2, ..., F11)features。Column one包含或label這些功能。goodbad我想繪制boxplot的所有這些功能11對label,而是通過單獨good或bad。到目前為止我的代碼是:qplot(Label, F1, data=testData, geom = "boxplot", fill=Label,            binwidth=0.5, main="Test") + xlab("Label") + ylab("Features")然而,這只能說明F1反對label。我的問題是:如何顯示F2, F3, ..., F11對label在一個圖表一些dodge position?我已將這些特征標準化,因此它們在[0 1]范圍內(nèi)具有相同的比例。測試數(shù)據(jù)可以在這里找到。我手工繪制了一些東西來解釋這個問題(見下文)。
查看完整描述

3 回答

?
jeck貓

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

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


查看完整回答
反對 回復 2019-08-26
?
回首憶惘然

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


查看完整回答
反對 回復 2019-08-26
  • 3 回答
  • 0 關(guān)注
  • 901 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號