{"id":486,"date":"2023-07-29T17:59:32","date_gmt":"2023-07-29T17:59:32","guid":{"rendered":"https:\/\/statorials.org\/de\/alterspyramide-in-r\/"},"modified":"2023-07-29T17:59:32","modified_gmt":"2023-07-29T17:59:32","slug":"alterspyramide-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/de\/alterspyramide-in-r\/","title":{"rendered":"So erstellen sie eine bev\u00f6lkerungspyramide in r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Eine <strong>Bev\u00f6lkerungspyramide<\/strong> ist ein Diagramm, das die Alters- und Geschlechtsverteilung einer bestimmten Bev\u00f6lkerung zeigt. Dies ist ein n\u00fctzliches Diagramm, um die Zusammensetzung einer Bev\u00f6lkerung sowie den aktuellen Bev\u00f6lkerungswachstumstrend leicht zu verstehen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Wenn eine Bev\u00f6lkerungspyramide eine rechteckige Form hat, bedeutet dies, dass die Bev\u00f6lkerung langsamer w\u00e4chst; \u00c4ltere Generationen werden durch etwa gleich gro\u00dfe neue Generationen ersetzt.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Wenn eine Bev\u00f6lkerungspyramide die Form einer Pyramide hat, bedeutet dies, dass eine Bev\u00f6lkerung schneller w\u00e4chst; \u00c4ltere Generationen bringen neue, gr\u00f6\u00dfere Generationen hervor.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In der Grafik wird auf der linken und rechten Seite das Geschlecht, auf der Y-Achse das Alter und auf der X-Achse der Prozentsatz bzw. die Bev\u00f6lkerungszahl angezeigt.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In diesem Tutorial wird erkl\u00e4rt, wie man in R eine Bev\u00f6lkerungspyramide erstellt.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Erstellen Sie eine Bev\u00f6lkerungspyramide in R<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Angenommen, wir haben den folgenden Datensatz, der die prozentuale Zusammensetzung einer Bev\u00f6lkerung basierend auf Alter (0 bis 100 Jahre) und Geschlecht (M = \u201eM\u00e4nnlich\u201c, F = \u201eWeiblich\u201c) zeigt:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#make this example reproducible<\/span>\nset.seed(1)\n\n<span style=\"color: #008080;\">#create data frame\n<\/span>data &lt;- data.frame(age = rep(1:100, 2), gender = rep(c(\"M\", \"F\"), each = 100))\n\n<span style=\"color: #008080;\">#add variable population\n<\/span>data$population &lt;- 1\/sqrt(data$age) * runif(200, 10000, 15000)\n\n<span style=\"color: #008080;\">#convert population variable to percentage\n<\/span>data$population &lt;- data$population \/ sum(data$population) * 100\n\n<span style=\"color: #008080;\">#view first six rows of dataset\n<\/span>head(data)\n\n# age gender population\n#1 1M 2.424362\n#2 2M 1.794957\n#3 3M 1.589594\n#4 4M 1.556063\n#5 5M 1.053662\n#6 6M 1.266231\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Mit der <strong>ggplot2-<\/strong> Bibliothek k\u00f6nnen wir eine grundlegende Bev\u00f6lkerungspyramide f\u00fcr diesen Datensatz erstellen:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#load <em>ggplot2\n<\/em><\/span>library(ggplot2)\n\n<span style=\"color: #008080;\">#create population pyramid<\/span>\nggplot(data, aes(x = age, fill = gender,\n                 y = ifelse(test = gender == \"M\",\n                            yes = -population, no = population))) + \n  geom_bar(stat = \"identity\") +\n  scale_y_continuous(labels = abs, limits = max(data$population) * c(-1,1)) +\n  coordinate_flip()<\/strong><\/pre>\n<h3> <strong>Titel und Tags hinzuf\u00fcgen<\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Mithilfe des <strong>labs()-<\/strong> Arguments k\u00f6nnen wir der Bev\u00f6lkerungspyramide sowohl Titel als auch Achsenbeschriftungen hinzuf\u00fcgen:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data, aes(x = age, fill = gender,\n                 y = ifelse(test = gender == \"M\",\n                            yes = -population, no = population))) + \n  geom_bar(stat = \"identity\") +\n  scale_y_continuous(labels = abs, limits = max(data$population) * c(-1,1)) <span style=\"color: #800080;\">+\n  labs(title = \"Population Pyramid\", x = \"Age\", y = \"Percent of population\")<\/span> +\n  coordinate_flip()<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Farben \u00e4ndern<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Mit dem Argument <strong>\u201escale_color_manual()\u201c<\/strong> k\u00f6nnen wir die beiden Farben \u00e4ndern, die zur Darstellung der Geschlechter verwendet werden:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data, aes(x = age, fill = gender,\n                 y = ifelse(test = gender == \"M\",\n                            yes = -population, no = population))) + \n  geom_bar(stat = \"identity\") +\n  scale_y_continuous(labels = abs, limits = max(data$population) * c(-1,1)) +\n  labs(title = \"Population Pyramid\", x = \"Age\", y = \"Percent of population\") <span style=\"color: #800080;\">+\n  scale_color_manual(values = c(\"pink\", \"steelblue\"),<\/span>\n<span style=\"color: #800080;\">aesthetics = c(\"color\", \"fill\"))<\/span> +\n  coordinate_flip()<\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Mehrere Alterspyramiden<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Mit dem Argument <strong>facet_wrap()<\/strong> ist es auch m\u00f6glich, mehrere Bev\u00f6lkerungspyramiden zusammen darzustellen. Angenommen, wir haben Bev\u00f6lkerungsdaten f\u00fcr die L\u00e4nder <em>A, B<\/em> und <em>C.<\/em> Der folgende Code veranschaulicht, wie eine Bev\u00f6lkerungspyramide f\u00fcr jedes Land erstellt wird:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#make this example reproducible<\/span>\nset.seed(1)\n\n<span style=\"color: #008080;\">#create data frame\n<\/span>data_multiple &lt;- data.frame(age = rep(1:100, 6),\n                   gender = rep(c(\"M\", \"F\"), each = 300),\n                   country = rep(c(\"A\", \"B\", \"C\"), each = 100, times = 2))\n\n<span style=\"color: #008080;\">#add variable population\n<\/span>data_multiple$population &lt;- round(1\/sqrt(data_multiple$age)*runif(200, 10000, 15000), 0)\n\n<span style=\"color: #008080;\">#view first six rows of dataset\n<\/span>head(data_multiple)\n\n# age gender country population\n#1 1 MA 11328\n#2 2 MA 8387\n#3 3 MA 7427\n#4 4 MA 7271\n#5 5 MA 4923\n#6 6 MA 5916\n\n<span style=\"color: #008080;\">#create one population pyramid per country\n<\/span>ggplot(data_multiple, aes(x = age, fill = gender,\n                          y = ifelse(test = gender == \"M\",\n                                     yes = -population, no = population))) + \n  geom_bar(stat = \"identity\") +\n  scale_y_continuous(labels = abs, limits = max(data_multiple$population) * c(-1,1)) +\n  labs(y = \"Population Amount\") + \n  coordinate_flip() <span style=\"color: #800080;\">+\n  facet_wrap(~country) <span style=\"color: #000000;\">+<\/span>\n<span style=\"color: #000000;\">theme(axis.text.x = element_text(angle = 90, hjust = 1))<\/span> <span style=\"color: #008080;\">#rotate x-axis labels<\/span><\/span><\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Thema \u00e4ndern<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Schlie\u00dflich k\u00f6nnen wir das Thema der Grafiken \u00e4ndern. Der folgende Code verwendet beispielsweise <strong>theme_classic()<\/strong> , um Grafiken minimalistischer aussehen zu lassen:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data_multiple, aes(x = age, fill = gender,\n                          y = ifelse(test = gender == \"M\",\n                                     yes = -population, no = population))) + \n  geom_bar(stat = \"identity\") +\n  scale_y_continuous(labels = abs, limits = max(data_multiple$population) * c(-1,1)) +\n  labs(y = \"Population Amount\") + \n  coordinate_flip() +\n  facet_wrap(~country) <span style=\"color: #800080;\">+<\/span>\n<span style=\"color: #800080;\">theme_classic()<\/span> + \n  theme(axis.text.x = element_text(angle = 90, hjust = 1))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Oder Sie k\u00f6nnen benutzerdefinierte ggthemes verwenden. Eine vollst\u00e4ndige Liste der ggthemes finden Sie auf<\/span> <a href=\"https:\/\/yutannihilation.github.io\/allYourFigureAreBelongToUs\/ggthemes\/\" target=\"_blank\" rel=\"noopener\">der Dokumentationsseite<\/a> <span style=\"color: #000000;\">.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Eine Bev\u00f6lkerungspyramide ist ein Diagramm, das die Alters- und Geschlechtsverteilung einer bestimmten Bev\u00f6lkerung zeigt. Dies ist ein n\u00fctzliches Diagramm, um die Zusammensetzung einer Bev\u00f6lkerung sowie den aktuellen Bev\u00f6lkerungswachstumstrend leicht zu verstehen. Wenn eine Bev\u00f6lkerungspyramide eine rechteckige Form hat, bedeutet dies, dass die Bev\u00f6lkerung langsamer w\u00e4chst; \u00c4ltere Generationen werden durch etwa gleich gro\u00dfe neue Generationen ersetzt. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>So erstellen Sie eine Bev\u00f6lkerungspyramide in R - Statorials<\/title>\n<meta name=\"description\" content=\"In diesem Tutorial wird erkl\u00e4rt, wie Sie ganz einfach eine Bev\u00f6lkerungspyramide in R erstellen.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/statorials.org\/de\/alterspyramide-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"So erstellen Sie eine Bev\u00f6lkerungspyramide in R - Statorials\" \/>\n<meta property=\"og:description\" content=\"In diesem Tutorial wird erkl\u00e4rt, wie Sie ganz einfach eine Bev\u00f6lkerungspyramide in R erstellen.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/de\/alterspyramide-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-29T17:59:32+00:00\" \/>\n<meta name=\"author\" content=\"Dr. Benjamin Anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Verfasst von\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. Benjamin Anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Gesch\u00e4tzte Lesezeit\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/de\/alterspyramide-in-r\/\",\"url\":\"https:\/\/statorials.org\/de\/alterspyramide-in-r\/\",\"name\":\"So erstellen Sie eine Bev\u00f6lkerungspyramide in R - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/de\/#website\"},\"datePublished\":\"2023-07-29T17:59:32+00:00\",\"dateModified\":\"2023-07-29T17:59:32+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\"},\"description\":\"In diesem Tutorial wird erkl\u00e4rt, wie Sie ganz einfach eine Bev\u00f6lkerungspyramide in R erstellen.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/de\/alterspyramide-in-r\/#breadcrumb\"},\"inLanguage\":\"de-DE\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/de\/alterspyramide-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/de\/alterspyramide-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Heim\",\"item\":\"https:\/\/statorials.org\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"So erstellen sie eine bev\u00f6lkerungspyramide in r\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/de\/#website\",\"url\":\"https:\/\/statorials.org\/de\/\",\"name\":\"Statorials\",\"description\":\"Ihr Leitfaden f\u00fcr statistische Kompetenz !\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/de\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de-DE\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\",\"name\":\"Dr. Benjamin Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de-DE\",\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. Benjamin Anderson\"},\"description\":\"Hallo, ich bin Benjamin, ein pensionierter Statistikprofessor, der sich zum engagierten Statorials-Lehrer entwickelt hat. Mit umfassender Erfahrung und Fachwissen auf dem Gebiet der Statistik bin ich bestrebt, mein Wissen zu teilen, um Studenten durch Statorials zu bef\u00e4higen. Mehr wissen\",\"sameAs\":[\"https:\/\/statorials.org\/de\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"So erstellen Sie eine Bev\u00f6lkerungspyramide in R - Statorials","description":"In diesem Tutorial wird erkl\u00e4rt, wie Sie ganz einfach eine Bev\u00f6lkerungspyramide in R erstellen.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/statorials.org\/de\/alterspyramide-in-r\/","og_locale":"de_DE","og_type":"article","og_title":"So erstellen Sie eine Bev\u00f6lkerungspyramide in R - Statorials","og_description":"In diesem Tutorial wird erkl\u00e4rt, wie Sie ganz einfach eine Bev\u00f6lkerungspyramide in R erstellen.","og_url":"https:\/\/statorials.org\/de\/alterspyramide-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-29T17:59:32+00:00","author":"Dr. Benjamin Anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr. Benjamin Anderson","Gesch\u00e4tzte Lesezeit":"3 Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/de\/alterspyramide-in-r\/","url":"https:\/\/statorials.org\/de\/alterspyramide-in-r\/","name":"So erstellen Sie eine Bev\u00f6lkerungspyramide in R - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/de\/#website"},"datePublished":"2023-07-29T17:59:32+00:00","dateModified":"2023-07-29T17:59:32+00:00","author":{"@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0"},"description":"In diesem Tutorial wird erkl\u00e4rt, wie Sie ganz einfach eine Bev\u00f6lkerungspyramide in R erstellen.","breadcrumb":{"@id":"https:\/\/statorials.org\/de\/alterspyramide-in-r\/#breadcrumb"},"inLanguage":"de-DE","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/de\/alterspyramide-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/de\/alterspyramide-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Heim","item":"https:\/\/statorials.org\/de\/"},{"@type":"ListItem","position":2,"name":"So erstellen sie eine bev\u00f6lkerungspyramide in r"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/de\/#website","url":"https:\/\/statorials.org\/de\/","name":"Statorials","description":"Ihr Leitfaden f\u00fcr statistische Kompetenz !","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/de\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de-DE"},{"@type":"Person","@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0","name":"Dr. Benjamin Anderson","image":{"@type":"ImageObject","inLanguage":"de-DE","@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/de\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","caption":"Dr. Benjamin Anderson"},"description":"Hallo, ich bin Benjamin, ein pensionierter Statistikprofessor, der sich zum engagierten Statorials-Lehrer entwickelt hat. Mit umfassender Erfahrung und Fachwissen auf dem Gebiet der Statistik bin ich bestrebt, mein Wissen zu teilen, um Studenten durch Statorials zu bef\u00e4higen. Mehr wissen","sameAs":["https:\/\/statorials.org\/de"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/486"}],"collection":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/comments?post=486"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/486\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/media?parent=486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/categories?post=486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/tags?post=486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}