{"id":961,"date":"2023-07-28T04:27:57","date_gmt":"2023-07-28T04:27:57","guid":{"rendered":"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/"},"modified":"2023-07-28T04:27:57","modified_gmt":"2023-07-28T04:27:57","slug":"grafici-affiancati-ggplot2","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/","title":{"rendered":"Come creare grafici affiancati in ggplot2"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Spesso potresti voler creare due grafici affiancati utilizzando il pacchetto <a href=\"https:\/\/ggplot2.tidyverse.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">ggplot2<\/a> in R. Fortunatamente, questo \u00e8 facile da fare con l&#8217;aiuto del pacchetto <a href=\"https:\/\/github.com\/thomasp85\/patchwork\" target=\"_blank\" rel=\"noopener noreferrer\">patchwork<\/a> .<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#install ggplot2 and patchwork packages<\/span>\ninstall.packages(' <span style=\"color: #008000;\">ggplot2<\/span> ')\ninstall.packages(' <span style=\"color: #008000;\">patchwork<\/span> ')\n\n<span style=\"color: #008080;\">#load the packages<\/span> \nlibrary(ggplot2)\nlibrary(patchwork)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo tutorial mostra diversi esempi di utilizzo di questi pacchetti per creare grafici affiancati.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: due appezzamenti affiancati<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come creare due grafici affiancati utilizzando il set di dati <strong>iris<\/strong> integrato di R:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create box plot<\/span>\nplot1 &lt;- ggplot(iris, aes(x = Species, y = Sepal.Length)) +\n  geom_boxplot()\n\n<span style=\"color: #008080;\">#create density plot<\/span>\nplot2 &lt;- ggplot(iris, aes(x = Sepal.Length, fill = Species)) +\n  geom_density(alpha = 0.8)\n\n<span style=\"color: #008080;\">#display plots side by side\n<\/span>plot1 + plot2 \n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10085 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/sidebysideggplot1.png\" alt=\"Grafici affiancati in ggplot2 in R\" width=\"668\" height=\"335\" srcset=\"\" sizes=\"\"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: tre appezzamenti affiancati<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come creare tre grafici affiancati utilizzando il set di dati <strong>iris<\/strong> integrato di R:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create box plot<\/span>\nplot1 &lt;- ggplot(iris, aes(x = Species, y = Sepal.Length)) +\n  geom_boxplot()\n\n<span style=\"color: #008080;\">#create density plot<\/span>\nplot2 &lt;- ggplot(iris, aes(x = Sepal.Length, fill = Species)) +\n  geom_density(alpha = 0.7)\n\n<span style=\"color: #008080;\">#create scatterplot<\/span> \nplot3 &lt;- ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) +\n  geom_point()\n\n<span style=\"color: #008080;\">#display three plots side by side\n<\/span>plot1 + plot2 + plot3\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10086 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/sidebysideggplot2.png\" alt=\"Tre trame affiancate in ggplot2\" width=\"677\" height=\"342\" srcset=\"\" sizes=\"\"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 3: due lotti sovrapposti<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come creare due grafici in pila, uno sopra l&#8217;altro:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create box plot<\/span>\nplot1 &lt;- ggplot(iris, aes(x = Species, y = Sepal.Length)) +\n  geom_boxplot()\n\n<span style=\"color: #008080;\">#create density plot<\/span>\nplot2 &lt;- ggplot(iris, aes(x = Sepal.Length, fill = Species)) +\n  geom_density(alpha = 0.7)\n\n<span style=\"color: #008080;\">#display plots stacked on top of each other\n<\/span>plot1 \/ plot2<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10088 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/sidebysideggplot3.png\" alt=\"Due grafici impilati in ggplot2\" width=\"444\" height=\"316\" srcset=\"\" sizes=\"\"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 4: aggiungere titoli, sottotitoli e didascalie<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come aggiungere titoli, sottotitoli e didascalie alle trame:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create box plot<\/span>\nplot1 &lt;- ggplot(iris, aes(x = Species, y = Sepal.Length)) +\n  geom_boxplot() +\n  ggtitle('Boxplot')\n\n<span style=\"color: #008080;\">#create density plot<\/span>\nplot2 &lt;- ggplot(iris, aes(x = Sepal.Length, fill = Species)) +\n  geom_density(alpha = 0.7) +\n  ggtitle('Density Plot')\n\n<span style=\"color: #008080;\">#display plots side by side with title, subtitle, and captions\n<\/span>patchwork &lt;- plot1 + plot2 \n\npatchwork + plot_annotation(\n  title = ' <span style=\"color: #008000;\">This is a title<\/span> ',\n  subtitle = ' <span style=\"color: #008000;\">This is a subtitle that describes more information about the plots<\/span> ',\n  caption = ' <span style=\"color: #008000;\">This is a caption<\/span> '\n)\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-10090 \" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/sidebysideggplot4-1.png\" alt=\"Trame affiancate in ggplot2 con titoli e sottotitoli\" width=\"672\" height=\"337\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\"><em>Puoi trovare altri tutorial su R qui .<\/em><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Spesso potresti voler creare due grafici affiancati utilizzando il pacchetto ggplot2 in R. Fortunatamente, questo \u00e8 facile da fare con l&#8217;aiuto del pacchetto patchwork . #install ggplot2 and patchwork packages install.packages(&#8216; ggplot2 &#8216;) install.packages(&#8216; patchwork &#8216;) #load the packages library(ggplot2) library(patchwork) Questo tutorial mostra diversi esempi di utilizzo di questi pacchetti per creare grafici affiancati. [&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 creare grafici affiancati in ggplot2 - Statorials<\/title>\n<meta name=\"description\" content=\"Una semplice spiegazione di come creare grafici affiancati in ggplot2, inclusi 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\/grafici-affiancati-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come creare grafici affiancati in ggplot2 - Statorials\" \/>\n<meta property=\"og:description\" content=\"Una semplice spiegazione di come creare grafici affiancati in ggplot2, inclusi diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-28T04:27:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/sidebysideggplot1.png\" \/>\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\/grafici-affiancati-ggplot2\/\",\"url\":\"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/\",\"name\":\"Come creare grafici affiancati in ggplot2 - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-28T04:27:57+00:00\",\"dateModified\":\"2023-07-28T04:27:57+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Una semplice spiegazione di come creare grafici affiancati in ggplot2, inclusi diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come creare grafici affiancati in ggplot2\"}]},{\"@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 creare grafici affiancati in ggplot2 - Statorials","description":"Una semplice spiegazione di come creare grafici affiancati in ggplot2, inclusi 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\/grafici-affiancati-ggplot2\/","og_locale":"it_IT","og_type":"article","og_title":"Come creare grafici affiancati in ggplot2 - Statorials","og_description":"Una semplice spiegazione di come creare grafici affiancati in ggplot2, inclusi diversi esempi.","og_url":"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/","og_site_name":"Statorials","article_published_time":"2023-07-28T04:27:57+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/sidebysideggplot1.png"}],"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\/grafici-affiancati-ggplot2\/","url":"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/","name":"Come creare grafici affiancati in ggplot2 - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-28T04:27:57+00:00","dateModified":"2023-07-28T04:27:57+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Una semplice spiegazione di come creare grafici affiancati in ggplot2, inclusi diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/grafici-affiancati-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come creare grafici affiancati in ggplot2"}]},{"@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\/961"}],"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=961"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/961\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=961"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=961"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=961"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}