{"id":22379,"date":"2015-08-07T01:17:18","date_gmt":"2015-08-07T01:17:18","guid":{"rendered":"http:\/\/www.inacreditavel.pt\/?p=22379"},"modified":"2015-08-07T01:17:18","modified_gmt":"2015-08-07T01:17:18","slug":"graficos-no-r","status":"publish","type":"post","link":"http:\/\/www.inacreditavel.pt\/?p=22379","title":{"rendered":"Gr\u00e1ficos no R"},"content":{"rendered":"<p>Para fazer gr\u00e1ficos no <a href=\"https:\/\/www.r-project.org\/\">R<\/a>, estou a usar o pacote <a href=\"http:\/\/ggplot2.org\">ggplot2<\/a>.<\/p>\n<p>Para isso, tive que instalar o pacote. Dentro do R, em consola, executei o comando:<\/p>\n<pre style=\"border: 2px solid black; border-radius: 5px; box-shadow: 5px 5px 5px grey; background-color: lightyellow; margin: 10px; padding: 8px; font-family: monospace;\">\r\ninstall.packages(\"ggplot2\")\r\n<\/pre>\n<p>Abri o ficheiro de dados e carreguei o pacote gr\u00e1fico:<\/p>\n<pre style=\"border: 2px solid black; border-radius: 5px; box-shadow: 5px 5px 5px grey; background-color: lightyellow; margin: 10px; padding: 8px; font-family: monospace;\">\r\nX<-read.table('\/tmp\/dados.txt',header=T)\r\nattach(X)\r\nlibrary(ggplot2)\r\n<\/pre>\n<p>O ficheiro de dados tem tr\u00eas vari\u00e1veis inteiras, com o aspeto seguinte<\/p>\n<pre style=\"border: 2px solid black; border-radius: 5px; box-shadow: 5px 5px 5px grey; background-color: lightyellow; margin: 10px; padding: 8px; font-family: monospace;\">\r\nv1      v3      v2\r\n11      43      2\r\n16      44      4\r\n16      43      1\r\n...    ...    ...\r\n13      45      1\r\n14      31      1\r\n18      28      2\r\n18      34      2\r\n13      45      1\r\n<\/pre>\n<p>Depois, criei um histograma e uma caixa de bigodes, com os comandos seguintes:<\/p>\n<pre style=\"border: 2px solid black; border-radius: 5px; box-shadow: 5px 5px 5px grey; background-color: lightyellow; margin: 10px; padding: 8px; font-family: monospace;\">\r\nvv<-factor(v2)\r\ntemp.g8<-qplot(vv, geom=\"histogram\", fill=vv, xlab=\"vari\u00e1vel\", ylab=\"contagem\")\r\nggsave('example8.png', temp.g8)\r\n\r\ntemp.g9<-qplot(vv, v1, geom=\"boxplot\", fill=vv, xlab=\"fator\", ylab=\"caixas de bigodes\")\r\nggsave('example9.png', temp.g9)\r\n<\/pre>\n<p>O resultado foram as figuras abaixo:<\/p>\n<p><a href=\"http:\/\/www.inacreditavel.pt\/wp-content\/uploads\/sites\/17\/2015\/08\/example7.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.inacreditavel.pt\/wp-content\/uploads\/sites\/17\/2015\/08\/example7-1024x1024.png\" alt=\"example7\" width=\"604\" height=\"604\" class=\"aligncenter size-large wp-image-22380\" srcset=\"http:\/\/www.inacreditavel.pt\/wp-content\/uploads\/sites\/17\/2015\/08\/example7-1024x1024.png 1024w, http:\/\/www.inacreditavel.pt\/wp-content\/uploads\/sites\/17\/2015\/08\/example7-150x150.png 150w, http:\/\/www.inacreditavel.pt\/wp-content\/uploads\/sites\/17\/2015\/08\/example7-300x300.png 300w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/www.inacreditavel.pt\/wp-content\/uploads\/sites\/17\/2015\/08\/example9.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.inacreditavel.pt\/wp-content\/uploads\/sites\/17\/2015\/08\/example9-1024x1024.png\" alt=\"example9\" width=\"604\" height=\"604\" class=\"aligncenter size-large wp-image-22381\" srcset=\"http:\/\/www.inacreditavel.pt\/wp-content\/uploads\/sites\/17\/2015\/08\/example9-1024x1024.png 1024w, http:\/\/www.inacreditavel.pt\/wp-content\/uploads\/sites\/17\/2015\/08\/example9-150x150.png 150w, http:\/\/www.inacreditavel.pt\/wp-content\/uploads\/sites\/17\/2015\/08\/example9-300x300.png 300w\" sizes=\"(max-width: 604px) 100vw, 604px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Para fazer gr\u00e1ficos no R, estou a usar o pacote ggplot2. Para isso, tive que instalar o pacote. Dentro do R, em consola, executei o comando: install.packages(&#8220;ggplot2&#8221;) Abri o ficheiro de dados e carreguei o pacote gr\u00e1fico: X<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.inacreditavel.pt\/index.php?rest_route=\/wp\/v2\/posts\/22379"}],"collection":[{"href":"http:\/\/www.inacreditavel.pt\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.inacreditavel.pt\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.inacreditavel.pt\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.inacreditavel.pt\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=22379"}],"version-history":[{"count":1,"href":"http:\/\/www.inacreditavel.pt\/index.php?rest_route=\/wp\/v2\/posts\/22379\/revisions"}],"predecessor-version":[{"id":22382,"href":"http:\/\/www.inacreditavel.pt\/index.php?rest_route=\/wp\/v2\/posts\/22379\/revisions\/22382"}],"wp:attachment":[{"href":"http:\/\/www.inacreditavel.pt\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=22379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.inacreditavel.pt\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=22379"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.inacreditavel.pt\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=22379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}