{"id":961,"date":"2023-07-28T04:21:01","date_gmt":"2023-07-28T04:21:01","guid":{"rendered":"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/"},"modified":"2023-07-28T04:21:01","modified_gmt":"2023-07-28T04:21:01","slug":"definir-limites-do-eixo-ggplot2","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/","title":{"rendered":"Como definir limites de eixo no ggplot2"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Muitas vezes voc\u00ea pode querer definir limites de eixo em um gr\u00e1fico usando <a href=\"https:\/\/ggplot2.tidyverse.org\/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">ggplot2<\/a> . Voc\u00ea pode fazer isso facilmente usando as seguintes fun\u00e7\u00f5es:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>xlim()<\/strong> : Especifica o limite inferior e superior do eixo x.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>ylim():<\/strong> especifica o limite inferior e superior do eixo y.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Observe que ambos os m\u00e9todos remover\u00e3o dados fora dos limites, o que \u00e0s vezes pode produzir consequ\u00eancias indesejadas. Para alterar os limites do eixo sem remover observa\u00e7\u00f5es de dados, voc\u00ea pode usar coord_cartesian():<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>coord_cartesian():<\/strong> especifica os limites dos eixos x e y sem remover observa\u00e7\u00f5es.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Este tutorial explica v\u00e1rias maneiras de usar essas fun\u00e7\u00f5es usando o seguinte gr\u00e1fico de dispers\u00e3o feito com o conjunto de dados R incorporado <em>mtcars<\/em> :<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#load ggplot2<\/span>\nlibrary(ggplot2)\n\n<span style=\"color: #008080;\">#create scatterplot\n<\/span>ggplot(mtcars, aes(mpg, wt)) +\n  geom_point()\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10095 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/axislimitsggplot1.png\" alt=\"\" width=\"610\" height=\"367\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 1: Definir limites do eixo X usando xlim()<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como definir os limites do eixo X do gr\u00e1fico de dispers\u00e3o usando a fun\u00e7\u00e3o <strong>xlim()<\/strong> :<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create scatterplot with x-axis ranging from 15 to 30\n<\/span>ggplot(mtcars, aes(mpg, wt)) +\n  geom_point() +\n  xlim <span style=\"color: #3366ff;\">(15, 30)\n\n<span style=\"color: #808080;\"><em>Warning message:\n\u201cRemoved 9 rows containing missing values (geom_point).\u201d\n<\/em><\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10096 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/axislimitsggplot2.png\" alt=\"Configurando limites do eixo X no ggplot2\" width=\"614\" height=\"369\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Voc\u00ea tamb\u00e9m pode usar <strong>NA<\/strong> para definir apenas o limite superior do eixo x e deixar o ggplot2 escolher automaticamente o limite inferior:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create scatterplot with x-axis upper limit at 30\n<\/span>ggplot(mtcars, aes(mpg, wt)) +\n  geom_point() +\n  xlim <span style=\"color: #3366ff;\">( <span style=\"color: #993300;\">NA<\/span> , 30)\n\n<span style=\"color: #808080;\"><em>Warning message:\n\u201cRemoved 4 rows containing missing values (geom_point).\u201d<\/em><\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10097 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/axislimitsggplot3.png\" alt=\"Como definir limites de eixo no ggplot2\" width=\"613\" height=\"366\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 2: Definir limites do eixo Y usando ylim()<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como definir os limites do eixo y do gr\u00e1fico de dispers\u00e3o usando a fun\u00e7\u00e3o <strong>ylim()<\/strong> :<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create scatterplot with y-axis ranging from 2 to 4\n<\/span>ggplot(mtcars, aes(mpg, wt)) +\n  geom_point() +\n  ylim <span style=\"color: #3366ff;\">(2, 4)\n\n<span style=\"color: #808080;\"><em>Warning message:\n\u201cRemoved 8 rows containing missing values (geom_point).\u201d<\/em><\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10098 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/axislimitsggplot4.png\" alt=\"Defina os limites do eixo Y no ggplot2\" width=\"632\" height=\"376\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Voc\u00ea tamb\u00e9m pode usar <strong>NA<\/strong> para definir apenas o limite inferior do eixo y e deixar o ggplot2 escolher automaticamente o limite superior:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create scatterplot with y-axis lower limit at 2\n<\/span>ggplot(mtcars, aes(mpg, wt)) +\n  geom_point() +\n  xlim <span style=\"color: #3366ff;\">(2, <span style=\"color: #993300;\">NA<\/span> )\n\n<span style=\"color: #808080;\"><em>Warning message:\n\u201cRemoved 4 rows containing missing values (geom_point).\u201d<\/em><\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10099 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/axislimitsggplot5.png\" alt=\"\" width=\"610\" height=\"370\" srcset=\"\" sizes=\"auto, \"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 3: Definir limites de eixo usando coordenadas_cartesian()<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">O c\u00f3digo a seguir mostra como definir os limites do eixo y do gr\u00e1fico de dispers\u00e3o usando a fun\u00e7\u00e3o <strong>coord_cartesian()<\/strong> :<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create scatterplot with y-axis ranging from 2 to 4\n<\/span>ggplot(mtcars, aes(mpg, wt)) +\n  geom_point() +\n  coord_cartesian(xlim =c <span style=\"color: #3366ff;\">(15, 25)<\/span> , ylim = c <span style=\"color: #3366ff;\">(3, 4)<\/span> )<span style=\"color: #3366ff;\">\n<\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10100 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/axislimitsggplot6.png\" alt=\"Defina os limites do eixo no ggplot2 usando a fun\u00e7\u00e3o coord_cartesian()\" width=\"614\" height=\"372\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\"><em>Voc\u00ea pode encontrar mais tutoriais do ggplot2 <a href=\"https:\/\/statorials.org\/pt\/estatologia-explica-conceitos-de-forma-simples-e-direta-facilitamos-o-aprendizado-de-estatistica\/\" target=\"_blank\" rel=\"noopener noreferrer\">aqui<\/a> .<\/em><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Muitas vezes voc\u00ea pode querer definir limites de eixo em um gr\u00e1fico usando ggplot2 . Voc\u00ea pode fazer isso facilmente usando as seguintes fun\u00e7\u00f5es: xlim() : Especifica o limite inferior e superior do eixo x. ylim(): especifica o limite inferior e superior do eixo y. Observe que ambos os m\u00e9todos remover\u00e3o dados fora dos limites, [&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-961","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 definir limites de eixo no ggplot2 \u2013 Statorials<\/title>\n<meta name=\"description\" content=\"Uma explica\u00e7\u00e3o simples de como definir limites de eixo em um gr\u00e1fico no ggplot2, incluindo v\u00e1rios exemplos.\" \/>\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\/definir-limites-do-eixo-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como definir limites de eixo no ggplot2 \u2013 Statorials\" \/>\n<meta property=\"og:description\" content=\"Uma explica\u00e7\u00e3o simples de como definir limites de eixo em um gr\u00e1fico no ggplot2, incluindo v\u00e1rios exemplos.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T04:21:01+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/axislimitsggplot1.png\" \/>\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=\"2 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/\",\"url\":\"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/\",\"name\":\"Como definir limites de eixo no ggplot2 \u2013 Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-28T04:21:01+00:00\",\"dateModified\":\"2023-07-28T04:21:01+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Uma explica\u00e7\u00e3o simples de como definir limites de eixo em um gr\u00e1fico no ggplot2, incluindo v\u00e1rios exemplos.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como definir limites de eixo no 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 definir limites de eixo no ggplot2 \u2013 Statorials","description":"Uma explica\u00e7\u00e3o simples de como definir limites de eixo em um gr\u00e1fico no ggplot2, incluindo v\u00e1rios exemplos.","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\/definir-limites-do-eixo-ggplot2\/","og_locale":"pt_PT","og_type":"article","og_title":"Como definir limites de eixo no ggplot2 \u2013 Statorials","og_description":"Uma explica\u00e7\u00e3o simples de como definir limites de eixo em um gr\u00e1fico no ggplot2, incluindo v\u00e1rios exemplos.","og_url":"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/","og_site_name":"Statorials","article_published_time":"2023-07-28T04:21:01+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/axislimitsggplot1.png"}],"author":"Dr. benjamim anderson","twitter_card":"summary_large_image","twitter_misc":{"Escrito por":"Dr. benjamim anderson","Tempo estimado de leitura":"2 minutos"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/","url":"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/","name":"Como definir limites de eixo no ggplot2 \u2013 Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-28T04:21:01+00:00","dateModified":"2023-07-28T04:21:01+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Uma explica\u00e7\u00e3o simples de como definir limites de eixo em um gr\u00e1fico no ggplot2, incluindo v\u00e1rios exemplos.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/definir-limites-do-eixo-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como definir limites de eixo no 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\/961","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=961"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/961\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}