{"id":3025,"date":"2023-07-19T14:17:21","date_gmt":"2023-07-19T14:17:21","guid":{"rendered":"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/"},"modified":"2023-07-19T14:17:21","modified_gmt":"2023-07-19T14:17:21","slug":"aggiungi-testo-a-ggplot","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/","title":{"rendered":"Come aggiungere testo ai grafici ggplot2 (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Puoi utilizzare la funzione <strong>annotate()<\/strong> per aggiungere testo ai grafici in ggplot2.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questa funzione utilizza la seguente sintassi di base:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>p+\n  annotate(\" <span style=\"color: #ff0000;\">text<\/span> \", x= <span style=\"color: #008000;\">6<\/span> , y= <span style=\"color: #008000;\">10<\/span> , label= \" <span style=\"color: #ff0000;\">hello<\/span> \")\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Oro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>x, y<\/strong> : le coordinate (x, y) in cui deve essere posizionato il testo.<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>label<\/strong> : il testo da visualizzare.<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare questa funzione nella pratica.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 1: aggiungi un elemento di testo a ggplot2<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare <strong>annotate()<\/strong> per aggiungere un elemento di testo a un grafico a dispersione ggplot2:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">library<\/span> (ggplot2)\n\n<span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (x=c(1, 3, 3, 5, 7, 8, 10, 11),\n                 y=c(3, 5, 7, 5, 8, 10, 14, 19))\n\n<span style=\"color: #008080;\">#create scatter plot with one text element\n<\/span>ggplot(df, aes(x=x, y=y)) +\n  geom_point()\n  annotate(\" <span style=\"color: #ff0000;\">text<\/span> \", x= <span style=\"color: #008000;\">6<\/span> , y= <span style=\"color: #008000;\">10<\/span> , label= \" <span style=\"color: #ff0000;\">hello<\/span> \")\n<\/strong><\/span><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-26036 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/annoter1.jpg\" alt=\"\" width=\"586\" height=\"385\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Nota che il nostro elemento di testo \u00e8 stato aggiunto alle coordinate (x, y) di (6, 10) nel grafico.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: aggiungi pi\u00f9 elementi di testo a ggplot2<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come utilizzare <strong>annotate()<\/strong> per aggiungere pi\u00f9 elementi di testo a un grafico a dispersione ggplot2:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">library<\/span> (ggplot2)\n\n<span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (x=c(1, 3, 3, 5, 7, 8, 10, 11),\n                 y=c(3, 5, 7, 5, 8, 10, 14, 19))\n\n<span style=\"color: #008080;\">#create scatter plot with one text element\n<\/span>ggplot(df, aes(x=x, y=y)) +\n  geom_point() +\n  annotate(\" <span style=\"color: #ff0000;\">text<\/span> \", x= <span style=\"color: #008000;\">6<\/span> , y= <span style=\"color: #008000;\">10<\/span> , label= \" <span style=\"color: #ff0000;\">hello<\/span> \") +\n  annotate(\" <span style=\"color: #ff0000;\">text<\/span> \", x= <span style=\"color: #008000;\">3<\/span> , y= <span style=\"color: #008000;\">15<\/span> , label= \" <span style=\"color: #ff0000;\">hello again<\/span> \")<\/strong><\/span> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-26037 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/annoter2.jpg\" alt=\"\" width=\"575\" height=\"381\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Notare che due elementi di testo sono stati aggiunti alla trama alle coordinate specificate.<\/span><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 3: personalizzare gli elementi di testo nella trama<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare gli argomenti <strong>size<\/strong> , <strong>col<\/strong> e <strong>italic<\/strong> o <strong>bold<\/strong> per personalizzare rispettivamente la dimensione, il colore e lo stile del carattere degli elementi di testo nella trama:<\/span> <\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008000;\">library<\/span> (ggplot2)\n\n<span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (x=c(1, 3, 3, 5, 7, 8, 10, 11),\n                 y=c(3, 5, 7, 5, 8, 10, 14, 19))\n\n<span style=\"color: #008080;\">#create scatter plot with custom text element\n<\/span>ggplot(df, aes(x=x, y=y)) +\n  geom_point() +\n  annotate(\" <span style=\"color: #ff0000;\">text<\/span> \", x= <span style=\"color: #008000;\">6<\/span> , y= <span style=\"color: #008000;\">10<\/span> , label= \" <span style=\"color: #ff0000;\">bolditalic(hello)<\/span> \",\n           col=\" <span style=\"color: #ff0000;\">blue<\/span> \", size= <span style=\"color: #008000;\">10<\/span> , parse= <span style=\"color: #008000;\">TRUE<\/span> )<\/strong><\/span> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-26038 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/annoter3.jpg\" alt=\"\" width=\"570\" height=\"372\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che l&#8217;unico elemento di testo nella trama ora \u00e8 in grassetto, corsivo, blu e ha una dimensione pari a 10.<\/span><\/p>\n<p> <span style=\"color: #000000;\"><span style=\"color: #000000;\"><strong>Nota<\/strong> : puoi trovare la documentazione completa della funzione <strong>annotate()<\/strong> in ggplot2 <a href=\"https:\/\/ggplot2.tidyverse.org\/reference\/annotate.html\" target=\"_blank\" rel=\"noopener\">qui<\/a> .<\/span><\/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\/dimensione-in-punti-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come modificare la dimensione in punti in ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/posizione-del-titolo-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come cambiare la posizione del titolo in ggplot2<\/a><br \/> Come rimuovere le etichette degli assi in ggplot2<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Puoi utilizzare la funzione annotate() per aggiungere testo ai grafici in ggplot2. Questa funzione utilizza la seguente sintassi di base: p+ annotate(&#8221; text &#8220;, x= 6 , y= 10 , label= &#8221; hello &#8220;) Oro: x, y : le coordinate (x, y) in cui deve essere posizionato il testo. label : il testo da visualizzare. [&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 aggiungere testo ai grafici ggplot2 (con esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come aggiungere testo ai grafici 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\/aggiungi-testo-a-ggplot\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come aggiungere testo ai grafici ggplot2 (con esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come aggiungere testo ai grafici in ggplot2, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-19T14:17:21+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/annoter1.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\/aggiungi-testo-a-ggplot\/\",\"url\":\"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/\",\"name\":\"Come aggiungere testo ai grafici ggplot2 (con esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-19T14:17:21+00:00\",\"dateModified\":\"2023-07-19T14:17:21+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come aggiungere testo ai grafici in ggplot2, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come aggiungere testo ai grafici 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 aggiungere testo ai grafici ggplot2 (con esempi) - Statorials","description":"Questo tutorial spiega come aggiungere testo ai grafici 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\/aggiungi-testo-a-ggplot\/","og_locale":"it_IT","og_type":"article","og_title":"Come aggiungere testo ai grafici ggplot2 (con esempi) - Statorials","og_description":"Questo tutorial spiega come aggiungere testo ai grafici in ggplot2, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/","og_site_name":"Statorials","article_published_time":"2023-07-19T14:17:21+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/annoter1.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\/aggiungi-testo-a-ggplot\/","url":"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/","name":"Come aggiungere testo ai grafici ggplot2 (con esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-19T14:17:21+00:00","dateModified":"2023-07-19T14:17:21+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come aggiungere testo ai grafici in ggplot2, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/aggiungi-testo-a-ggplot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come aggiungere testo ai grafici 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\/3025"}],"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=3025"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3025\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3025"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3025"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3025"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}