{"id":3557,"date":"2023-07-16T20:50:00","date_gmt":"2023-07-16T20:50:00","guid":{"rendered":"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/"},"modified":"2023-07-16T20:50:00","modified_gmt":"2023-07-16T20:50:00","slug":"etichette-degli-assi-sfaccettati-ggplot","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/","title":{"rendered":"Come modificare le etichette degli assi delle faccette in ggplot2"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Puoi utilizzare la funzione <strong>as_labeller()<\/strong> per modificare le etichette degli assi delle faccette in ggplot2:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #000000;\">ggplot(df, aes(x, y)) + \n  geom_point() +\n  facet_wrap(.~group,\n             strip. <span style=\"color: #3366ff;\">position<\/span> = ' <span style=\"color: #ff0000;\">left<\/span> ', \n             labeller = as_labeller(c(A=' <span style=\"color: #ff0000;\">new1<\/span> ', B=' <span style=\"color: #ff0000;\">new2<\/span> ', C=' <span style=\"color: #ff0000;\">new3<\/span> ', D=' <span style=\"color: #ff0000;\">new4<\/span> '))) +\n  ylab(NULL) +\n  theme(strip. <span style=\"color: #3366ff;\">background<\/span> = element_blank(),\n        strip. <span style=\"color: #3366ff;\">placement<\/span> ='outside')\n<\/span><\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo particolare esempio sostituisce le seguenti vecchie etichette:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">ABCD<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">con le seguenti nuove etichette:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\">nuovo1, nuovo2, nuovo3, nuovo4<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare questa sintassi nella pratica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Esempio: modifica le etichette degli assi sfaccettati in ggplot2<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente frame di dati in R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#create data frame<\/span>\ndf &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('A', 'A', 'B', 'B', 'C', 'C', 'D', 'D'),\n                 points=c(8, 14, 20, 22, 25, 29, 30, 31),\n                 assists=c(10, 5, 5, 3, 8, 6, 9, 12))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n  team points assists\n1 to 8 10\n2 to 14 5\n3 B 20 5\n4 B 22 3\n5 C 25 8\n6 C 29 6\n7 D 30 9\n8 D 31 12<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare <strong>facet_wrap()<\/strong> per creare una griglia che visualizzi un grafico a dispersione degli assist rispetto ai punti per ciascuna squadra:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (ggplot2)\n\n<span style=\"color: #008080;\">#create multiple scatter plots using facet_wrap\n<\/span>ggplot(df, <span style=\"color: #3366ff;\">aes<\/span> (assists, points)) +\n  geom_point() +\n  facet_wrap(.~team, nrow= <span style=\"color: #008000;\">4<\/span> )\n<\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-29435 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/facette11.jpg\" alt=\"\" width=\"595\" height=\"472\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Attualmente, le faccette hanno le seguenti etichette: A, B, C, D.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Tuttavia, possiamo utilizzare il seguente codice per modificare le etichette in Squadra A, Squadra B, Squadra C e Squadra D:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #993300;\"><span style=\"color: #000000;\"><span style=\"color: #008000;\">library<\/span> (ggplot2)\n\n<span style=\"color: #008080;\">#create multiple scatter plots using facet_wrap with custom facet labels<\/span>\nggplot(df, aes(assists, points)) + \n  geom_point() +\n  facet_wrap(.~team, nrow= <span style=\"color: #008000;\">4<\/span> ,\n             strip. <span style=\"color: #3366ff;\">position<\/span> = ' <span style=\"color: #ff0000;\">left<\/span> ', \n             labeller = as_labeller(c(A=' <span style=\"color: #ff0000;\">team A<\/span> ',\n                                      B=' <span style=\"color: #ff0000;\">team B<\/span> ',\n                                      C=' <span style=\"color: #ff0000;\">team C<\/span> ',\n                                      D=' <span style=\"color: #ff0000;\">team D<\/span> '))) +\n  ylab(NULL) +\n  theme(strip. <span style=\"color: #3366ff;\">background<\/span> = element_blank(),\n        strip. <span style=\"color: #3366ff;\">placement<\/span> = ' <span style=\"color: #ff0000;\">outside<\/span> ')\n<\/span><\/span><\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-29436\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/facette12.jpg\" alt=\"ggplot2 cambia le etichette degli assi delle faccette\" width=\"559\" height=\"448\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che le etichette delle sfaccettature sono state modificate in Squadra A, Squadra B, Squadra C e Squadra D e sono state spostate sul lato sinistro del grafico.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : l&#8217;argomento <strong>strip. background<\/strong> rimuove lo sfondo grigio dietro le etichette delle faccette e l&#8217;argomento <strong>strip.placement<\/strong> specifica che le etichette devono essere posizionate all&#8217;esterno dei segni di graduazione dell&#8217;asse.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come eseguire altre attivit\u00e0 comuni in ggplot2:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/ordine-delle-sfaccettature-di-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come cambiare l&#8217;ordine delle sfaccettature in ggplot2<\/a><br \/><a href=\"https:\/\/statorials.org\/it\/dimensione-del-carattere-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come cambiare la dimensione del carattere in ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/\" target=\"_blank\" rel=\"noopener\">Come ruotare le etichette degli assi in ggplot2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Puoi utilizzare la funzione as_labeller() per modificare le etichette degli assi delle faccette in ggplot2: ggplot(df, aes(x, y)) + geom_point() + facet_wrap(.~group, strip. position = &#8216; left &#8216;, labeller = as_labeller(c(A=&#8217; new1 &#8216;, B=&#8217; new2 &#8216;, C=&#8217; new3 &#8216;, D=&#8217; new4 &#8216;))) + ylab(NULL) + theme(strip. background = element_blank(), strip. placement =&#8217;outside&#8217;) Questo particolare 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 modificare le etichette degli assi delle faccette in ggplot2 - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come modificare le etichette degli assi delle faccette in ggplot2, con un esempio.\" \/>\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\/etichette-degli-assi-sfaccettati-ggplot\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come modificare le etichette degli assi delle faccette in ggplot2 - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come modificare le etichette degli assi delle faccette in ggplot2, con un esempio.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-16T20:50:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/facette11.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\/etichette-degli-assi-sfaccettati-ggplot\/\",\"url\":\"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/\",\"name\":\"Come modificare le etichette degli assi delle faccette in ggplot2 - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-16T20:50:00+00:00\",\"dateModified\":\"2023-07-16T20:50:00+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come modificare le etichette degli assi delle faccette in ggplot2, con un esempio.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come modificare le etichette degli assi delle faccette 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 modificare le etichette degli assi delle faccette in ggplot2 - Statorials","description":"Questo tutorial spiega come modificare le etichette degli assi delle faccette in ggplot2, con un esempio.","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\/etichette-degli-assi-sfaccettati-ggplot\/","og_locale":"it_IT","og_type":"article","og_title":"Come modificare le etichette degli assi delle faccette in ggplot2 - Statorials","og_description":"Questo tutorial spiega come modificare le etichette degli assi delle faccette in ggplot2, con un esempio.","og_url":"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/","og_site_name":"Statorials","article_published_time":"2023-07-16T20:50:00+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/facette11.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\/etichette-degli-assi-sfaccettati-ggplot\/","url":"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/","name":"Come modificare le etichette degli assi delle faccette in ggplot2 - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-16T20:50:00+00:00","dateModified":"2023-07-16T20:50:00+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come modificare le etichette degli assi delle faccette in ggplot2, con un esempio.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/etichette-degli-assi-sfaccettati-ggplot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come modificare le etichette degli assi delle faccette 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\/3557"}],"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=3557"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3557\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3557"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3557"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3557"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}