2014-09-03 19 views
0

我有一個data.frame,我想爲兩個不同的列繪製一個分組的barplot。如何爲兩個不同的列繪製分組的條形圖?

以下是我關心的兩列。

str(credit_arff) 

$ checking_status  : Factor w/ 4 levels "<0",">=200","0<=X<200",..: 
$ class     : Factor w/ 2 levels "bad","good": 

我可以由barplot(mydata$checking_status)繪製barplot爲checking_status(如下所示),但我怎樣可以得出一個barplot,它表示有多少的goodbad對應的值。

理想我想在每個酒吧的不同分至圈,每個代表goodbad

enter image description here

回答

1

有不少方法可以做到這一點。請參閱post

QuickR也是這類事情的一個很好的參考。

爲您的特定情況下,你可以做到這一點使用基本圖形:

credit_arff <- data.frame(
    checking_status = c("<0", "<0", "<0", ">=200", ">=200", "0<=X<200", "0<=X<200", "0<=X<200", "0<=X<200", "no checking", "no checking", "no checking"), 
    class = c("bad", "bad", "good", "bad", "good", "bad", "bad", "good", "bad", "good", "good", "bad") 
) 

df <- table(credit_arff$class, credit_arff$checking_status) 
barplot(df, beside=T, col=c("red", "blue"), legend=rownames(df)) 

your grouped bar chart

相關問題