{"id":458,"date":"2023-07-29T20:27:57","date_gmt":"2023-07-29T20:27:57","guid":{"rendered":"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/"},"modified":"2023-07-29T20:27:57","modified_gmt":"2023-07-29T20:27:57","slug":"come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/","title":{"rendered":"Come tracciare pi\u00f9 linee (serie di dati) in un singolo grafico in r"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Questo tutorial spiega come tracciare pi\u00f9 linee (ovvero serie di dati) in un singolo grafico in R.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Per tracciare pi\u00f9 linee in un grafico, possiamo utilizzare la base R o installare un pacchetto pi\u00f9 sofisticato come ggplot2.<\/span><\/p>\n<h2> <strong>Utilizzando BaseR<\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Ecco due esempi di come tracciare pi\u00f9 linee in un singolo grafico utilizzando Base R.<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Esempio 1: utilizzo di Matplot<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Se disponi di un set di dati <a href=\"https:\/\/en.wikipedia.org\/wiki\/Wide_and_narrow_data#Wide\" target=\"_blank\" rel=\"noopener\">di grande formato<\/a> , un modo semplice per tracciare pi\u00f9 linee in un grafico \u00e8 utilizzare matplot:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#Create a fake dataset with 3 columns (ncol=3) composed of randomly generated\n#numbers from a uniform distribution with minimum = 1 and maximum = 10\n<\/span>data &lt;- matrix(runif(30,1,10), ncol=3)\ndata\n        [,1] [,2] [,3]\n#[1,] 5.371653 3.490919 3.953603\n#[2,] 9.551883 2.681054 9.506765\n#[3,] 3.525686 1.027758 8.059011\n#[4,] 9.923080 1.337935 1.112361\n#[5,] 7.273972 7.627546 1.174340\n#[6,] 8.859109 3.778144 9.384526\n#[7,] 9.614542 3.866029 7.301729\n#[8,] 9.288085 5.804041 8.347907\n#[9,] 1.696849 4.650687 7.220209\n#[10,] 5.820941 4.799682 5.243663\n\n<span style=\"color: #008080;\">#plot the three columns of the dataset as three lines and add a legend in<\/span>\n<span style=\"color: #008080;\">#the top right corner of the chart<\/span>\nmatplot(data, type = \"b\",pch=1,col = 1:3)\nlegend(\"topright\", legend = 1:3, col=1:3, pch=1)\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo codice genera il seguente grafico:<\/span><\/p>\n<h3> <strong><span style=\"color: #000000;\">Esempio 2: utilizzo di punti e linee<\/span><\/strong><\/h3>\n<p> <span style=\"color: #000000;\">Un altro modo per disegnare pi\u00f9 linee \u00e8 disegnarle una alla volta, utilizzando le funzioni integrate di R points() e lines(). Il codice seguente mostra un esempio di questo approccio:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#generate an x-axis along with three data series\n<\/span>x &lt;- c(1,2,3,4,5,6)\ny1 &lt;- c(2,4,7,9,12,19)\ny2 &lt;- c(1,5,9,8,9,13)\ny3 &lt;- c(3,6,12,14,17,15)\n<\/strong>\n<strong><span style=\"color: #008080;\">#plot the first data series using plot()<\/span>\nplot(x, y1, type=\"o\", col=\"blue\", pch=\"o\", ylab=\"y\", lty=1)\n\n<span style=\"color: #008080;\">#add second data series to the same chart using points() and lines()\n<\/span>points(x, y2, col=\"red\", pch=\"*\")\nlines(x, y2, col=\"red\",lty=2)\n\n<span style=\"color: #008080;\">#add third data series to the same chart using points() and lines()<\/span>\npoints(x, y3, col=\"dark red\",pch=\"+\")\nlines(x, y3, col=\"dark red\", lty=3)\n\n<span style=\"color: #008080;\">#add a legend in top left corner of chart at (x, y) coordinates = (1, 19)\n<\/span>legend(1,19,legend=c(\"y1\",\"y2\",\"y3\"), col=c(\"blue\",\"red\",\"black\"),\n                                   pch=c(\"o\",\"*\",\"+\"),lty=c(1,2,3), ncol=1)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo codice genera il seguente grafico:<\/span><\/p>\n<h2> <strong>Utilizzando ggplot2<\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Ecco un esempio di come tracciare pi\u00f9 linee in un singolo grafico utilizzando ggplot2.<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#install (if not already installed) and load ggplot2 package<\/span>\nif(!require(ggplot2)){install.packages(' <span style=\"color: #ff0000;\">ggplot2<\/span> ')}\n\n<span style=\"color: #008080;\">#generate fake dataset with three columns 'x', 'value', and 'variable'<\/span>\ndata &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (x=rep(1:5, 3),\n                   value=sample(1:100, 15), \n                   variable=rep(paste0(' <span style=\"color: #ff0000;\">series<\/span> ', 1:3), each=5))\n\n<span style=\"color: #008080;\">#view dataset\n<\/span>head(data)\n  x value variable\n1 1 93 series1\n2 2 64 series1\n3 3 36 series1\n4 4 17 series1\n5 5 95 series1\n6 1 80 series2\n\n<span style=\"color: #008080;\">#plot all three series on the same chart using geom_line()<\/span>\nggplot(data = data, aes(x=x, y=value)) + geom_line(aes(color=variable))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo genera il seguente grafico:<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre operazioni di stampa comuni in ggplot2:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/posizione-della-legenda-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come cambiare la posizione della legenda in ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/cambia-il-titolo-della-legenda-ggplot2\/\" target=\"_blank\" rel=\"noopener\">Come cambiare il titolo della legenda in ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/margini-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come modificare i margini in ggplot2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Questo tutorial spiega come tracciare pi\u00f9 linee (ovvero serie di dati) in un singolo grafico in R. Per tracciare pi\u00f9 linee in un grafico, possiamo utilizzare la base R o installare un pacchetto pi\u00f9 sofisticato come ggplot2. Utilizzando BaseR Ecco due esempi di come tracciare pi\u00f9 linee in un singolo grafico utilizzando Base R. Esempio [&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":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Come tracciare pi\u00f9 linee (serie di dati) in un singolo grafico in R - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come disegnare pi\u00f9 linee in un grafico in R, con diversi esempi.\" \/>\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\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come tracciare pi\u00f9 linee (serie di dati) in un singolo grafico in R - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come disegnare pi\u00f9 linee in un grafico in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-29T20:27:57+00:00\" \/>\n<meta name=\"author\" content=\"Benjamin anderson\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Benjamin anderson\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/\",\"url\":\"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/\",\"name\":\"Come tracciare pi\u00f9 linee (serie di dati) in un singolo grafico in R - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-29T20:27:57+00:00\",\"dateModified\":\"2023-07-29T20:27:57+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come disegnare pi\u00f9 linee in un grafico in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come tracciare pi\u00f9 linee (serie di dati) in un singolo grafico in r\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/statorials.org\/it\/#website\",\"url\":\"https:\/\/statorials.org\/it\/\",\"name\":\"Statorials\",\"description\":\"La tua guida all&#039;alfabetizzazione statistica!\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/statorials.org\/it\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"it-IT\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\",\"name\":\"Benjamin anderson\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"it-IT\",\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"contentUrl\":\"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg\",\"caption\":\"Benjamin anderson\"},\"description\":\"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9\",\"sameAs\":[\"https:\/\/statorials.org\/it\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Come tracciare pi\u00f9 linee (serie di dati) in un singolo grafico in R - Statorials","description":"Questo tutorial spiega come disegnare pi\u00f9 linee in un grafico in R, con diversi esempi.","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\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come tracciare pi\u00f9 linee (serie di dati) in un singolo grafico in R - Statorials","og_description":"Questo tutorial spiega come disegnare pi\u00f9 linee in un grafico in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-29T20:27:57+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"2 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/","url":"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/","name":"Come tracciare pi\u00f9 linee (serie di dati) in un singolo grafico in R - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-29T20:27:57+00:00","dateModified":"2023-07-29T20:27:57+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come disegnare pi\u00f9 linee in un grafico in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come tracciare pi\u00f9 linee (serie di dati) in un singolo grafico in r"}]},{"@type":"WebSite","@id":"https:\/\/statorials.org\/it\/#website","url":"https:\/\/statorials.org\/it\/","name":"Statorials","description":"La tua guida all&#039;alfabetizzazione statistica!","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/statorials.org\/it\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"it-IT"},{"@type":"Person","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae","name":"Benjamin anderson","image":{"@type":"ImageObject","inLanguage":"it-IT","@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/image\/","url":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","contentUrl":"https:\/\/statorials.org\/it\/wp-content\/uploads\/2023\/10\/Dr.-Benjamin-Anderson-96x96.jpg","caption":"Benjamin anderson"},"description":"Ciao, sono Benjamin, un professore di statistica in pensione diventato insegnante dedicato di Statorials. Con una vasta esperienza e competenza nel campo della statistica, sono ansioso di condividere le mie conoscenze per potenziare gli studenti attraverso Statorials. Scopri di pi\u00f9","sameAs":["https:\/\/statorials.org\/it"]}]}},"yoast_meta":{"yoast_wpseo_title":"","yoast_wpseo_metadesc":"","yoast_wpseo_canonical":""},"_links":{"self":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/458"}],"collection":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/comments?post=458"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/458\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=458"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=458"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=458"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}