In the following graph, we’ll plot the mean illiteracy rate forregions of the United States in 1970. The built-in R dataset state.x77 has the illiteracy rates by state, and the datasetstate.region has the region names for each state. The following listing provides the code needed to create the graph
在下图中,我们将绘制1970年在美国的大区。内置R数据集state.x77按州列出了文盲率,数据集state.region具有每个州的区域名称。这个下面的列表提供了创建图形所需的代码:
```{r}states <-data.frame(state.region,state.x77)
library(dplyr)
library(ggplot2)
plotdata <-states %>%
group_by(state.region) %>%
summarize(mean=mean(Illiteracy)) #Illiteracy文盲
plotdata
ggplot(plotdata, aes(x=reorder(state.region, mean), y=mean)) +
geom_bar(stat="identity") +
labs(x="Region",
y="",
title = "Mean Illiteracy Rate")
```