{"id":2957,"date":"2023-01-17T06:29:55","date_gmt":"2023-01-16T22:29:55","guid":{"rendered":"http:\/\/192.168.1.2\/?p=2957"},"modified":"2023-01-17T06:29:55","modified_gmt":"2023-01-16T22:29:55","slug":"r-ggplot2%e7%ae%80%e5%8d%95%e6%9d%a1%e5%9b%be%e7%bb%98%e5%88%b6","status":"publish","type":"post","link":"http:\/\/g1n29wqq.ipyingshe.net:5347\/?p=2957","title":{"rendered":"R ggplot2\u7b80\u5355\u6761\u56fe\u7ed8\u5236"},"content":{"rendered":"\n<p>In the following graph, we\u2019ll 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<\/p>\n\n\n\n<p>\u5728\u4e0b\u56fe\u4e2d\uff0c\u6211\u4eec\u5c06\u7ed8\u52361970\u5e74\u5728\u7f8e\u56fd\u7684\u5927\u533a\u3002\u5185\u7f6eR\u6570\u636e\u96c6state.x77\u6309\u5dde\u5217\u51fa\u4e86\u6587\u76f2\u7387\uff0c\u6570\u636e\u96c6state.region\u5177\u6709\u6bcf\u4e2a\u5dde\u7684\u533a\u57df\u540d\u79f0\u3002\u8fd9\u4e2a\u4e0b\u9762\u7684\u5217\u8868\u63d0\u4f9b\u4e86\u521b\u5efa\u56fe\u5f62\u6240\u9700\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>```<span style=\"background-color: initial; font-family: inherit; font-size: inherit; color: initial;\">{r}<\/span><code>states &lt;-data.frame(state.region,state.x77)\nlibrary(dplyr)\nlibrary(ggplot2)\nplotdata &lt;-states %>%\n  group_by(state.region) %>%\n  summarize(mean=mean(Illiteracy))   #Illiteracy\u6587\u76f2\nplotdata\nggplot(plotdata, aes(x=reorder(state.region, mean), y=mean)) + \n geom_bar(stat=\"identity\") + \n labs(x=\"Region\", \n y=\"\", \n title = \"Mean Illiteracy Rate\")<\/code>```\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>In the following graph, we\u2019ll plot the m <span class=\"readmore\"><a href=\"http:\/\/g1n29wqq.ipyingshe.net:5347\/?p=2957\">Continue Reading<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-2957","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2957","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2957"}],"version-history":[{"count":1,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2957\/revisions"}],"predecessor-version":[{"id":2958,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=\/wp\/v2\/posts\/2957\/revisions\/2958"}],"wp:attachment":[{"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2957"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2957"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/g1n29wqq.ipyingshe.net:5347\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2957"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}