2017-08-20 12 views
1

こんにちは私はバープロットの横に作成しようとしていますが、バーが重なっているように見えるのは正しいスペースにありません。バープロットを試みる

この出力する
barplot(counts, 
    main ="2011 vs 2016 Men Volunteering", 
    ylim=c(0,320000), 
    xlab="Age (years)", 
    ylab = "Frequancy", 
    names.arg = c("15-19", "20-24", "25-34", "35-44", "45-54", "55-64", "65-74", "75-84", "84 and over"), 
    col=c("red","green"), 
    beside=TRUE) 

legend("topright", 
     legend = c("2011", "2016"), 
     fill = c("red", "green")) 

:現実には、私はそれが次のようになりたい場合は

を:

「私はNcoI部位= 2を使用して試してみましたが、私はできますそれを動作させるには、どのように実装するのですか?この、

barplot(counts, 
    main ="2011 vs 2016 Men Volunteering", 
    ylim=c(0,320000), 
    xlab="Age (years)", 
    ylab = "Frequancy", 
    names.arg = c("15-19", "20-24", "25-34", "35-44", "45-54", "55-64", "65-74", "75-84", "84 and over"), 
    ncol = 2, 
    col=c("red","green"), 
    beside=TRUE) 

legend("topright", 
     legend = c("2011", "2016"), 
     fill = c("red", "green")) 

またはこのよう

counts <- as.matrix(ELEVENMenVolunteerAge, SIXTEENMenVolunteerAge, ncol = 2) 

ご協力いただきありがとうございます。

+3

SOへようこそ。他の人があなたを助けやすいようにするには、[再現可能な例]を含めることをお勧めします(http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/ 5963610)。 – Jaap

+1

より具体的に言えば、 'dput(counts)'の出力を含めて、あなたの質問を多く改善します。 – Jaap

答えて

0

countsの再現可能なデータがないため、ドッジされたプロットを作成する方法の例はほとんどありません。


ggplot(mtcars, aes(factor(cyl), fill = factor(vs))) + 
    geom_bar(position = "dodge") 

enter image description here

# Grouped Bar Plot 
counts <- table(mtcars$vs, mtcars$gear) 
barplot(counts, col=c("darkblue","red"), 
     legend = rownames(counts), beside=TRUE) 

enter image description here