{"id":472,"date":"2023-07-29T19:13:06","date_gmt":"2023-07-29T19:13:06","guid":{"rendered":"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/"},"modified":"2023-07-29T19:13:06","modified_gmt":"2023-07-29T19:13:06","slug":"bump-plot-in-r-mit-ggplot2","status":"publish","type":"post","link":"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/","title":{"rendered":"So erstellen sie mit ggplot2 ganz einfach ein reliefdiagramm in r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Ein <strong>Bump-Diagramm<\/strong> ist eine Art Diagramm, das die Rangfolge verschiedener Gruppen im Zeitverlauf anstelle absoluter Werte anzeigt, um die Reihenfolge der Gruppen und nicht das Ausma\u00df der \u00c4nderung hervorzuheben.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In diesem Tutorial wird erkl\u00e4rt, wie Sie mit ggplot2 ganz einfach ein Bump-Plot in R erstellen.<\/span><\/p>\n<h2> <strong><span style=\"color: #000000;\">Beispiel: Erstellen einer Reliefgrafik<\/span><\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Um ein Bump-Chart in R zu erstellen, m\u00fcssen wir zun\u00e4chst zwei Pakete laden: <strong>dplyr<\/strong> und <strong>ggplot2<\/strong> :<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>library(ggplot2) <span style=\"color: #008080;\">#for creating bump chart<\/span>\nlibrary(dplyr) <span style=\"color: #008080;\">#for manipulating data<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Als N\u00e4chstes erstellen wir einige Daten, mit denen wir arbeiten k\u00f6nnen:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#set the seed to make this example reproducible<\/span>\nset.seed(10)\n\ndata &lt;- data.frame(team = rep(LETTERS[1:5], each = 10),\n                   random_num = runif(50),\n                   day = rep(1:10, 5))\n\ndata &lt;- data %&gt;%\n  group_by(day) %&gt;%\n  arrange(day, desc(random_num), team) %&gt;% \n  mutate(rank = row_number()) %&gt;%\n  A group()\n\nhead(data)\n\n# team random_num day rank          \n#1 C 0.865 1 1\n#2 B 0.652 1 2\n#3 D 0.536 1 3\n#4 A 0.507 1 4\n#5 E 0.275 1 5\n#6 C 0.615 2 1<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Diese Datenbank zeigt einfach die \u201eRangliste\u201c von f\u00fcnf verschiedenen Teams \u00fcber einen Zeitraum von 10 Tagen.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen ggplot2 verwenden, um ein Fortschrittsdiagramm zu erstellen, um die Platzierung jedes Teams an jedem Tag in diesem Zeitraum zu visualisieren:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data, aes(x = day, y = rank, group = team)) +\n  geom_line(aes(color = team, alpha = 1), size = 2) +\n  geom_point(aes(color = team, alpha = 1), size = 4) +\n  scale_y_reverse(breaks = 1:nrow(data))<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Dieses Bump-Diagramm zeigt die Daten im gew\u00fcnschten Format an, ist aber ziemlich h\u00e4sslich. Mit ein paar \u00e4sthetischen \u00c4nderungen k\u00f6nnen wir dieses Gem\u00e4lde viel besser machen.<\/span><\/p>\n<h2> <strong><span style=\"color: #000000;\">Stilisieren Sie die Bump-Grafik<\/span><\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Um das Erscheinungsbild des Diagramms zu verbessern, k\u00f6nnen wir das folgende von <a href=\"https:\/\/dominikkoch.github.io\/Bump-Chart\/\" target=\"_blank\" rel=\"noopener\">Dominik Koch<\/a> erstellte Theme verwenden:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>my_theme &lt;- function() {\n\n  # Colors\n  color.background = \"white\"\n  color.text = \"#22211d\"\n\n  # Begin construction of chart\n  theme_bw(base_size=15) +\n\n    # Format background colors\n    theme(panel.background = element_rect(fill=color.background,\n                                          color=color.background)) +\n    theme(plot.background = element_rect(fill=color.background,\n                                          color=color.background)) +\n    theme(panel.border = element_rect(color=color.background)) +\n    theme(strip.background = element_rect(fill=color.background,\n                                          color=color.background)) +\n\n    # Format the grid\n    theme(panel.grid.major.y = element_blank()) +\n    theme(panel.grid.minor.y = element_blank()) +\n    theme(axis.ticks = element_blank()) +\n\n    # Format the legend\n    theme(legend.position = \"none\") +\n\n    # Format title and axis labels\n    theme(plot.title = element_text(color=color.text, size=20, face = \"bold\")) +\n    theme(axis.title.x = element_text(size=14, color=\"black\", face = \"bold\")) +\n    theme(axis.title.y = element_text(size=14, color=\"black\", face = \"bold\",\n                                          vjust=1.25)) +\n    theme(axis.text.x = element_text(size=10, vjust=0.5, hjust=0.5,\n                                          color = color.text)) +\n    theme(axis.text.y = element_text(size=10, color = color.text)) +\n    theme(strip.text = element_text(face = \"bold\")) +\n\n    # Plot margins\n    theme(plot.margin = unit(c(0.35, 0.2, 0.3, 0.35), \"cm\"))\n}<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Wir erstellen das Bump-Diagramm erneut, entfernen dieses Mal jedoch die Legende, f\u00fcgen einige Diagrammbeschriftungen hinzu und verwenden das im obigen Code definierte Thema:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data, aes(x = as.factor(day), y = rank, group = team)) +\n  geom_line(aes(color = team, alpha = 1), size = 2) +\n  geom_point(aes(color = team, alpha = 1), size = 4) +\n  geom_point(color = \"#FFFFFF\", size = 1) +\n  scale_y_reverse(breaks = 1:nrow(data)) + \n  scale_x_discrete(breaks = 1:10) +\n  theme(legend.position = 'none') +\n  geom_text(data = data %&gt;% filter(day == \"1\"),\n            aes(label = team, x = 0.5), hjust = .5,\n            fontface = \"bold\", color = \"#888888\", size = 4) +\n  geom_text(data = data %&gt;% filter(day == \"10\"),\n            aes(label = team, x = 10.5), hjust = 0.5,\n            fontface = \"bold\", color = \"#888888\", size = 4) +\n  labs(x = 'Day', y = 'Rank', title = 'Team Ranking by Day') +\n  my_theme()<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnen eine der Zeilen auch einfach hervorheben, indem wir ein <strong>Scale_color_manual()-<\/strong> Argument hinzuf\u00fcgen. Im folgenden Code machen wir beispielsweise die Linie von Team A lila und alle anderen Linien grau:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data, aes(x = as.factor(day), y = rank, group = team)) +\n  geom_line(aes(color = team, alpha = 1), size = 2) +\n  geom_point(aes(color = team, alpha = 1), size = 4) +\n  geom_point(color = \"#FFFFFF\", size = 1) +\n  scale_y_reverse(breaks = 1:nrow(data)) + \n  scale_x_discrete(breaks = 1:10) +\n  theme(legend.position = 'none') +\n  geom_text(data = data %&gt;% filter(day == \"1\"),\n            aes(label = team, x = 0.5), hjust = .5,\n            fontface = \"bold\", color = \"#888888\", size = 4) +\n  geom_text(data = data %&gt;% filter(day == \"10\"),\n            aes(label = team, x = 10.5), hjust = 0.5,\n            fontface = \"bold\", color = \"#888888\", size = 4) +\n  labs(x = 'Day', y = 'Rank', title = 'Team Ranking by Day') +\n  my_theme() <span style=\"color: #800080;\">+\n  scale_color_manual(values = c('purple', 'grey', 'grey', 'grey', 'grey'))<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Wir k\u00f6nnten auch mehrere Zeilen hervorheben, wenn wir wollten:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data, aes(x = as.factor(day), y = rank, group = team)) +\n  geom_line(aes(color = team, alpha = 1), size = 2) +\n  geom_point(aes(color = team, alpha = 1), size = 4) +\n  geom_point(color = \"#FFFFFF\", size = 1) +\n  scale_y_reverse(breaks = 1:nrow(data)) + \n  scale_x_discrete(breaks = 1:10) +\n  theme(legend.position = 'none') +\n  geom_text(data = data %&gt;% filter(day == \"1\"),\n            aes(label = team, x = 0.5), hjust = .5,\n            fontface = \"bold\", color = \"#888888\", size = 4) +\n  geom_text(data = data %&gt;% filter(day == \"10\"),\n            aes(label = team, x = 10.5), hjust = 0.5,\n            fontface = \"bold\", color = \"#888888\", size = 4) +\n  labs(x = 'Day', y = 'Rank', title = 'Team Ranking by Day') +\n  my_theme() <span style=\"color: #800080;\">+\n  scale_color_manual(values = c('purple', 'steelblue', 'grey', 'grey', 'grey'))<\/span><\/strong><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ein Bump-Diagramm ist eine Art Diagramm, das die Rangfolge verschiedener Gruppen im Zeitverlauf anstelle absoluter Werte anzeigt, um die Reihenfolge der Gruppen und nicht das Ausma\u00df der \u00c4nderung hervorzuheben. In diesem Tutorial wird erkl\u00e4rt, wie Sie mit ggplot2 ganz einfach ein Bump-Plot in R erstellen. Beispiel: Erstellen einer Reliefgrafik Um ein Bump-Chart in R zu [&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 ganz einfach ein Bump-Diagramm in R mit ggplot2 \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"In diesem Tutorial wird erkl\u00e4rt, wie Sie mit ggplot2 ganz einfach ein Bump-Plot 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\/bump-plot-in-r-mit-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"So erstellen Sie ganz einfach ein Bump-Diagramm in R mit ggplot2 \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"In diesem Tutorial wird erkl\u00e4rt, wie Sie mit ggplot2 ganz einfach ein Bump-Plot in R erstellen.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-29T19:13:06+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=\"4 Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/\",\"url\":\"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/\",\"name\":\"So erstellen Sie ganz einfach ein Bump-Diagramm in R mit ggplot2 \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/de\/#website\"},\"datePublished\":\"2023-07-29T19:13:06+00:00\",\"dateModified\":\"2023-07-29T19:13:06+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0\"},\"description\":\"In diesem Tutorial wird erkl\u00e4rt, wie Sie mit ggplot2 ganz einfach ein Bump-Plot in R erstellen.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/#breadcrumb\"},\"inLanguage\":\"de-DE\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Heim\",\"item\":\"https:\/\/statorials.org\/de\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"So erstellen sie mit ggplot2 ganz einfach ein reliefdiagramm 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 ganz einfach ein Bump-Diagramm in R mit ggplot2 \u2013 Statorials","description":"In diesem Tutorial wird erkl\u00e4rt, wie Sie mit ggplot2 ganz einfach ein Bump-Plot 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\/bump-plot-in-r-mit-ggplot2\/","og_locale":"de_DE","og_type":"article","og_title":"So erstellen Sie ganz einfach ein Bump-Diagramm in R mit ggplot2 \u2013 Statorials","og_description":"In diesem Tutorial wird erkl\u00e4rt, wie Sie mit ggplot2 ganz einfach ein Bump-Plot in R erstellen.","og_url":"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/","og_site_name":"Statorials","article_published_time":"2023-07-29T19:13:06+00:00","author":"Dr. Benjamin Anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr. Benjamin Anderson","Gesch\u00e4tzte Lesezeit":"4 Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/","url":"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/","name":"So erstellen Sie ganz einfach ein Bump-Diagramm in R mit ggplot2 \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/de\/#website"},"datePublished":"2023-07-29T19:13:06+00:00","dateModified":"2023-07-29T19:13:06+00:00","author":{"@id":"https:\/\/statorials.org\/de\/#\/schema\/person\/ec75c4d6365f2708f8a0ad3a42121aa0"},"description":"In diesem Tutorial wird erkl\u00e4rt, wie Sie mit ggplot2 ganz einfach ein Bump-Plot in R erstellen.","breadcrumb":{"@id":"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/#breadcrumb"},"inLanguage":"de-DE","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/de\/bump-plot-in-r-mit-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Heim","item":"https:\/\/statorials.org\/de\/"},{"@type":"ListItem","position":2,"name":"So erstellen sie mit ggplot2 ganz einfach ein reliefdiagramm 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\/472"}],"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=472"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/posts\/472\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/media?parent=472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/categories?post=472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/de\/wp-json\/wp\/v2\/tags?post=472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}