-1

ggplot2 グラフの x ファセットと y ファセットの両方を再ラベル付けしようとしています。

1 つのファセットを再ラベル付けする関数を作成する複数の方法を見つけましたが、両方ではありません。

head(nh2)  
        RatioIncomePoverty Ethnicity Education mean.bmi  
1                  0         1         1       26.18333  
2                  0         1         1       30.88000  
3                  0         1         2       32.03000  
4                  0         1         4       34.45000  
5                  0         2         1       26.33000  
6                  0         2         2       23.44000  

b2 <- qplot(RatioIncomePoverty, mean.bmi, data=nh2, facets=Education~Ethnicity)
b2 = b2 + labs(list(title="Average BMI and Ratio of Family Income to Poverty Threshold     among US Ethnic groups", x = "Ratio of Family Income to Poverty Threshold", y = "Average BMI"))
b2 

現在、教育と民族の両方にそれぞれ 1 ~ 5 の値があり、調査で対応したものに名前を変更したいと思います。

Education:    
1 = "<9th"  
2 = "9th-11th"  
3 = "GED"  
4 = "Some/AA"  
5 = "Grad"  

Ethnicity:  
1 = "Mex/Amer"  
2 = "OtherHisp"  
3 = "White"  
4 = "Black"  
5 = "Other/Multi"  
4

1 に答える 1

1

それらをレベルとして単純に要因を作成してみませんか?

eth <- c('Mex/Amer', 'OtherHisp', 'White', 'Black', 'Other/Multi')
edu <- c('<9th', '9th-11th', 'GED', 'Some/AA', 'Grad')

nh2 <- within(nh2, {ethFac <- factor(Ethnicity, labels = eth)
                    eduFac <- factor(Education, labels = edu)})

 b2 <- qplot(RatioIncomePoverty, mean.bmi, data=nh2, facets=eduFac~ethFac)                       
于 2013-04-24T01:32:31.713 に答える