{"id":503,"date":"2023-07-29T16:49:12","date_gmt":"2023-07-29T16:49:12","guid":{"rendered":"https:\/\/statorials.org\/it\/abline-nel-r\/"},"modified":"2023-07-29T16:49:12","modified_gmt":"2023-07-29T16:49:12","slug":"abline-nel-r","status":"publish","type":"post","link":"https:\/\/statorials.org\/it\/abline-nel-r\/","title":{"rendered":"Come utilizzare aline() in r per aggiungere linee rette ai grafici"},"content":{"rendered":"<p><\/p>\n<hr>\n<p><span style=\"color: #000000;\">La funzione <strong>abline()<\/strong> in R pu\u00f2 essere utilizzata per aggiungere una o pi\u00f9 linee rette a un grafico in R.<\/span><\/p>\n<p> <span style=\"color: #000000;\">Questa funzione utilizza la seguente sintassi:<\/span><\/p>\n<p> <span style=\"color: #000000;\"><strong>abline(a=NULL, b=NULL, h=NULL, v=NULL, \u2026)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Oro:<\/span><\/p>\n<ul>\n<li> <span style=\"color: #000000;\"><strong>a, b:<\/strong> valori univoci che specificano l&#8217;origine e la pendenza della linea<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>h:<\/strong> il valore y per la linea orizzontale<\/span><\/li>\n<li> <span style=\"color: #000000;\"><strong>v:<\/strong> il valore x per la linea verticale<\/span><\/li>\n<\/ul>\n<p> <span style=\"color: #000000;\">I seguenti esempi mostrano come utilizzare questa funzione nella pratica.<\/span><\/p>\n<h2> <span style=\"color: #000000;\"><strong>Come aggiungere linee orizzontali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice di base per aggiungere una linea orizzontale a un grafico in R \u00e8: <strong>abline(h = qualche valore)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Supponiamo di avere il seguente diagramma a dispersione che mostra i valori <em>di<\/em> <em>xey<\/em> in un set di dati:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define dataset\n<\/span>data &lt;- data.frame(x = c(1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 11, 11),\n                   y = c(13, 14, 17, 12, 23, 24, 25, 25, 24, 28, 32, 33, 35, 40, 41))\n\n<span style=\"color: #008080;\">#plot <em>x<\/em> and <em>y<\/em> values in dataset\n<\/span>plot(data$x, data$y, pch = 16)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Per aggiungere una linea orizzontale al valore y = 20, possiamo usare il seguente codice:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong>abline(h = 20, col = 'coral2', lwd = 2)<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Il codice seguente illustra come aggiungere una linea orizzontale continua al valore medio di <em>y<\/em> e due linee tratteggiate orizzontali una deviazione standard sopra e sotto il valore medio:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#create scatterplot for <em>x<\/em> and <em>y<\/em><\/span>\nplot(data$x, data$y, pch = 16)\n\n<span style=\"color: #008080;\">#create horizontal line at mean value of <em>y<\/em>\n<\/span>abline(h = mean(data$y), lwd = 2)\n\n<span style=\"color: #008080;\">#create horizontal lines at one standard deviation above and below the mean value\n<\/span>abline(h = mean(data$y) + sd(data$y), col = 'steelblue', lwd = 3, lty = 2)\nabline(h = mean(data$y) - sd(data$y), col = 'steelblue', lwd = 3, lty = 2)<\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Come aggiungere linee verticali<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice di base per aggiungere una linea verticale a un grafico in R \u00e8: <strong>abline(v = qualche valore)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come aggiungere una linea verticale al valore medio su un istogramma:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#make this example reproducible\n<\/span>set.seed(0)\n\n<span style=\"color: #008080;\">#create dataset with 1000 random values normally distributed with mean = 10, sd = 2\n<\/span>data &lt;- rnorm(1000, mean = 10, sd = 2)\n\n<span style=\"color: #008080;\">#create histogram of data values\n<\/span>hist(data, col = 'steelblue')\n\n<span style=\"color: #008080;\">#draw a vertical dashed line at the mean value\n<\/span>abline(v = mean(data), lwd = 3, lty = 2)<\/strong><\/pre>\n<h2> <span style=\"color: #000000;\"><strong>Come aggiungere linee di regressione<\/strong><\/span><\/h2>\n<p> <span style=\"color: #000000;\">Il codice di base per aggiungere una semplice linea di regressione lineare a un grafico in R \u00e8: <strong>abline(model)<\/strong><\/span><\/p>\n<p> <span style=\"color: #000000;\">Il codice seguente mostra come aggiungere una linea di regressione lineare adattata a un grafico a dispersione:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define dataset\n<\/span>data &lt;- data.frame(x = c(1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 11, 11),\n                   y = c(13, 14, 17, 12, 23, 24, 25, 25, 24, 28, 32, 33, 35, 40, 41))\n\n<span style=\"color: #008080;\">#create scatterplot of <em>x<\/em> and <em>y<\/em> values\n<\/span>plot(data$x, data$y, pch = 16)\n\n<span style=\"color: #008080;\">#fit a linear regression model to the data\n<\/span>reg_model &lt;- lm(y ~ x, data = data)\n\n<span style=\"color: #008080;\">#add the fitted regression line to the scatterplot\n<\/span>abline(reg_model, col=\"steelblue\")<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Tieni presente che abbiamo semplicemente bisogno di un valore per l&#8217;intercetta e la pendenza per adattare una semplice linea di regressione lineare ai dati utilizzando la funzione abline().<\/span><\/p>\n<p> <span style=\"color: #000000;\">Quindi, un altro modo per utilizzare <strong>abline()<\/strong> per aggiungere una linea di regressione \u00e8 specificare esplicitamente i coefficienti originali e di pendenza del modello di regressione:<\/span><\/p>\n<pre style=\"background-color: #e5e5e5; font-size: 15px;\"> <strong><span style=\"color: #008080;\">#define dataset\n<\/span>data &lt;- data.frame(x = c(1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 11, 11),\n                   y = c(13, 14, 17, 12, 23, 24, 25, 25, 24, 28, 32, 33, 35, 40, 41))\n\n<span style=\"color: #008080;\">#create scatterplot of <em>x<\/em> and <em>y<\/em> values\n<\/span>plot(data$x, data$y, pch = 16)\n\n<span style=\"color: #008080;\">#fit a linear regression model to the data\n<\/span>reg_model &lt;- lm(y ~ x, data = data)\n\n<span style=\"color: #008080;\">#define intercept and slope values\n<\/span>a &lt;- coefficients(reg_model)[1] <span style=\"color: #008080;\">#intercept<\/span>\nb &lt;- coefficients(reg_model)[2] <span style=\"color: #008080;\">#slope<\/span>\n\n<span style=\"color: #008080;\">#add the fitted regression line to the scatterplot\n<\/span>abline(a=a, b=b, col=\"steelblue\")<\/strong><\/pre>\n<p> <span style=\"color: #000000;\">Nota che questo produce la stessa linea di prima.<\/span><\/p>\n<hr>\n<p> <span style=\"color: #000000;\">Puoi trovare altri tutorial su R in questa pagina .<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>La funzione abline() in R pu\u00f2 essere utilizzata per aggiungere una o pi\u00f9 linee rette a un grafico in R. Questa funzione utilizza la seguente sintassi: abline(a=NULL, b=NULL, h=NULL, v=NULL, \u2026) Oro: a, b: valori univoci che specificano l&#8217;origine e la pendenza della linea h: il valore y per la linea orizzontale v: il valore [&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 utilizzare abline() in R per aggiungere linee rette ai grafici - Statorials<\/title>\n<meta name=\"description\" content=\"Questo tutorial spiega come utilizzare la funzione abline() in R per aggiungere una o pi\u00f9 linee rette a un percorso in R.\" \/>\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\/abline-nel-r\/\" \/>\n<meta property=\"og:locale\" content=\"it_IT\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Come utilizzare abline() in R per aggiungere linee rette ai grafici - Statorials\" \/>\n<meta property=\"og:description\" content=\"Questo tutorial spiega come utilizzare la funzione abline() in R per aggiungere una o pi\u00f9 linee rette a un percorso in R.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/statorials.org\/it\/abline-nel-r\/\" \/>\n<meta property=\"og:site_name\" content=\"Statorials\" \/>\n<meta property=\"article:published_time\" content=\"2023-07-29T16:49:12+00:00\" \/>\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=\"3 minuti\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/statorials.org\/it\/abline-nel-r\/\",\"url\":\"https:\/\/statorials.org\/it\/abline-nel-r\/\",\"name\":\"Come utilizzare abline() in R per aggiungere linee rette ai grafici - Statorials\",\"isPartOf\":{\"@id\":\"https:\/\/statorials.org\/it\/#website\"},\"datePublished\":\"2023-07-29T16:49:12+00:00\",\"dateModified\":\"2023-07-29T16:49:12+00:00\",\"author\":{\"@id\":\"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae\"},\"description\":\"Questo tutorial spiega come utilizzare la funzione abline() in R per aggiungere una o pi\u00f9 linee rette a un percorso in R.\",\"breadcrumb\":{\"@id\":\"https:\/\/statorials.org\/it\/abline-nel-r\/#breadcrumb\"},\"inLanguage\":\"it-IT\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/statorials.org\/it\/abline-nel-r\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/statorials.org\/it\/abline-nel-r\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Casa\",\"item\":\"https:\/\/statorials.org\/it\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Come utilizzare aline() in r per aggiungere linee rette ai grafici\"}]},{\"@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 utilizzare abline() in R per aggiungere linee rette ai grafici - Statorials","description":"Questo tutorial spiega come utilizzare la funzione abline() in R per aggiungere una o pi\u00f9 linee rette a un percorso in R.","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\/abline-nel-r\/","og_locale":"it_IT","og_type":"article","og_title":"Come utilizzare abline() in R per aggiungere linee rette ai grafici - Statorials","og_description":"Questo tutorial spiega come utilizzare la funzione abline() in R per aggiungere una o pi\u00f9 linee rette a un percorso in R.","og_url":"https:\/\/statorials.org\/it\/abline-nel-r\/","og_site_name":"Statorials","article_published_time":"2023-07-29T16:49:12+00:00","author":"Benjamin anderson","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Benjamin anderson","Est. reading time":"3 minuti"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/statorials.org\/it\/abline-nel-r\/","url":"https:\/\/statorials.org\/it\/abline-nel-r\/","name":"Come utilizzare abline() in R per aggiungere linee rette ai grafici - Statorials","isPartOf":{"@id":"https:\/\/statorials.org\/it\/#website"},"datePublished":"2023-07-29T16:49:12+00:00","dateModified":"2023-07-29T16:49:12+00:00","author":{"@id":"https:\/\/statorials.org\/it\/#\/schema\/person\/0896f191fb9fb019f2cd8623112cb3ae"},"description":"Questo tutorial spiega come utilizzare la funzione abline() in R per aggiungere una o pi\u00f9 linee rette a un percorso in R.","breadcrumb":{"@id":"https:\/\/statorials.org\/it\/abline-nel-r\/#breadcrumb"},"inLanguage":"it-IT","potentialAction":[{"@type":"ReadAction","target":["https:\/\/statorials.org\/it\/abline-nel-r\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/statorials.org\/it\/abline-nel-r\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Casa","item":"https:\/\/statorials.org\/it\/"},{"@type":"ListItem","position":2,"name":"Come utilizzare aline() in r per aggiungere linee rette ai grafici"}]},{"@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\/503"}],"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=503"}],"version-history":[{"count":0,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/posts\/503\/revisions"}],"wp:attachment":[{"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/media?parent=503"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/categories?post=503"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/statorials.org\/it\/wp-json\/wp\/v2\/tags?post=503"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}