{"id":465,"date":"2023-07-29T19:48:38","date_gmt":"2023-07-29T19:48:38","guid":{"rendered":"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/"},"modified":"2023-07-29T19:48:38","modified_gmt":"2023-07-29T19:48:38","slug":"wykres-gantta-r-ggplot2","status":"publish","type":"post","link":"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/","title":{"rendered":"Jak utworzy\u0107 wykres gantta w r za pomoc\u0105 ggplot2"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\"><strong>Wykres Gantta<\/strong> to rodzaj wykresu przedstawiaj\u0105cego czas rozpocz\u0119cia i zako\u0144czenia r\u00f3\u017cnych zdarze\u0144.<\/span><\/p>\n<p> <span style=\"color: #000000;\">W tym samouczku wyja\u015bniono, jak utworzy\u0107 wykres Gantta w j\u0119zyku R przy u\u017cyciu pakietu <strong>ggplot2<\/strong> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Tworzenie wykresu Gantta w R przy u\u017cyciu ggplot2<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Za\u0142\u00f3\u017cmy, \u017ce mamy nast\u0119puj\u0105cy zestaw danych, kt\u00f3ry pokazuje godzin\u0119 rozpocz\u0119cia i zako\u0144czenia czterech r\u00f3\u017cnych zmian pracownik\u00f3w w sklepie:<\/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;\">Aby utworzy\u0107 wykres Gantta za pomoc\u0105 ggplot2, kt\u00f3ry wizualizuje czas rozpocz\u0119cia i zako\u0144czenia ka\u017cdego pracownika, mo\u017cemy u\u017cy\u0107 nast\u0119puj\u0105cego kodu:<\/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;\">W wyniku tego powstaje nast\u0119puj\u0105cy wykres Gantta:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Dzi\u0119ki kilku poprawkom w uk\u0142adzie mo\u017cemy sprawi\u0107, \u017ce ten wykres Gantta b\u0119dzie wygl\u0105da\u0142 znacznie lepiej:<\/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;\">Daje to nast\u0119puj\u0105cy wykres:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Dodatkowo, je\u015bli chcesz ustawi\u0107 dok\u0142adne kolory, kt\u00f3re maj\u0105 by\u0107 u\u017cywane na wykresie, mo\u017cesz u\u017cy\u0107 nast\u0119puj\u0105cego kodu:<\/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;\">Daje to nast\u0119puj\u0105cy wykres z kolorami r\u00f3\u017cowym, fioletowym i niebieskim, kt\u00f3re reprezentuj\u0105 r\u00f3\u017cne typy zmian:<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>U\u017cyj niestandardowych motyw\u00f3w<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Mo\u017cemy p\u00f3j\u015b\u0107 dalej, korzystaj\u0105c z niestandardowych motyw\u00f3w z biblioteki <a href=\"https:\/\/yutannihilation.github.io\/allYourFigureAreBelongToUs\/ggthemes\/\" target=\"_blank\" rel=\"noopener\"><strong>ggthemes<\/strong><\/a> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Na przyk\u0142ad mo\u017cemy utworzy\u0107 wykres Gantta wykorzystuj\u0105cy motyw inspirowany Wall Street Journal:<\/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;\">Mo\u017cemy te\u017c u\u017cy\u0107 motywu inspirowanego \u201eThe Economist\u201d:<\/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;\">A mo\u017ce motyw inspirowany <a href=\"https:\/\/fivethirtyeight.com\/\" target=\"_blank\" rel=\"noopener\">Five Thirty Eight<\/a> :<\/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;\">Pe\u0142n\u0105 list\u0119 motyw\u00f3w dost\u0119pnych w bibliotece <em>ggthemes<\/em> znajdziesz na <a href=\"https:\/\/yutannihilation.github.io\/allYourFigureAreBelongToUs\/ggthemes\/\" target=\"_blank\" rel=\"noopener\">stronie dokumentacji<\/a> .<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Wykres Gantta to rodzaj wykresu przedstawiaj\u0105cego czas rozpocz\u0119cia i zako\u0144czenia r\u00f3\u017cnych zdarze\u0144. W tym samouczku wyja\u015bniono, jak utworzy\u0107 wykres Gantta w j\u0119zyku R przy u\u017cyciu pakietu ggplot2 . Tworzenie wykresu Gantta w R przy u\u017cyciu ggplot2 Za\u0142\u00f3\u017cmy, \u017ce mamy nast\u0119puj\u0105cy zestaw danych, kt\u00f3ry pokazuje godzin\u0119 rozpocz\u0119cia i zako\u0144czenia czterech r\u00f3\u017cnych zmian pracownik\u00f3w w sklepie: #create [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-465","post","type-post","status-publish","format-standard","hentry","category-przewodnik"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Jak utworzy\u0107 wykres Gantta w R za pomoc\u0105 ggplot2 - Statologia<\/title>\n<meta name=\"description\" content=\"Prosty tutorial jak stworzy\u0107 wykres Gantta w R przy u\u017cyciu 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\/pl\/wykres-gantta-r-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"pl_PL\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Jak utworzy\u0107 wykres Gantta w R za pomoc\u0105 ggplot2 - Statologia\" \/>\n<meta property=\"og:description\" content=\"Prosty tutorial jak stworzy\u0107 wykres Gantta w R przy u\u017cyciu ggplot2.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pl\/wykres-gantta-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=\"Benjamin Anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Napisane przez\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin Anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Szacowany czas czytania\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minuty\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/\",\"url\":\"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/\",\"name\":\"Jak utworzy\u0107 wykres Gantta w R za pomoc\u0105 ggplot2 - Statologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pl\/#website\"},\"datePublished\":\"2023-07-29T19:48:38+00:00\",\"dateModified\":\"2023-07-29T19:48:38+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965\"},\"description\":\"Prosty tutorial jak stworzy\u0107 wykres Gantta w R przy u\u017cyciu ggplot2.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/#breadcrumb\"},\"inLanguage\":\"pl-PL\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Dom\",\"item\":\"https:\/\/statorials.org\/pl\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Jak utworzy\u0107 wykres gantta w r za pomoc\u0105 ggplot2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pl\/#website\",\"url\":\"https:\/\/statorials.org\/pl\/\",\"name\":\"Statorials\",\"description\":\"Tw\u00f3j przewodnik po kompetencjach statystycznych!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pl\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pl-PL\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965\",\"name\":\"Benjamin Anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pl-PL\",\"@id\":\"https:\/\/statorials.org\/pl\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin Anderson\"},\"description\":\"Cze\u015b\u0107, jestem Benjamin i jestem emerytowanym profesorem statystyki, kt\u00f3ry zosta\u0142 oddanym nauczycielem Statorials. Dzi\u0119ki bogatemu do\u015bwiadczeniu i wiedzy specjalistycznej w dziedzinie statystyki ch\u0119tnie dziel\u0119 si\u0119 swoj\u0105 wiedz\u0105, aby wzmocni\u0107 pozycj\u0119 uczni\u00f3w za po\u015brednictwem Statorials. Wiedzie\u0107 wi\u0119cej\",\"sameAs\":[\"https:\/\/statorials.org\/pl\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Jak utworzy\u0107 wykres Gantta w R za pomoc\u0105 ggplot2 - Statologia","description":"Prosty tutorial jak stworzy\u0107 wykres Gantta w R przy u\u017cyciu 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\/pl\/wykres-gantta-r-ggplot2\/","og_locale":"pl_PL","og_type":"article","og_title":"Jak utworzy\u0107 wykres Gantta w R za pomoc\u0105 ggplot2 - Statologia","og_description":"Prosty tutorial jak stworzy\u0107 wykres Gantta w R przy u\u017cyciu ggplot2.","og_url":"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/","og_site_name":"Statorials","article_published_time":"2023-07-29T19:48:38+00:00","author":"Benjamin Anderson","twitter_card":"summary_large_image","twitter_misc":{"Napisane przez":"Benjamin Anderson","Szacowany czas czytania":"3 minuty"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/","url":"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/","name":"Jak utworzy\u0107 wykres Gantta w R za pomoc\u0105 ggplot2 - Statologia","isPartOf":{"@id":"https:\/\/statorials.org\/pl\/#website"},"datePublished":"2023-07-29T19:48:38+00:00","dateModified":"2023-07-29T19:48:38+00:00","author":{"@id":"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965"},"description":"Prosty tutorial jak stworzy\u0107 wykres Gantta w R przy u\u017cyciu ggplot2.","breadcrumb":{"@id":"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/#breadcrumb"},"inLanguage":"pl-PL","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pl\/wykres-gantta-r-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Dom","item":"https:\/\/statorials.org\/pl\/"},{"@type":"ListItem","position":2,"name":"Jak utworzy\u0107 wykres gantta w r za pomoc\u0105 ggplot2"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pl\/#website","url":"https:\/\/statorials.org\/pl\/","name":"Statorials","description":"Tw\u00f3j przewodnik po kompetencjach statystycznych!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pl\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pl-PL"},{"@type":"Person","@id":"https:\/\/statorials.org\/pl\/#\/schema\/person\/6484727a4612df3e69f016c3129c6965","name":"Benjamin Anderson","image":{"@type":"ImageObject","inLanguage":"pl-PL","@id":"https:\/\/statorials.org\/pl\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pl\/wp-content\/uploads\/2023\/11\/Benjamin-Anderson-96x96.jpg","caption":"Benjamin Anderson"},"description":"Cze\u015b\u0107, jestem Benjamin i jestem emerytowanym profesorem statystyki, kt\u00f3ry zosta\u0142 oddanym nauczycielem Statorials. Dzi\u0119ki bogatemu do\u015bwiadczeniu i wiedzy specjalistycznej w dziedzinie statystyki ch\u0119tnie dziel\u0119 si\u0119 swoj\u0105 wiedz\u0105, aby wzmocni\u0107 pozycj\u0119 uczni\u00f3w za po\u015brednictwem Statorials. Wiedzie\u0107 wi\u0119cej","sameAs":["https:\/\/statorials.org\/pl"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/posts\/465","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/comments?post=465"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/posts\/465\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/media?parent=465"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/categories?post=465"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pl\/wp-json\/wp\/v2\/tags?post=465"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}