{"id":467,"date":"2023-07-29T19:48:38","date_gmt":"2023-07-29T19:48:38","guid":{"rendered":"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/"},"modified":"2023-07-29T19:48:38","modified_gmt":"2023-07-29T19:48:38","slug":"gantt-diagram-r-ggplot2","status":"publish","type":"post","link":"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/","title":{"rendered":"Hoe u een gantt-diagram in r maakt met ggplot2"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Een <strong>Gantt-diagram<\/strong> is een soort diagram dat de begin- en eindtijden van verschillende gebeurtenissen weergeeft.<\/span><\/p>\n<p> <span style=\"color: #000000;\">In deze zelfstudie wordt uitgelegd hoe u een Gantt-diagram in R maakt met behulp van het <strong>ggplot2-<\/strong> pakket.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Een Gantt-diagram maken in R met ggplot2<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Laten we zeggen dat we de volgende gegevensset hebben die de begin- en eindtijden toont van vier verschillende ploegendiensten in een winkel:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame<\/span>\ndata &lt;- data.frame(name = c('Bob', 'Greg', 'Mike', 'Andy'), \nstart = c(4, 7, 12, 16),\nend = c(12, 11, 8, 22),\nshift_type = c('early', 'mid_day', 'mid_day', 'late')\n)\ndata\n\n# name start end shift_type\n#1 Bob 4 12 early\n#2 Greg 7 11 mid_day\n#3 Mike 12 8 mid_day\n#4 Andy 16 22 late<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Om een Gantt-diagram te maken met ggplot2 dat de begin- en eindtijden van elke werknemer visualiseert, kunnen we de volgende code gebruiken:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#install (if not already installed) and load ggplot2<\/span>\nif(!require(ggplot2)){install.packages('ggplot2')}\n\n<span style=\"color: #008080;\">#create gantt chart that visualizes start and end time for each worker<\/span>\nggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +\n  geom_segment()\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Dit levert het volgende Gantt-diagram op:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Met een paar aanpassingen aan de lay-out kunnen we dit Gantt-diagram er veel beter uit laten zien:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +<\/strong>\n<strong>theme_bw()+ <span style=\"color: #008080;\">#use ggplot theme with black gridlines and white background<\/span><\/strong>\n<strong>geom_segment(size=8) + <span style=\"color: #008080;\">#increase line width of segments in the chart<\/span><\/strong>\n<strong>labs(title='Worker Schedule', x='Time', y='Worker Name')<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Dit levert de volgende grafiek op:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Als u bovendien de exacte kleuren wilt instellen die u in het diagram wilt gebruiken, kunt u de volgende code gebruiken:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +\n  theme_bw()+ <span style=\"color: #008080;\">#use ggplot theme with black gridlines and white background<\/span>\n  geom_segment(size=8) + <span style=\"color: #008080;\">#increase line width of segments in the chart<\/span>\n  labs(title='Worker Schedule', x='Time', y='Worker Name') +\n  scale_color_manual(values = c('pink', 'purple', 'blue'))<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Dit levert de volgende grafiek op met de kleuren roze, paars en blauw om de verschillende ploegendiensten weer te geven:<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Gebruik aangepaste thema&#8217;s<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">We kunnen verder gaan door aangepaste thema&#8217;s uit de <a href=\"https:\/\/yutannihilation.github.io\/allYourFigureAreBelongToUs\/ggthemes\/\" target=\"_blank\" rel=\"noopener\"><strong>ggthemes-<\/strong><\/a> bibliotheek te gebruiken.<\/span><\/p>\n<p> <span style=\"color: #000000;\">We kunnen bijvoorbeeld een Gantt-diagram maken dat een op de Wall Street Journal ge\u00efnspireerd thema gebruikt:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#load <em>ggthemes<\/em> library<\/span>\nlibrary(ggthemes)\n\n<span style=\"color: #008080;\">#create scatterplot with Wall Street Journal theme\n<\/span>ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +\n  theme_bw()+\n  geom_segment(size=8) +\n  labs(title='Worker Schedule', x='Time', y='Worker Name') +\n  scale_color_manual(values = c('pink', 'purple', 'blue')) <span style=\"color: #800080;\">+\n  theme_wsj() + \n  theme(axis.title = element_text())<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Of we kunnen een thema gebruiken dat is ge\u00efnspireerd door The Economist:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +\n  theme_bw()+\n  geom_segment(size=8) +\n  labs(title='Worker Schedule', x='Time', y='Worker Name') +\n  scale_color_manual(values = c('pink', 'purple', 'blue')) <span style=\"color: #800080;\">+\n  theme_economist() + \n  theme(axis.title = element_text())<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Of misschien een door <a href=\"https:\/\/fivethirtyeight.com\/\" target=\"_blank\" rel=\"noopener\">Five Thirty Eight<\/a> ge\u00efnspireerd thema:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>ggplot(data, aes(x=start, xend=end, y=name, yend=name, color=shift_type)) +\n  theme_bw()+\n  geom_segment(size=8) +\n  labs(title='Worker Schedule', x='Time', y='Worker Name') +\n  scale_color_manual(values = c('pink', 'purple', 'blue')) <span style=\"color: #800080;\">+\n  theme_fivethirtyeight() + \n  theme(axis.title = element_text())<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Zie <a href=\"https:\/\/yutannihilation.github.io\/allYourFigureAreBelongToUs\/ggthemes\/\" target=\"_blank\" rel=\"noopener\">de documentatiepagina<\/a> voor een volledige lijst met thema&#8217;s die beschikbaar zijn in de <em>ggthemes-<\/em> bibliotheek.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Een Gantt-diagram is een soort diagram dat de begin- en eindtijden van verschillende gebeurtenissen weergeeft. In deze zelfstudie wordt uitgelegd hoe u een Gantt-diagram in R maakt met behulp van het ggplot2- pakket. Een Gantt-diagram maken in R met ggplot2 Laten we zeggen dat we de volgende gegevensset hebben die de begin- en eindtijden toont [&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":[],"class_list":["post-467","post","type-post","status-publish","format-standard","hentry","category-gids"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Een Gantt-diagram maken in R met ggplot2 - Statorials<\/title>\n<meta name=\"description\" content=\"Een eenvoudige tutorial over hoe u een Gantt-diagram in R kunt maken met ggplot2.\" \/>\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\/nl\/gantt-diagram-r-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"de_DE\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Een Gantt-diagram maken in R met ggplot2 - Statorials\" \/>\n<meta property=\"og:description\" content=\"Een eenvoudige tutorial over hoe u een Gantt-diagram in R kunt maken met ggplot2.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-29T19:48:38+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\u00a0Minuten\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/\",\"url\":\"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/\",\"name\":\"Een Gantt-diagram maken in R met ggplot2 - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/nl\/#website\"},\"datePublished\":\"2023-07-29T19:48:38+00:00\",\"dateModified\":\"2023-07-29T19:48:38+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\"},\"description\":\"Een eenvoudige tutorial over hoe u een Gantt-diagram in R kunt maken met ggplot2.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/#breadcrumb\"},\"inLanguage\":\"de\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Thuis\",\"item\":\"https:\/\/statorials.org\/nl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Hoe u een gantt-diagram in r maakt met ggplot2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/nl\/#website\",\"url\":\"https:\/\/statorials.org\/nl\/\",\"name\":\"Statorials\",\"description\":\"Uw gids voor statistische competentie\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/nl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"de\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219\",\"name\":\"Dr.benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"de\",\"@id\":\"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr.benjamin anderson\"},\"description\":\"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder\",\"sameAs\":[\"http:\/\/statorials.org\/nl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Een Gantt-diagram maken in R met ggplot2 - Statorials","description":"Een eenvoudige tutorial over hoe u een Gantt-diagram in R kunt maken met ggplot2.","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\/nl\/gantt-diagram-r-ggplot2\/","og_locale":"de_DE","og_type":"article","og_title":"Een Gantt-diagram maken in R met ggplot2 - Statorials","og_description":"Een eenvoudige tutorial over hoe u een Gantt-diagram in R kunt maken met ggplot2.","og_url":"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/","og_site_name":"Statorials","article_published_time":"2023-07-29T19:48:38+00:00","author":"Dr.benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Verfasst von":"Dr.benjamin anderson","Gesch\u00e4tzte Lesezeit":"3\u00a0Minuten"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/","url":"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/","name":"Een Gantt-diagram maken in R met ggplot2 - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/nl\/#website"},"datePublished":"2023-07-29T19:48:38+00:00","dateModified":"2023-07-29T19:48:38+00:00","author":{"@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219"},"description":"Een eenvoudige tutorial over hoe u een Gantt-diagram in R kunt maken met ggplot2.","breadcrumb":{"@id":"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/#breadcrumb"},"inLanguage":"de","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/nl\/gantt-diagram-r-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Thuis","item":"https:\/\/statorials.org\/nl\/"},{"@type":"ListItem","position":2,"name":"Hoe u een gantt-diagram in r maakt met ggplot2"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/nl\/#website","url":"https:\/\/statorials.org\/nl\/","name":"Statorials","description":"Uw gids voor statistische competentie","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/nl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"de"},{"@type":"Person","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/d4b8842173cca1bb62cdec41860e4219","name":"Dr.benjamin anderson","image":{"@type":"ImageObject","inLanguage":"de","@id":"https:\/\/statorials.org\/nl\/#\/schema\/person\/image\/","url":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"http:\/\/statorials.org\/nl\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr.benjamin anderson"},"description":"Ik ben Benjamin, een gepensioneerde hoogleraar statistiek die nu een toegewijde Statorials-lesgever is. Ik heb uitgebreide ervaring en expertise op het gebied van statistiek en ik ben vastbesloten om mijn kennis te delen met studenten via Statorials. Lees verder","sameAs":["http:\/\/statorials.org\/nl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/comments?post=467"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/posts\/467\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/media?parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/categories?post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/nl\/wp-json\/wp\/v2\/tags?post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}