{"id":466,"date":"2023-07-29T19:48:38","date_gmt":"2023-07-29T19:48:38","guid":{"rendered":"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/"},"modified":"2023-07-29T19:48:38","modified_gmt":"2023-07-29T19:48:38","slug":"grafico-de-gantt-r-ggplot2","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/","title":{"rendered":"Como criar um gr\u00e1fico de gantt em r usando ggplot2"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Um <strong>gr\u00e1fico de Gantt<\/strong> \u00e9 um tipo de gr\u00e1fico que mostra os hor\u00e1rios de in\u00edcio e t\u00e9rmino de v\u00e1rios eventos.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Este tutorial explica como criar um gr\u00e1fico de Gantt em R usando o pacote <strong>ggplot2<\/strong> .<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Criando um gr\u00e1fico de Gantt em R usando ggplot2<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Digamos que temos o seguinte conjunto de dados que mostra os hor\u00e1rios de in\u00edcio e t\u00e9rmino de quatro turnos diferentes de trabalhadores em uma loja:<\/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;\">Para criar um gr\u00e1fico de Gantt usando ggplot2 que visualize os hor\u00e1rios de in\u00edcio e t\u00e9rmino de cada trabalhador, podemos usar o seguinte c\u00f3digo:<\/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;\">Isso produz o seguinte gr\u00e1fico de Gantt:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Com alguns ajustes no layout, podemos fazer com que este gr\u00e1fico de Gantt tenha uma apar\u00eancia muito melhor:<\/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;\">Isso produz o seguinte gr\u00e1fico:<\/span><\/p>\n<p> <span style=\"color: #000000;\">Al\u00e9m disso, se quiser definir as cores exatas a serem usadas no gr\u00e1fico, voc\u00ea pode usar o seguinte c\u00f3digo:<\/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;\">Isso produz o seguinte gr\u00e1fico com as cores rosa, roxo e azul para representar os diferentes tipos de turno:<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Use temas personalizados<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Podemos ir mais longe usando temas personalizados da biblioteca <a href=\"https:\/\/yutannihilation.github.io\/allYourFigureAreBelongToUs\/ggthemes\/\" target=\"_blank\" rel=\"noopener\"><strong>ggthemes<\/strong><\/a> .<\/span><\/p>\n<p> <span style=\"color: #000000;\">Por exemplo, podemos criar um gr\u00e1fico de Gantt que use um tema inspirado no 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;\">Ou poder\u00edamos usar um tema inspirado no 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;\">Ou talvez um tema inspirado em <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;\">Para obter uma lista completa de temas dispon\u00edveis na biblioteca <em>ggthemes<\/em> , consulte <a href=\"https:\/\/yutannihilation.github.io\/allYourFigureAreBelongToUs\/ggthemes\/\" target=\"_blank\" rel=\"noopener\">a p\u00e1gina de documenta\u00e7\u00e3o<\/a> .<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Um gr\u00e1fico de Gantt \u00e9 um tipo de gr\u00e1fico que mostra os hor\u00e1rios de in\u00edcio e t\u00e9rmino de v\u00e1rios eventos. Este tutorial explica como criar um gr\u00e1fico de Gantt em R usando o pacote ggplot2 . Criando um gr\u00e1fico de Gantt em R usando ggplot2 Digamos que temos o seguinte conjunto de dados que mostra [&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-466","post","type-post","status-publish","format-standard","hentry","category-guia"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Como criar um gr\u00e1fico de Gantt em R usando ggplot2 - Estatologia<\/title>\n<meta name=\"description\" content=\"Um tutorial simples sobre como criar um gr\u00e1fico de Gantt em R usando 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\/pt\/grafico-de-gantt-r-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como criar um gr\u00e1fico de Gantt em R usando ggplot2 - Estatologia\" \/>\n<meta property=\"og:description\" content=\"Um tutorial simples sobre como criar um gr\u00e1fico de Gantt em R usando ggplot2.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/grafico-de-gantt-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. benjamim anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Escrito por\" \/>\n\t<meta name=\"twitter:data1\" content=\"Dr. benjamim anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Tempo estimado de leitura\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/\",\"url\":\"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/\",\"name\":\"Como criar um gr\u00e1fico de Gantt em R usando ggplot2 - Estatologia\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-29T19:48:38+00:00\",\"dateModified\":\"2023-07-29T19:48:38+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Um tutorial simples sobre como criar um gr\u00e1fico de Gantt em R usando ggplot2.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como criar um gr\u00e1fico de gantt em r usando ggplot2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/pt\/#website\",\"url\":\"https:\/\/statorials.org\/pt\/\",\"name\":\"Statorials\",\"description\":\"O seu guia para a literacia estat\u00edstica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/pt\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"pt-PT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\",\"name\":\"Dr. benjamim anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"pt-PT\",\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Dr. benjamim anderson\"},\"description\":\"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais\",\"sameAs\":[\"https:\/\/statorials.org\/pt\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Como criar um gr\u00e1fico de Gantt em R usando ggplot2 - Estatologia","description":"Um tutorial simples sobre como criar um gr\u00e1fico de Gantt em R usando 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\/pt\/grafico-de-gantt-r-ggplot2\/","og_locale":"pt_PT","og_type":"article","og_title":"Como criar um gr\u00e1fico de Gantt em R usando ggplot2 - Estatologia","og_description":"Um tutorial simples sobre como criar um gr\u00e1fico de Gantt em R usando ggplot2.","og_url":"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/","og_site_name":"Statorials","article_published_time":"2023-07-29T19:48:38+00:00","author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"3 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/","url":"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/","name":"Como criar um gr\u00e1fico de Gantt em R usando ggplot2 - Estatologia","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-29T19:48:38+00:00","dateModified":"2023-07-29T19:48:38+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Um tutorial simples sobre como criar um gr\u00e1fico de Gantt em R usando ggplot2.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/grafico-de-gantt-r-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como criar um gr\u00e1fico de gantt em r usando ggplot2"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/pt\/#website","url":"https:\/\/statorials.org\/pt\/","name":"Statorials","description":"O seu guia para a literacia estat\u00edstica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/pt\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"pt-PT"},{"@type":"Person","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666","name":"Dr. benjamim anderson","image":{"@type":"ImageObject","inLanguage":"pt-PT","@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/pt\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Dr. benjamim anderson"},"description":"Ol\u00e1, sou Benjamin, um professor aposentado de estat\u00edstica que se tornou professor dedicado na Statorials. Com vasta experi\u00eancia e conhecimento na \u00e1rea de estat\u00edstica, estou empenhado em compartilhar meu conhecimento para capacitar os alunos por meio de Statorials. Saber mais","sameAs":["https:\/\/statorials.org\/pt"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/466","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/comments?post=466"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/466\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=466"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=466"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=466"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}