{"id":1793,"date":"2023-07-24T23:21:26","date_gmt":"2023-07-24T23:21:26","guid":{"rendered":"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/"},"modified":"2023-07-24T23:21:26","modified_gmt":"2023-07-24T23:21:26","slug":"ruotare-le-etichette-degli-assi-ggplot2","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/","title":{"rendered":"Come ruotare le etichette degli assi in ggplot2 (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi per ruotare le etichette degli assi in un grafico ggplot2:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>p + theme(axis. <span style=\"color: #3366ff;\">text<\/span> . <span style=\"color: #3366ff;\">x<\/span> = element_text(angle = <span style=\"color: #008000;\">45<\/span> , vjust = <span style=\"color: #008000;\">1<\/span> , hjust= <span style=\"color: #008000;\">1<\/span> ))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\"><strong>Angle<\/strong> controlla l&#8217;angolo del testo mentre <strong>vjust<\/strong> e <strong>hjust<\/strong> controllano la giustificazione verticale e orizzontale del testo.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Il seguente esempio passo passo mostra come utilizzare questa sintassi nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Passaggio 1: creare il frame di dati<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Innanzitutto, creiamo un semplice frame di dati:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame\n<\/span>df = data. <span style=\"color: #3366ff;\">frame<\/span> (team=c('The Amazing Amazon Anteaters',\n                       'The Rowdy Racing Raccoons',\n                       'The Crazy Camping Cobras'),\n                dots=c(14, 22, 11))\n\n<span style=\"color: #008080;\">#view data frame<\/span>\ndf\n\n                          team points\n1 The Amazing Amazon Anteaters 14\n2 The Rowdy Racing Raccoons 22\n3 The Crazy Camping Cobras 11\n<\/strong><\/pre>\n<h3> <span style=\"color: #000000;\"><strong>Passaggio 2: creare un grafico a barre<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Successivamente, creiamo un grafico a barre per visualizzare i punti segnati da ciascuna squadra:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (ggplot2)<\/span>\n\n#create bar plot\n<\/span>ggplot(data=df, <span style=\"color: #3366ff;\">aes<\/span> (x=team, y=points)) +\n  geom_bar(stat=\" <span style=\"color: #ff0000;\">identity<\/span> \")<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-17453 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/faire-pivoter1-1.png\" alt=\"\" width=\"450\" height=\"451\" srcset=\"\" sizes=\"\"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Passaggio 3: ruotare le etichette dell&#8217;asse del grafico<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Possiamo usare il seguente codice per ruotare le etichette dell&#8217;asse x di 90 gradi:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (ggplot2)<\/span>\n\n#create bar plot with axis labels rotated 90 degrees\n<\/span>ggplot(data=df, <span style=\"color: #3366ff;\">aes<\/span> (x=team, y=points)) +\n  geom_bar(stat=\" <span style=\"color: #ff0000;\">identity<\/span> \") +\n  theme(axis. <span style=\"color: #3366ff;\">text<\/span> . <span style=\"color: #3366ff;\">x<\/span> = element_text(angle= <span style=\"color: #008000;\">90<\/span> , vjust= <span style=\"color: #008000;\">.5<\/span> , hjust= <span style=\"color: #008000;\">1<\/span> ))<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-17455 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/rotation2.png\" alt=\"\" width=\"472\" height=\"470\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Oppure possiamo usare il seguente codice per ruotare le etichette dell&#8217;asse X di 45 gradi:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\"><span style=\"color: #000000;\"><span style=\"color: #993300;\">library<\/span> (ggplot2)<\/span>\n\n#create bar plot with axis labels rotated 90 degrees\n<\/span>ggplot(data=df, <span style=\"color: #3366ff;\">aes<\/span> (x=team, y=points)) +\n  geom_bar(stat=\" <span style=\"color: #ff0000;\">identity<\/span> \") +\n  theme(axis. <span style=\"color: #3366ff;\">text<\/span> . <span style=\"color: #3366ff;\">x<\/span> = element_text(angle= <span style=\"color: #008000;\">45<\/span> , vjust= <span style=\"color: #008000;\">1<\/span> , hjust= <span style=\"color: #008000;\">1<\/span> ))<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-17456 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/rotation3.png\" alt=\"\" width=\"477\" height=\"466\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">A seconda <strong>dell&#8217;angolo<\/strong> con cui si ruotano le etichette, potrebbe essere necessario regolare i valori <strong>vjust<\/strong> e <strong>hjust<\/strong> per garantire che le etichette siano sufficientemente vicine al percorso.<\/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\/imposta-i-limiti-dellasse-ggplot2\/\" target=\"_blank\" rel=\"noopener\">Come impostare i limiti degli assi in ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/asse-inverso-ggplot\/\">Come invertire l&#8217;ordine degli assi in ggplot2<\/a><br \/> Come rimuovere la griglia in ggplot2<br \/> <a href=\"https:\/\/statorials.org\/it\/spessore-della-linea-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come regolare lo spessore della linea in ggplot2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi per ruotare le etichette degli assi in un grafico ggplot2: p + theme(axis. text . x = element_text(angle = 45 , vjust = 1 , hjust= 1 )) Angle controlla l&#8217;angolo del testo mentre vjust e hjust controllano la giustificazione verticale e orizzontale del testo. Il seguente esempio passo [&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 ruotare le etichette degli assi in ggplot2 (con esempi)<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come ruotare le etichette degli assi di un grafico in ggplot2, 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\/ruotare-le-etichette-degli-assi-ggplot2\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come ruotare le etichette degli assi in ggplot2 (con esempi)\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come ruotare le etichette degli assi di un grafico in ggplot2, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-24T23:21:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/faire-pivoter1-1.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\/ruotare-le-etichette-degli-assi-ggplot2\/\",\"url\":\"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/\",\"name\":\"Come ruotare le etichette degli assi in ggplot2 (con esempi)\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-24T23:21:26+00:00\",\"dateModified\":\"2023-07-24T23:21:26+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come ruotare le etichette degli assi di un grafico in ggplot2, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come ruotare le etichette degli assi in ggplot2 (con 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 ruotare le etichette degli assi in ggplot2 (con esempi)","description":"Questo tutorial spiega come ruotare le etichette degli assi di un grafico in ggplot2, 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\/ruotare-le-etichette-degli-assi-ggplot2\/","og_locale":"it_IT","og_type":"article","og_title":"Come ruotare le etichette degli assi in ggplot2 (con esempi)","og_description":"Questo tutorial spiega come ruotare le etichette degli assi di un grafico in ggplot2, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/","og_site_name":"Statorials","article_published_time":"2023-07-24T23:21:26+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/faire-pivoter1-1.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\/ruotare-le-etichette-degli-assi-ggplot2\/","url":"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/","name":"Come ruotare le etichette degli assi in ggplot2 (con esempi)","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-24T23:21:26+00:00","dateModified":"2023-07-24T23:21:26+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come ruotare le etichette degli assi di un grafico in ggplot2, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/ruotare-le-etichette-degli-assi-ggplot2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come ruotare le etichette degli assi in ggplot2 (con 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\/1793"}],"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=1793"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/1793\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=1793"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=1793"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=1793"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}