{"id":3024,"date":"2023-07-19T14:30:32","date_gmt":"2023-07-19T14:30:32","guid":{"rendered":"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/"},"modified":"2023-07-19T14:30:32","modified_gmt":"2023-07-19T14:30:32","slug":"r-grafici-multipli-sullo-stesso-grafico","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/","title":{"rendered":"Come tracciare pi\u00f9 grafici sullo stesso grafico in r (3 esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare i seguenti metodi per disegnare pi\u00f9 grafici sullo stesso grafico in R:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Metodo 1: traccia pi\u00f9 linee sullo stesso grafico<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#plot first line<\/span>\nplot(x, y1, type=' <span style=\"color: #ff0000;\">l<\/span> ')\n\n<span style=\"color: #008080;\">#add second line to plot\n<\/span>lines(x, y2)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 2: crea pi\u00f9 percorsi affiancati<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define plotting area as one row and two columns\n<span style=\"color: #000000;\">by(mfrow = c(1, 2))\n<\/span>\n#create first plot\n<span style=\"color: #000000;\">plot(x, y1, type=' <span style=\"color: #ff0000;\">l<\/span> ')\n<\/span>\n#create second plot\n<span style=\"color: #000000;\">plot(x, y2, type=' <span style=\"color: #ff0000;\">l<\/span> ')\n<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Metodo 3: creare pi\u00f9 grafici impilati verticalmente<\/strong><\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define plotting area as two rows and one column\n<span style=\"color: #000000;\">by(mfrow = c(2, 1))<\/span>\n<span style=\"color: #000000;\">  \n<span style=\"color: #008080;\">#create first plot\n<\/span>plot(x, y1, type=' <span style=\"color: #ff0000;\">l<\/span> ')\n\n<span style=\"color: #008080;\">#create second plot\n<\/span>plot(x, y2, type=' <span style=\"color: #ff0000;\">l<\/span> ')<\/span><\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Gli esempi seguenti mostrano come utilizzare ciascun metodo nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: disegnare pi\u00f9 linee sullo stesso grafico<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come disegnare due linee sullo stesso grafico in R:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define data to plot\n<span style=\"color: #000000;\">x &lt;- 1:10\ny1 &lt;- c(2, 4, 4, 5, 7, 6, 5, 8, 12, 19)\ny2 &lt;- c(2, 2, 3, 4, 4, 6, 5, 9, 10, 13)\n\n<span style=\"color: #008080;\">#plot first line\n<\/span>plot(x, y1, type=' <span style=\"color: #ff0000;\">l<\/span> ', col=' <span style=\"color: #ff0000;\">red<\/span> ', xlab=' <span style=\"color: #ff0000;\">x<\/span> ', ylab=' <span style=\"color: #ff0000;\">y<\/span> ')\n\n<span style=\"color: #008080;\">#add second line to plot\n<\/span>lines(x, y2, col=' <span style=\"color: #ff0000;\">blue<\/span> ')\n<\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-26030\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/meme-graphique1.jpg\" alt=\"R traccia pi\u00f9 grafici nello stesso grafico\" width=\"445\" height=\"408\" srcset=\"\" sizes=\"\"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: creare pi\u00f9 percorsi affiancati<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare l&#8217;argomento <strong>par()<\/strong> per tracciare pi\u00f9 grafici affiancati:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define data to plot\n<span style=\"color: #000000;\">x &lt;- 1:10\ny1 &lt;- c(2, 4, 4, 5, 7, 6, 5, 8, 12, 19)\ny2 &lt;- c(2, 2, 3, 4, 4, 6, 5, 9, 10, 13)<\/span>\n\n#define plotting area as one row and two columns\n<span style=\"color: #000000;\">by(mfrow = c(1, 2))\n\n<span style=\"color: #008080;\">#create first line plot\n<\/span>plot(x, y1, type=' <span style=\"color: #ff0000;\">l<\/span> ', col=' <span style=\"color: #ff0000;\">red<\/span> ')\n\n<span style=\"color: #008080;\">#create second line plot<\/span>\nplot(x, y2, type=' <span style=\"color: #ff0000;\">l<\/span> ', col=' <span style=\"color: #ff0000;\">blue<\/span> ', ylim=c(min(y1), max(y1)))<\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-26031 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/meme-graphique2.jpg\" alt=\"\" width=\"442\" height=\"406\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che abbiamo utilizzato l&#8217;argomento <a href=\"https:\/\/statorials.org\/it\/xlim-ylim-nella-r\/\" target=\"_blank\" rel=\"noopener\">ylim()<\/a> nel secondo grafico per garantire che entrambi i grafici avessero gli stessi limiti sull&#8217;asse y.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 3: creare pi\u00f9 grafici impilati verticalmente<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare l&#8217;argomento <strong>par()<\/strong> per tracciare pi\u00f9 grafici impilati verticalmente:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define data to plot\n<span style=\"color: #000000;\">x &lt;- 1:10\ny1 &lt;- c(2, 4, 4, 5, 7, 6, 5, 8, 12, 19)\ny2 &lt;- c(2, 2, 3, 4, 4, 6, 5, 9, 10, 13)<\/span>\n\n#define plotting area as two rows and one column\n<span style=\"color: #000000;\">par(mfrow = c(2, 1), mar = c(2, 4, 4, 2))\n<span style=\"color: #008080;\">#create first line plot\n<\/span>plot(x, y1, type=' <span style=\"color: #ff0000;\">l<\/span> ', col=' <span style=\"color: #ff0000;\">red<\/span> ')\n\n<span style=\"color: #008080;\">#create second line plot\n<\/span>plot(x, y2, type=' <span style=\"color: #ff0000;\">l<\/span> ', col=' <span style=\"color: #ff0000;\">blue<\/span> ', ylim=c(min(y1), max(y1)))<\/span><\/span><\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-26032 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/meme-graphique3.jpg\" alt=\"\" width=\"458\" height=\"433\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Nota che abbiamo usato l&#8217;argomento <strong>mar<\/strong> per specificare i margini (in basso, a sinistra, in alto, a destra) dell&#8217;area del tracciato.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota:<\/strong> l&#8217;impostazione predefinita \u00e8 mar = c(5.1, 4.1, 4.1, 2.1)<\/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 attivit\u00e0 comuni in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/tracciare-piu-colonne-in-r\/\" target=\"_blank\" rel=\"noopener\">Come tracciare pi\u00f9 colonne in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/legenda-fuori-trama-r\/\" target=\"_blank\" rel=\"noopener\">Come disegnare una leggenda al di fuori di una trama in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/log-log-grafico-in-r\/\" target=\"_blank\" rel=\"noopener\">Come creare un grafico log-log in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare i seguenti metodi per disegnare pi\u00f9 grafici sullo stesso grafico in R: Metodo 1: traccia pi\u00f9 linee sullo stesso grafico #plot first line plot(x, y1, type=&#8217; l &#8216;) #add second line to plot lines(x, y2) Metodo 2: crea pi\u00f9 percorsi affiancati #define plotting area as one row and two columns by(mfrow = [&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 grafici sullo stesso grafico in R (3 esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come disegnare pi\u00f9 grafici sullo stesso 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\/r-grafici-multipli-sullo-stesso-grafico\/\" \/>\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 grafici sullo stesso grafico in R (3 esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come disegnare pi\u00f9 grafici sullo stesso grafico in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-19T14:30:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/meme-graphique1.jpg\" \/>\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\/r-grafici-multipli-sullo-stesso-grafico\/\",\"url\":\"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/\",\"name\":\"Come tracciare pi\u00f9 grafici sullo stesso grafico in R (3 esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-19T14:30:32+00:00\",\"dateModified\":\"2023-07-19T14:30:32+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come disegnare pi\u00f9 grafici sullo stesso grafico in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come tracciare pi\u00f9 grafici sullo stesso grafico in r (3 esempi)\"}]},{\"@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 grafici sullo stesso grafico in R (3 esempi) - Statorials","description":"Questo tutorial spiega come disegnare pi\u00f9 grafici sullo stesso 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\/r-grafici-multipli-sullo-stesso-grafico\/","og_locale":"it_IT","og_type":"article","og_title":"Come tracciare pi\u00f9 grafici sullo stesso grafico in R (3 esempi) - Statorials","og_description":"Questo tutorial spiega come disegnare pi\u00f9 grafici sullo stesso grafico in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/","og_site_name":"Statorials","article_published_time":"2023-07-19T14:30:32+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/meme-graphique1.jpg"}],"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\/r-grafici-multipli-sullo-stesso-grafico\/","url":"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/","name":"Come tracciare pi\u00f9 grafici sullo stesso grafico in R (3 esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-19T14:30:32+00:00","dateModified":"2023-07-19T14:30:32+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come disegnare pi\u00f9 grafici sullo stesso grafico in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/r-grafici-multipli-sullo-stesso-grafico\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come tracciare pi\u00f9 grafici sullo stesso grafico in r (3 esempi)"}]},{"@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\/3024"}],"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=3024"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3024\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}