{"id":2268,"date":"2023-07-23T00:20:55","date_gmt":"2023-07-23T00:20:55","guid":{"rendered":"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/"},"modified":"2023-07-23T00:20:55","modified_gmt":"2023-07-23T00:20:55","slug":"r-plot-new-ainda-nao-foi-chamado","status":"publish","type":"post","link":"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/","title":{"rendered":"Como consertar em r: plot.new ainda n\u00e3o foi chamado"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Um erro que voc\u00ea pode encontrar ao usar R \u00e9:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong>Error in plot.xy(xy.coords(x, y), type = type, ...): \n  plot.new has not been called yet\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Este erro ocorre quando voc\u00ea tenta executar uma a\u00e7\u00e3o que exige que j\u00e1 exista um gr\u00e1fico em R, mas n\u00e3o existe nenhum gr\u00e1fico.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Os exemplos a seguir mostram como corrigir esse erro na pr\u00e1tica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 1: Como corrigir o erro com linhas()<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Suponha que estejamos tentando tra\u00e7ar uma linha de regress\u00e3o ajustada em R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#createdata\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (x=c(1, 2, 2, 3, 5, 6, 8, 8, 9, 9, 10, 11, 12, 15, 15),\n                 y=c(2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 16, 19, 28))\n\n<span style=\"color: #008080;\">#fit polynomial regression model\n<\/span>model &lt;- lm(y~poly(x, 2), data=df)\n\n<span style=\"color: #008080;\">#define new sequence of x-values\n<\/span>new_x &lt;- seq(min(df$x), max(df$y))\n\n<span style=\"color: #008080;\">#attempt to plot fitted regression line\n<\/span>lines(new_x, predict(model, newdata = data. <span style=\"color: #3366ff;\">frame<\/span> (x=new_x))) \n\nError in plot.xy(xy.coords(x, y), type = type, ...): \n  plot.new has not been called yet<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Estamos recebendo um erro porque n\u00e3o podemos usar a fun\u00e7\u00e3o <strong>lines()<\/strong> sem primeiro criar um caminho em R.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Para corrigir esse erro, podemos primeiro criar um gr\u00e1fico de dispers\u00e3o e depois usar a fun\u00e7\u00e3o <strong>lines()<\/strong> :<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#create data\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (x=c(1, 2, 2, 3, 5, 6, 8, 8, 9, 9, 10, 11, 12, 15, 15),\n                 y=c(2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 16, 19, 28))\n\n<span style=\"color: #008080;\">#fit polynomial regression model\n<\/span>model &lt;- lm(y~poly(x, 2), data=df)\n\n<span style=\"color: #008080;\">#define new sequence of x-values\n<\/span>new_x &lt;- seq(min(df$x), max(df$y))\n\n<span style=\"color: #008080;\">#create scatterplot of x vs. y values\n<\/span>plot(y~x, data=df)\n\n<span style=\"color: #008080;\">#attempt to plot fitted regression line\n<\/span>lines(new_x, predict(model, newdata = data. <span style=\"color: #3366ff;\">frame<\/span> (x=new_x)))<\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-20681 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lignes11.png\" alt=\"\" width=\"468\" height=\"428\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Observe que n\u00e3o estamos recebendo um erro porque usamos primeiro a fun\u00e7\u00e3o <strong>plot()<\/strong> antes de usar a fun\u00e7\u00e3o <strong>lines()<\/strong> .<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Exemplo 2: Como corrigir um erro com abline()<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Suponha que estejamos tentando criar um gr\u00e1fico de dispers\u00e3o com uma linha reta horizontal em R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#create data\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (x=c(1, 2, 2, 3, 5, 6, 8, 8, 9, 9, 10, 11, 12, 15, 15),\n                 y=c(2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 16, 19, 28))\n\n<span style=\"color: #008080;\">#attempt to add horizontal line at y=10\n<\/span>abline(a=10, b=0, lwd=2)\n\nError in plot.xy(xy.coords(x, y), type = type, ...):\n  plot.new has not been called yet\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Estamos recebendo um erro porque n\u00e3o podemos usar a fun\u00e7\u00e3o <strong>abline()<\/strong> sem primeiro criar um gr\u00e1fico em R.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Para corrigir esse erro, podemos primeiro criar um gr\u00e1fico de dispers\u00e3o e depois usar a fun\u00e7\u00e3o <strong>abline()<\/strong> :<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #008080;\">#createdata\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (x=c(1, 2, 2, 3, 5, 6, 8, 8, 9, 9, 10, 11, 12, 15, 15),\n                 y=c(2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 16, 19, 28))\n\n<span style=\"color: #008080;\">#create scatterplot of x vs. y<\/span>\nplot(y~x, data=df)\n\n<span style=\"color: #008080;\">#add horizontal line at y=10\n<\/span>abline(a=10, b=0, lwd=2)\n<\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-20682 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lignes12.png\" alt=\"\" width=\"444\" height=\"407\" srcset=\"\" sizes=\"auto, \"><\/p>\n<p> <span style=\"color: #000000;\">Observe que n\u00e3o estamos recebendo um erro porque usamos primeiro a fun\u00e7\u00e3o <strong>plot()<\/strong> antes de usar a fun\u00e7\u00e3o <strong>abline()<\/strong> .<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Relacionado:<\/strong><\/span> <a href=\"https:\/\/statorials.org\/pt\/abline-em-r\/\" target=\"_blank\" rel=\"noopener\">Como usar aline() em R para adicionar linhas retas a caminhos<\/a><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Recursos adicionais<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Os tutoriais a seguir explicam como corrigir outros erros comuns no R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/pt\/r-constante-de-string-inesperada\/\" target=\"_blank\" rel=\"noopener\">Como corrigir em R: constante de string inesperada<\/a><br \/> Como corrigir em R: f\u00f3rmula de modelo inv\u00e1lida em ExtractVars<br \/> <a href=\"https:\/\/statorials.org\/pt\/o-argumento-r-nao-e-numerico-ou-logico\/\" target=\"_blank\" rel=\"noopener\">Como consertar em R: o argumento n\u00e3o \u00e9 num\u00e9rico nem l\u00f3gico: return na<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Um erro que voc\u00ea pode encontrar ao usar R \u00e9: Error in plot.xy(xy.coords(x, y), type = type, &#8230;): plot.new has not been called yet Este erro ocorre quando voc\u00ea tenta executar uma a\u00e7\u00e3o que exige que j\u00e1 exista um gr\u00e1fico em R, mas n\u00e3o existe nenhum gr\u00e1fico. Os exemplos a seguir mostram como corrigir esse [&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-2268","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 consertar em R: plot.new ainda n\u00e3o foi chamado - Statorials<\/title>\n<meta name=\"description\" content=\"Este tutorial explica como corrigir o seguinte erro em R: plot.new ainda n\u00e3o foi chamado.\" \/>\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\/r-plot-new-ainda-nao-foi-chamado\/\" \/>\n<meta property=\"og:locale\" content=\"pt_PT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Como consertar em R: plot.new ainda n\u00e3o foi chamado - Statorials\" \/>\n<meta property=\"og:description\" content=\"Este tutorial explica como corrigir o seguinte erro em R: plot.new ainda n\u00e3o foi chamado.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T00:20:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lignes11.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=\"3 minutos\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/\",\"url\":\"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/\",\"name\":\"Como consertar em R: plot.new ainda n\u00e3o foi chamado - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/pt\/#website\"},\"datePublished\":\"2023-07-23T00:20:55+00:00\",\"dateModified\":\"2023-07-23T00:20:55+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666\"},\"description\":\"Este tutorial explica como corrigir o seguinte erro em R: plot.new ainda n\u00e3o foi chamado.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/#breadcrumb\"},\"inLanguage\":\"pt-PT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Lar\",\"item\":\"https:\/\/statorials.org\/pt\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Como consertar em r: plot.new ainda n\u00e3o foi chamado\"}]},{\"@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 consertar em R: plot.new ainda n\u00e3o foi chamado - Statorials","description":"Este tutorial explica como corrigir o seguinte erro em R: plot.new ainda n\u00e3o foi chamado.","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\/r-plot-new-ainda-nao-foi-chamado\/","og_locale":"pt_PT","og_type":"article","og_title":"Como consertar em R: plot.new ainda n\u00e3o foi chamado - Statorials","og_description":"Este tutorial explica como corrigir o seguinte erro em R: plot.new ainda n\u00e3o foi chamado.","og_url":"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/","og_site_name":"Statorials","article_published_time":"2023-07-23T00:20:55+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/lignes11.png"}],"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\/r-plot-new-ainda-nao-foi-chamado\/","url":"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/","name":"Como consertar em R: plot.new ainda n\u00e3o foi chamado - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/pt\/#website"},"datePublished":"2023-07-23T00:20:55+00:00","dateModified":"2023-07-23T00:20:55+00:00","author":{"@id":"https:\/\/statorials.org\/pt\/#\/schema\/person\/e08f98e8db95e0aa9c310e1b27c9c666"},"description":"Este tutorial explica como corrigir o seguinte erro em R: plot.new ainda n\u00e3o foi chamado.","breadcrumb":{"@id":"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/#breadcrumb"},"inLanguage":"pt-PT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/pt\/r-plot-new-ainda-nao-foi-chamado\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Lar","item":"https:\/\/statorials.org\/pt\/"},{"@type":"ListItem","position":2,"name":"Como consertar em r: plot.new ainda n\u00e3o foi chamado"}]},{"@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\/2268","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=2268"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/posts\/2268\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/media?parent=2268"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/categories?post=2268"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/pt\/wp-json\/wp\/v2\/tags?post=2268"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}