{"id":3215,"date":"2023-07-18T15:48:27","date_gmt":"2023-07-18T15:48:27","guid":{"rendered":"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/"},"modified":"2023-07-18T15:48:27","modified_gmt":"2023-07-18T15:48:27","slug":"ggplot-annota-la-rotazione-del-testo","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/","title":{"rendered":"Come ruotare il testo annotato in ggplot2 (con esempio)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi di base per ruotare il testo annotato nei grafici ggplot2:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>ggplot(df) +\n  geom_point(aes(x=x, y=y)) + \n  geom_text(aes(x=x, y=y, label=group), hjust= <span style=\"color: #008000;\">-0.3<\/span> , vjust= <span style=\"color: #008000;\">-0.1<\/span> , angle= <span style=\"color: #008000;\">45<\/span> )<\/strong>\n<\/pre>\n<p> <span style=\"color: #000000;\">In questo esempio particolare, utilizziamo l&#8217;argomento <strong>angolo<\/strong> per ruotare il testo annotato di 45 gradi in senso antiorario e gli argomenti <strong>hjust<\/strong> e <strong>vjust<\/strong> per aumentare la distanza orizzontale e verticale del testo dai punti sulla traccia.<\/span><\/p>\n<p> <span style=\"color: #000000;\">L&#8217;esempio seguente mostra come utilizzare questa sintassi nella pratica.<\/span><\/p>\n<h2> <strong><span style=\"color: #000000;\">Esempio: ruotare il testo annotato in ggplot2<\/span><\/strong><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente set di dati in R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (player=c('Brad', 'Ty', 'Spencer', 'Luke', 'Max'),\n                 dots=c(17, 5, 12, 20, 22),\n                 assists=c(4, 3, 7, 7, 5))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n   player points assists\n1 Brad 17 4\n2 Ty 5 3\n3 Spencer 12 7\n4 Luke 20 7\n5 Max 22 5<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Supponiamo ora di creare il seguente diagramma a dispersione in ggplot2 per visualizzare questi dati:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (ggplot2)\n\n<span style=\"color: #008080;\">#create scatter plot with annotated labels<\/span>\nggplot(df) +\n  geom_point(aes(x=points, y=assists)) + \n  geom_text(aes(x=points, y=assists, label=player))<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-27302 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/rotation11-1.jpg\" alt=\"\" width=\"475\" height=\"471\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che le etichette sono orizzontali e posizionate direttamente sopra i punti.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare la seguente sintassi per ruotare le etichette e allontanarle leggermente dai punti per facilitarne la lettura:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008000;\">library<\/span> (ggplot2)\n\n<span style=\"color: #008080;\">#create scatter plot with annotated rotated labels<\/span>\nggplot(df) +\n  geom_point(aes(x=points, y=assists)) + \n  geom_text(aes(x=points, y=assists, label=player), hjust= <span style=\"color: #008000;\">-.3<\/span> , vjust= <span style=\"color: #008000;\">-.1<\/span> , angle= <span style=\"color: #008000;\">45<\/span> ) +\n  ylim(3, 8)<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-27303 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/rotation12-1.jpg\" alt=\"\" width=\"468\" height=\"465\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che le etichette ora sono tutte ruotate di 45 gradi in senso antiorario.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Sentiti libero di giocare con gli argomenti <strong>hjust<\/strong> , <strong>vjust<\/strong> e <strong>corner<\/strong> per ottenere il testo annotato nella posizione che desideri sulla trama.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>Nota<\/strong> : abbiamo utilizzato anche l&#8217;argomento <strong>ylim<\/strong> per <a href=\"https:\/\/statorials.org\/it\/imposta-i-limiti-dellasse-ggplot2\/\" target=\"_blank\" rel=\"noopener\">aumentare i limiti dell&#8217;asse y<\/a> sul grafico in modo che l&#8217;etichetta &#8220;Spencer&#8221; nella parte superiore del grafico non venisse tagliata.<\/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\/ruotare-le-etichette-degli-assi-ggplot2\/\" target=\"_blank\" rel=\"noopener\">Come ruotare le etichette degli assi in ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/dimensione-in-punti-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come modificare la dimensione in punti in ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come aggiungere testo ai grafici ggplot2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi di base per ruotare il testo annotato nei grafici ggplot2: ggplot(df) + geom_point(aes(x=x, y=y)) + geom_text(aes(x=x, y=y, label=group), hjust= -0.3 , vjust= -0.1 , angle= 45 ) In questo esempio particolare, utilizziamo l&#8217;argomento angolo per ruotare il testo annotato di 45 gradi in senso antiorario e gli argomenti hjust [&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 il testo annotato in ggplot2 (con esempio) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come ruotare il testo annotato 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\/ggplot-annota-la-rotazione-del-testo\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come ruotare il testo annotato in ggplot2 (con esempio) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come ruotare il testo annotato in ggplot2, con un esempio.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-18T15:48:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/rotation11-1.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\/ggplot-annota-la-rotazione-del-testo\/\",\"url\":\"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/\",\"name\":\"Come ruotare il testo annotato in ggplot2 (con esempio) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-18T15:48:27+00:00\",\"dateModified\":\"2023-07-18T15:48:27+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come ruotare il testo annotato in ggplot2, con un esempio.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come ruotare il testo annotato in ggplot2 (con esempio)\"}]},{\"@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 il testo annotato in ggplot2 (con esempio) - Statorials","description":"Questo tutorial spiega come ruotare il testo annotato 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\/ggplot-annota-la-rotazione-del-testo\/","og_locale":"it_IT","og_type":"article","og_title":"Come ruotare il testo annotato in ggplot2 (con esempio) - Statorials","og_description":"Questo tutorial spiega come ruotare il testo annotato in ggplot2, con un esempio.","og_url":"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/","og_site_name":"Statorials","article_published_time":"2023-07-18T15:48:27+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/rotation11-1.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\/ggplot-annota-la-rotazione-del-testo\/","url":"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/","name":"Come ruotare il testo annotato in ggplot2 (con esempio) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-18T15:48:27+00:00","dateModified":"2023-07-18T15:48:27+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come ruotare il testo annotato in ggplot2, con un esempio.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/ggplot-annota-la-rotazione-del-testo\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come ruotare il testo annotato in ggplot2 (con esempio)"}]},{"@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\/3215"}],"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=3215"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3215\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3215"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3215"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3215"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}