{"id":3984,"date":"2023-07-14T08:54:44","date_gmt":"2023-07-14T08:54:44","guid":{"rendered":"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/"},"modified":"2023-07-14T08:54:44","modified_gmt":"2023-07-14T08:54:44","slug":"etichette-dellistogramma-ggplot","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/","title":{"rendered":"Come aggiungere etichette all&#39;istogramma in ggplot2 (con esempio)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">Puoi utilizzare la seguente sintassi di base per aggiungere etichette a un istogramma in ggplot2:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>ggplot(data=df, aes(x=values_var)) + \n  geom_histogram(aes(fill=group_var), binwidth= <span style=\"color: #008000;\">1<\/span> , color=' <span style=\"color: #ff0000;\">black<\/span> ') +\n  stat_bin(binwidth= <span style=\"color: #008000;\">1<\/span> , geom=' <span style=\"color: #ff0000;\">text<\/span> ', color=' <span style=\"color: #ff0000;\">white<\/span> ', size= <span style=\"color: #008000;\">4<\/span> ,\n           aes(label=..count.., group=group_var), position=position_stack(vjust= <span style=\"color: #008000;\">0.5<\/span> ))\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Questo particolare esempio aggiunge un&#8217;etichetta bianca per visualizzare il conteggio di ciascun contenitore in ciascuna categoria di un istogramma.<\/span><\/p>\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: aggiungi etichette all&#8217;istogramma in ggplot2<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente frame di dati in R che contiene informazioni sui punti segnati dai giocatori di basket di tre squadre diverse:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <span style=\"color: #000000;\"><strong><span style=\"color: #008080;\">#make this example reproducible\n<\/span>set. <span style=\"color: #3366ff;\">seeds<\/span> (1)\n\n<span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (team=rep(c(' <span style=\"color: #ff0000;\">A<\/span> ', ' <span style=\"color: #ff0000;\">B<\/span> ', ' <span style=\"color: #ff0000;\">C<\/span> '), each=100),\n                 points=c(runif(100, 5, 10),\n                          runif(100, 5, 10),\n                          runif(100, 5, 10)))\n\n<span style=\"color: #008080;\">#view head of data frame\n<\/span>head(df)\n\n  team points\n1 A 6.327543\n2 A 6.860619\n3 A 7.864267\n4 A 9.541039\n5 A 6.008410\n6 A 9.491948\n<\/strong><\/span><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare il codice seguente per creare un istogramma che mostri i punti segnati dai giocatori di ciascuna squadra con etichette che indicano il conteggio per ciascun contenitore:<\/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 histogram with labels for each bin<\/span>\nggplot(data=df, aes(x=points)) + \n  geom_histogram(aes(fill=team), binwidth= <span style=\"color: #008000;\">1<\/span> , color=' <span style=\"color: #ff0000;\">black<\/span> ') +\n  stat_bin(binwidth= <span style=\"color: #008000;\">1<\/span> , geom=' <span style=\"color: #ff0000;\">text<\/span> ', color=' <span style=\"color: #ff0000;\">white<\/span> ', size= <span style=\"color: #008000;\">4<\/span> ,\n           aes(label=..count.., group=team), position=position_stack(vjust= <span style=\"color: #008000;\">0.5<\/span> ))<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-31897\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/laboratoires1.jpg\" alt=\"Etichette dell'istogramma ggplot\" width=\"602\" height=\"442\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che ogni contenitore ha un&#8217;etichetta che ne visualizza il numero.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Tieni presente che puoi modificare i valori di <strong>colore<\/strong> e <strong>dimensione<\/strong> nella funzione <strong>stat_bin()<\/strong> per modificare rispettivamente il colore e la dimensione delle etichette.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Ad esempio, possiamo utilizzare la seguente sintassi per utilizzare invece etichette nere con una maggiore dimensione del carattere:<\/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 histogram with labels for each bin<\/span>\nggplot(data=df, aes(x=points)) + \n  geom_histogram(aes(fill=team), binwidth= <span style=\"color: #008000;\">1<\/span> , color=' <span style=\"color: #ff0000;\">black<\/span> ') +\n  stat_bin(binwidth= <span style=\"color: #008000;\">1<\/span> , geom=' <span style=\"color: #ff0000;\">text<\/span> ', color=' <span style=\"color: #ff0000;\">black<\/span> ', size= <span style=\"color: #008000;\">6<\/span> ,\n           aes(label=..count.., group=team), position=position_stack(vjust= <span style=\"color: #008000;\">0.5<\/span> ))<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-31898 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/laboratoires2.jpg\" alt=\"\" width=\"571\" height=\"416\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Le etichette per ogni contenitore ora utilizzano testo nero e una dimensione del carattere pi\u00f9 grande.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Sentiti libero di giocare con gli argomenti <strong>colore<\/strong> e <strong>dimensione<\/strong> nella funzione <strong>stat_bin()<\/strong> per far apparire le etichette nel modo desiderato.<\/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 R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/istogramma-ggplot2-per-gruppo\/\" target=\"_blank\" rel=\"noopener\">Come creare istogrammi per gruppo in ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/percentuale-dellistogramma-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come visualizzare le percentuali sull&#8217;istogramma in ggplot2<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/contenitori-dellistogramma-ggplot\/\" target=\"_blank\" rel=\"noopener\">Come impostare il numero di contenitori per un istogramma in ggplot2<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Puoi utilizzare la seguente sintassi di base per aggiungere etichette a un istogramma in ggplot2: ggplot(data=df, aes(x=values_var)) + geom_histogram(aes(fill=group_var), binwidth= 1 , color=&#8217; black &#8216;) + stat_bin(binwidth= 1 , geom=&#8217; text &#8216;, color=&#8217; white &#8216;, size= 4 , aes(label=..count.., group=group_var), position=position_stack(vjust= 0.5 )) Questo particolare esempio aggiunge un&#8217;etichetta bianca per visualizzare il conteggio di ciascun [&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 etichette all&#039;istogramma in ggplot2 (con esempio) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come aggiungere etichette a un istogramma 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-dellistogramma-ggplot\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come aggiungere etichette all&#039;istogramma in ggplot2 (con esempio) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come aggiungere etichette a un istogramma in ggplot2, con un esempio.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-14T08:54:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/laboratoires1.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-dellistogramma-ggplot\/\",\"url\":\"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/\",\"name\":\"Come aggiungere etichette all&#39;istogramma in ggplot2 (con esempio) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-14T08:54:44+00:00\",\"dateModified\":\"2023-07-14T08:54:44+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come aggiungere etichette a un istogramma in ggplot2, con un esempio.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come aggiungere etichette all&#39;istogramma 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 aggiungere etichette all&#39;istogramma in ggplot2 (con esempio) - Statorials","description":"Questo tutorial spiega come aggiungere etichette a un istogramma 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-dellistogramma-ggplot\/","og_locale":"it_IT","og_type":"article","og_title":"Come aggiungere etichette all&#39;istogramma in ggplot2 (con esempio) - Statorials","og_description":"Questo tutorial spiega come aggiungere etichette a un istogramma in ggplot2, con un esempio.","og_url":"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/","og_site_name":"Statorials","article_published_time":"2023-07-14T08:54:44+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/laboratoires1.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-dellistogramma-ggplot\/","url":"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/","name":"Come aggiungere etichette all&#39;istogramma in ggplot2 (con esempio) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-14T08:54:44+00:00","dateModified":"2023-07-14T08:54:44+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come aggiungere etichette a un istogramma in ggplot2, con un esempio.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/etichette-dellistogramma-ggplot\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come aggiungere etichette all&#39;istogramma 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\/3984"}],"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=3984"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/3984\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=3984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=3984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=3984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}