R 重命名ggplot2的机器人x和y面

R 重命名ggplot2的机器人x和y面,r,ggplot2,R,Ggplot2,我正在尝试重新标记ggplot2图形的x和y面 我发现了多种编写函数的方法来重新标记一个方面,但不是两个方面都可以 head(nh2) RatioIncomePoverty Ethnicity Education mean.bmi 1 0 1 1 26.18333 2 0 1 1 30.88000 3

我正在尝试重新标记ggplot2图形的x和y面

我发现了多种编写函数的方法来重新标记一个方面,但不是两个方面都可以

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 
head(nh2)
贫困率种族教育平均值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为什么不简单地以这些为水平创建因子

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)                       

eth-Hmm-这创造了因素,但我仍然得到“布局中的错误(数据,行,drop=drop):至少一个层必须包含用于刻面的所有变量”我将标记它回答,我在刻面中使用的变量中有一个大写错误。谢谢
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)