2017-07-13 3 views
0

ggplotを使用してデータをグループ化した棒グラフを作成する最良の方法は何ですか?ggplotに3つ以上のパラメータを含める

すべてのパラメータをggplotに取得するのが難しいことがわかりました。私は "bathng"とP_Hygnをx軸に、EnteredARCはfill.y軸を比例値にしたいと思います。入浴とP_hygnの値は0〜5であり、0 =独立、1 =監督、2 =中程度、3 =極小、4は重度、5は昏睡である。

 gender EnteredARC Ethnicity Bathng P_Hygn 
1:  M Entry_RC European  4  2 
2:  F NoEntry_RC European  3  0 
3:  F NoEntry_RC European  0  0 
4:  M Entry_RC European  3  4 
5:  F Entry_RC European  5  2 
6:  F NoEntry_RC European  2  0 
7:  F Entry_RC European  3  1 
8:  M Entry_RC European  4  2 
9:  M Entry_RC European  8  2 



gender EnteredARC Ethnicity Bathng P_Hygn 
1:  M Entry_RC European  4  2 
2:  F NoEntry_RC European  3  0 
3:  F NoEntry_RC European  0  0 
4:  M Entry_RC European  3  4 
5:  F Entry_RC European  5  2 
6:  F NoEntry_RC European  2  0 
7:  F Entry_RC European  3  1 
8:  M Entry_RC European  4  2 
9:  M Entry_RC European  8  2 

答えて

0

これは何か?

library(ggplot2) 
library(plotly) 

df <- data.frame(gender=c('M','F','F','M','F','F','F','M','M'), 
       EnteredARC=c('Entry_RC','NoEntry_RC','NoEntry_RC','Entry_RC','Entry_RC','NoEntry_RC','Entry_RC','Entry_RC','Entry_RC'), 
       Ethnicity=c('European','European','European','European','European','European','European','European','European'), 
       Bathng=c(4,3,0,3,5,2,3,4,8), 
       P_Hygn=c(2,0,0,4,2,0,1,2,2)) 
g <- ggplot(df,aes(factor(Bathng),color=gender,size=P_Hygn)) + 
    geom_bar(aes(fill=EnteredARC)) + 
    scale_fill_manual(values=c("dark grey", "light grey")) 
ggplotly(g) 
+0

似たような問題に直面した場合に他の人にも役立つだろうと期待している解決策であるかどうかお知らせください。 – Prem

関連する問題