{"id":2093,"date":"2023-07-23T17:48:41","date_gmt":"2023-07-23T17:48:41","guid":{"rendered":"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/"},"modified":"2023-07-23T17:48:41","modified_gmt":"2023-07-23T17:48:41","slug":"barre-di-errore-in-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/","title":{"rendered":"Come aggiungere barre di errore ai grafici in r (con esempi)"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">\u00c8 possibile utilizzare la seguente sintassi di base per aggiungere barre di errore a un grafico a barre in R:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong>ggplot(df) +\n    geom_bar( <span style=\"color: #3366ff;\">aes<\/span> (x=x, y=y), stat=' <span style=\"color: #ff0000;\">identity<\/span> ') +\n    geom_errorbar( <span style=\"color: #3366ff;\">aes<\/span> (x=x, ymin=y-sd, ymax=y+sd), width= <span style=\"color: #008000;\">0.4<\/span> )\n<\/strong><\/pre>\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: aggiungere barre di errore utilizzando dati di riepilogo<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente frame di dati in R che visualizza le statistiche riepilogative per cinque categorie:<\/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> (category=c('A', 'B', 'C', 'D', 'E'),\n                 value=c(12, 17, 30, 22, 19),\n                 sd=c(4, 5, 7, 4, 2))\n\n<span style=\"color: #008080;\">#view data frame\n<\/span>df\n\n  category value sd\n1 to 12 4\n2 B 17 5\n3 C 30 7\n4 D 22 4\n5 E 19 2\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Possiamo utilizzare il seguente codice per creare un grafico a barre con barre di errore per visualizzare questi dati:<\/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 error bars\n<\/span>ggplot(df) +\n    geom_bar( <span style=\"color: #3366ff;\">aes<\/span> (x=category, y=value), stat=' <span style=\"color: #ff0000;\">identity<\/span> ', fill=' <span style=\"color: #ff0000;\">steelblue<\/span> ') +\n    geom_errorbar( <span style=\"color: #3366ff;\">aes<\/span> (x=category, ymin=value-sd, ymax=value+sd), width= <span style=\"color: #008000;\">0.4<\/span> )\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\"aligncenter wp-image-19472\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/barre-derreurr1.png\" alt=\"grafico a barre con barre di errore in R\" width=\"465\" height=\"465\" srcset=\"\" sizes=\"\"><\/p>\n<p> <span style=\"color: #000000;\">Sentiti libero di utilizzare i seguenti argomenti per modificare l&#8217;aspetto delle barre di errore:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>larghezza<\/strong> : la larghezza delle barre di errore<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>size<\/strong> : lo spessore delle barre di errore<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>color<\/strong> : il colore delle barre di errore<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">Per esempio:<\/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<\/span>\n<span style=\"color: #008080;\">#create bar plot with custom error bars<\/span>\nggplot(df) +\n    geom_bar( <span style=\"color: #3366ff;\">aes<\/span> (x=category, y=value), stat=' <span style=\"color: #ff0000;\">identity<\/span> ', fill=' <span style=\"color: #ff0000;\">steelblue<\/span> ') +\n    geom_errorbar( <span style=\"color: #3366ff;\">aes<\/span> (x=category, ymin=value-sd, ymax=value+sd),\n                  width= <span style=\"color: #008000;\">0.3<\/span> , size= <span style=\"color: #008000;\">2.3<\/span> , color=' <span style=\"color: #ff0000;\">red<\/span> ')\n<\/strong><\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-19473 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/barre-derreurr2.png\" alt=\"\" width=\"445\" height=\"452\" srcset=\"\" sizes=\"\"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Esempio 2: aggiungere barre di errore utilizzando dati grezzi<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente frame di dati che mostra i dati grezzi per cinque diverse categorie:<\/span><\/p>\n<pre style=\"background-color: #ececec; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#make this example reproducible<\/span>\nset. <span style=\"color: #3366ff;\">seeds<\/span> (0)\n\n<span style=\"color: #008080;\">#create data frame\n<\/span>df &lt;- data. <span style=\"color: #3366ff;\">frame<\/span> (category=rep(c('A', 'B', 'C', 'D', 'E'), each= <span style=\"color: #008000;\">10<\/span> ),\n                 value=runif(50, 10, 20))\n\n<span style=\"color: #008080;\">#view first six rows of data frame\n<\/span>head(df)\n\n  category value\n1 A 18.96697\n2 A 12.65509\n3 A 13.72124\n4 A 15.72853\n5 A 19.08208\n6 A 12.01682\n<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come riepilogare i dati e quindi creare un grafico a barre con barre di errore:<\/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 style=\"color: #000000;\">(dplyr)<\/span>\nlibrary<\/span> (ggplot2)\n<\/span><\/span>\n<span style=\"color: #008080;\">#summarize mean and sd for each category\n<\/span>df_summary &lt;- df %&gt;%\n  group_by(category) %&gt;%\n  summarize(mean=mean(value),\n            sd=sd(value))\n\n<span style=\"color: #008080;\">#view summary data\n<\/span>df_summary\n\n# A tibble: 5 x 3\n  category mean sd\n       \n1 A 16.4 2.80\n2B 14.9 2.99\n3 C 14.6 3.25\n4 D 15.2 2.48\n5 E 15.8 2.41 \n\n<span style=\"color: #008080;\">#create bar plot with error bars\n<\/span>ggplot(df_summary) +\n    geom_bar( <span style=\"color: #3366ff;\">aes<\/span> (x=category, y=mean), stat=' <span style=\"color: #ff0000;\">identity<\/span> ', fill=' <span style=\"color: #ff0000;\">steelblue<\/span> ') +\n    geom_errorbar( <span style=\"color: #3366ff;\">aes<\/span> (x=category, ymin=mean-sd, ymax=mean+sd), width= <span style=\"color: #008000;\">0.3<\/span> , color=' <span style=\"color: #ff0000;\">red<\/span> ')<\/strong> <\/pre>\n<p><img decoding=\"async\" loading=\"lazy\" class=\" wp-image-19475 aligncenter\" src=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/barre-derreurr3.png\" alt=\"\" width=\"468\" height=\"464\" srcset=\"\" sizes=\"\"><\/p>\n<h3> <span style=\"color: #000000;\"><strong>Risorse addizionali<\/strong><\/span><\/h3>\n<p> <span style=\"color: #000000;\">I seguenti tutorial spiegano come creare altre visualizzazioni di dati comuni in R:<\/span><\/p>\n<p> <a href=\"https:\/\/statorials.org\/it\/boxplot-multipli-r\/\" target=\"_blank\" rel=\"noopener\">Come tracciare pi\u00f9 boxplot in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/istogrammi-multipli-r\/\" target=\"_blank\" rel=\"noopener\">Come tracciare pi\u00f9 istogrammi in R<\/a><br \/> <a href=\"https:\/\/statorials.org\/it\/come-tracciare-piu-linee-di-dati-in-serie-in-un-grafico-in-r\/\" target=\"_blank\" rel=\"noopener\">Come disegnare pi\u00f9 linee in R<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00c8 possibile utilizzare la seguente sintassi di base per aggiungere barre di errore a un grafico a barre in R: ggplot(df) + geom_bar( aes (x=x, y=y), stat=&#8217; identity &#8216;) + geom_errorbar( aes (x=x, ymin=y-sd, ymax=y+sd), width= 0.4 ) I seguenti esempi mostrano come utilizzare questa funzione nella pratica. Esempio 1: aggiungere barre di errore utilizzando [&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 barre di errore ai grafici in R (con esempi) - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come aggiungere barre di errore ai grafici in R, 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\/barre-di-errore-in-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come aggiungere barre di errore ai grafici in R (con esempi) - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come aggiungere barre di errore ai grafici in R, con diversi esempi.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-23T17:48:41+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/barre-derreurr1.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\/barre-di-errore-in-r\/\",\"url\":\"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/\",\"name\":\"Come aggiungere barre di errore ai grafici in R (con esempi) - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-23T17:48:41+00:00\",\"dateModified\":\"2023-07-23T17:48:41+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come aggiungere barre di errore ai grafici in R, con diversi esempi.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come aggiungere barre di errore ai grafici in r (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 barre di errore ai grafici in R (con esempi) - Statorials","description":"Questo tutorial spiega come aggiungere barre di errore ai grafici in R, 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\/barre-di-errore-in-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come aggiungere barre di errore ai grafici in R (con esempi) - Statorials","og_description":"Questo tutorial spiega come aggiungere barre di errore ai grafici in R, con diversi esempi.","og_url":"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/","og_site_name":"Statorials","article_published_time":"2023-07-23T17:48:41+00:00","og_image":[{"url":"https:\/\/statorials.org\/wp-content\/uploads\/2023\/08\/barre-derreurr1.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\/barre-di-errore-in-r\/","url":"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/","name":"Come aggiungere barre di errore ai grafici in R (con esempi) - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-23T17:48:41+00:00","dateModified":"2023-07-23T17:48:41+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come aggiungere barre di errore ai grafici in R, con diversi esempi.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/barre-di-errore-in-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/barre-di-errore-in-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come aggiungere barre di errore ai grafici in r (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\/2093"}],"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=2093"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/2093\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=2093"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=2093"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=2093"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}