{"id":385,"date":"2024-03-21T11:13:25","date_gmt":"2024-03-21T11:13:25","guid":{"rendered":"https:\/\/agustincastro.es\/?p=385"},"modified":"2026-01-24T13:22:37","modified_gmt":"2026-01-24T13:22:37","slug":"como-realizar-graficos-de-boxplot-en-r","status":"publish","type":"post","link":"https:\/\/agustincastro.es\/index.php\/2024\/03\/21\/como-realizar-graficos-de-boxplot-en-r\/","title":{"rendered":"\u00bfC\u00f3mo realizar gr\u00e1ficos de BOXPLOT en R?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Un gr\u00e1fico <strong><em>boxplot<\/em><\/strong>, tambi\u00e9n conocido como diagrama de caja y bigotes, es una herramienta gr\u00e1fica para visualizar la distribuci\u00f3n de un conjunto de datos y resumir varias caracter\u00edsticas importantes de manera concisa. Fue desarrollado por el estad\u00edstico <strong>John Tukey<\/strong> en la d\u00e9cada de <strong>1970<\/strong>. <p class=\"MsoNormal\" style=\"text-align:justify\">Interpretar un gr\u00e1fico de boxplot es relativamente sencillo y puede proporcionar una gran cantidad de informaci\u00f3n sobre la distribuci\u00f3n de los datos. <span style=\"font-size: revert;\"> <\/span><\/p><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><p class=\"MsoNormal\" style=\"text-align:justify\"><span style=\"font-size: revert; text-indent: -18pt; font-family: Symbol;\">\u00b7<span style=\"font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: &quot;Times New Roman&quot;;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span><\/span><b style=\"font-size: revert; text-indent: -18pt;\">Mediana<\/b><span style=\"font-size: revert; text-indent: -18pt;\">: La l\u00ednea dentro del rect\u00e1ngulo representa la mediana de los datos. Indicar\u00eda el valor que divide al <\/span><u style=\"font-size: revert; text-indent: -18pt;\">total del conjunto de datos<\/u><span style=\"font-size: revert; text-indent: -18pt;\"> en dos partes iguales, con el 50% de estos por encima y el 50% por debajo.<\/span><\/p> <span style=\"font-size: revert; text-align: justify; text-indent: -18pt; font-family: Symbol;\">\u00b7<span style=\"font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: &quot;Times New Roman&quot;;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span><\/span><b style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">Rango intercuart\u00edlico IQR*<\/b><span style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">: La caja en el <\/span><i style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">boxplot<\/i><span style=\"font-size: revert; text-align: justify; text-indent: -18pt;\"> representa la diferencia entre el tercer cuartil (Q3) y el primer cuartil (Q1). El 50% de los datos se encuentran dentro de esta caja. La longitud de la caja indica la variabilidad de los datos. *<\/span><i style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">IQR = interquartile Range. <\/i> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-size: revert; text-align: justify; text-indent: -18pt; font-family: Symbol;\">\u00b7<span style=\"font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: &quot;Times New Roman&quot;;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span><\/span><b style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">Bigotes<\/b><span style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">: Los bigotes se extienden desde los bordes de la caja hasta los puntos que est\u00e1n dentro de 1.5 veces el IQR desde el primer y tercer cuartil. Los datos que caen fuera de los bigotes se pueden considerar como valores at\u00edpicos o valores extremos, pero no necesariamente errores en la recopilaci\u00f3n de datos. <\/span> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-size: revert; text-align: justify; text-indent: -18pt; font-family: Symbol;\">\u00b7<span style=\"font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: &quot;Times New Roman&quot;;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span><\/span><b style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">Valores at\u00edpicos<\/b><span style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">: Los puntos que est\u00e1n m\u00e1s all\u00e1 de los bigotes se muestran como puntos individuales y se consideran valores at\u00edpicos (<\/span><i style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">outliers<\/i><span style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">). Pueden indicar variabilidad adicional en los datos o, errores en la recopilaci\u00f3n de datos.<\/span> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-size: revert; text-align: justify; text-indent: -18pt; font-family: Symbol;\">\u00b7<span style=\"font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: &quot;Times New Roman&quot;;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span><\/span><b style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">Simetr\u00eda y sesgo<\/b><span style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">: La simetr\u00eda y el sesgo de los datos se pueden inferir observando la distribuci\u00f3n de los datos a trav\u00e9s del boxplot. Por ejemplo, si la mediana no est\u00e1 cerca del centro de la caja, podr\u00eda indicar una distribuci\u00f3n sesgada.<\/span> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><span style=\"font-size: revert; text-align: justify; text-indent: -18pt; font-family: Symbol;\">\u00b7<span style=\"font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-alternates: normal; font-kerning: auto; font-optical-sizing: auto; font-feature-settings: normal; font-variation-settings: normal; font-variant-position: normal; font-stretch: normal; font-size: 7pt; line-height: normal; font-family: &quot;Times New Roman&quot;;\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 <\/span><\/span><b style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">Comparaciones<\/b><span style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">: Los <\/span><i style=\"font-size: revert; text-align: justify; text-indent: -18pt;\">boxplots<\/i><span style=\"font-size: revert; text-align: justify; text-indent: -18pt;\"> tambi\u00e9n son \u00fatiles para comparar distribuciones entre diferentes grupos. Por ejemplo, en este caso concreto en el que comparamos el efecto de diferentes dietas sobre el crecimiento de los animales, podemos ver r\u00e1pidamente si hay diferencias en las medianas, la dispersi\u00f3n o la presencia de valores at\u00edpicos entre los grupos.<\/span> <\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>DATASET CHICKWEIGHT<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">El conjunto de datos <strong><u>ChickWeight<\/u><\/strong> es un <em>dataset<\/em> integrado en R que contiene informaci\u00f3n sobre el peso de pollos que han crecido aliment\u00e1ndose de diferentes dietas a lo largo del tiempo. Es com\u00fanmente utilizado en ejemplos de an\u00e1lisis de datos y en la ense\u00f1anza de t\u00e9cnicas estad\u00edsticas y de visualizaci\u00f3n en R. En este caso utilizamos estos datos para representar visualmente los pesos alcanzados con cada una de las dietas mediante gr\u00e1ficos <em>boxplot<\/em>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Para ver el conjunto de datasets utiliza <strong>data()<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Nombre del conjunto de datos<\/strong>: ChickWeight<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Tipo de datos<\/strong>: Datos longitudinales (es decir, datos recopilados en m\u00faltiples momentos a lo largo del tiempo)<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Variables<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Weight: Peso del individuo.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Time: Tiempo de observaci\u00f3n (d\u00edas).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Chick: Identificador \u00fanico para cada animal.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Diet: Tipo de dieta que recibe el pollito. Existen cuatro tipos de dieta en este conjunto de datos.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Observaciones: Cada fila en el conjunto de datos representa una observaci\u00f3n de un pollito en un momento espec\u00edfico del tiempo.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>C\u00d3DIGO R<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"676\" data-src=\"https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/image-1-1024x676.png\" alt=\"\" class=\"wp-image-389 lazyload\" data-srcset=\"https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/image-1-1024x676.png 1024w, https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/image-1-300x198.png 300w, https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/image-1-768x507.png 768w, https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/image-1-1536x1015.png 1536w, https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/image-1.png 1582w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/676;\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" width=\"1024\" height=\"683\" data-src=\"https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/weight_diet-1024x683.jpg\" alt=\"\" class=\"wp-image-390 lazyload\" data-srcset=\"https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/weight_diet-1024x683.jpg 1024w, https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/weight_diet-300x200.jpg 300w, https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/weight_diet-768x512.jpg 768w, https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/weight_diet-1536x1024.jpg 1536w, https:\/\/agustincastro.es\/wp-content\/uploads\/2024\/03\/weight_diet-2048x1365.jpg 2048w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/683;\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Un gr\u00e1fico boxplot, tambi\u00e9n conocido como diagrama de caja y bigotes, es una herramienta gr\u00e1fica para visualizar la distribuci\u00f3n de un conjunto de datos y resumir varias caracter\u00edsticas importantes de manera concisa. Fue desarrollado por el estad\u00edstico John Tukey en la d\u00e9cada de 1970. Interpretar un gr\u00e1fico de boxplot es relativamente sencillo y puede proporcionar [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":330,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,5],"tags":[],"class_list":["post-385","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-r","category-tecnica-y-practica"],"_links":{"self":[{"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/posts\/385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/comments?post=385"}],"version-history":[{"count":5,"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/posts\/385\/revisions"}],"predecessor-version":[{"id":396,"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/posts\/385\/revisions\/396"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/media\/330"}],"wp:attachment":[{"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/media?parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/categories?post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/agustincastro.es\/index.php\/wp-json\/wp\/v2\/tags?post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}