<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-21694095</id><updated>2026-03-11T09:33:07.605+01:00</updated><category term="R"/><category term="Rstats"/><category term="Ms Excel"/><category term="ggplot2"/><category term="VBA"/><category term="dplyr"/><category term="Ms Access"/><category term="English"/><category term="R para Principiantes"/><category term="SQL"/><category term="Data frame"/><category term="Gráficos"/><category term="Estadística"/><category term="Tablas dinámicas"/><category term="Excel"/><category term="geom_boxplot"/><category term="sqldf"/><category term="RStudio"/><category term="boxplot"/><category term="geom_point"/><category term="mutate"/><category term="table"/><category term="tidyverse"/><category term="Aleatorio"/><category term="filter"/><category term="Distribución normal"/><category term="Formato"/><category term="data.table"/><category term="geom_bar"/><category term="Consulta"/><category term="Diagrama de caja"/><category term="Select"/><category term="apply"/><category term="as.Date"/><category term="Importación"/><category term="diagrama de dispersión"/><category term="seq"/><category term="theme"/><category term="Fórmulas matriciales"/><category term="IMDb"/><category term="summary"/><category term="Fichero de texto"/><category term="Formato condicional"/><category term="Frecuencias"/><category term="Project Euler"/><category term="R for beginners"/><category term="as.POSIXct"/><category term="group_by"/><category term="gsub"/><category term="prop.table"/><category term="psych"/><category term="stackoverflow"/><category term="Notepad++"/><category term="Tablas de contingencia"/><category term="facet_wrap"/><category term="geom_tile"/><category term="ifelse"/><category term="iris"/><category term="range"/><category term="xlabs"/><category term="%in%"/><category term="Error"/><category term="Matemáticas"/><category term="Min"/><category term="Regresión lineal"/><category term="fivenum"/><category term="identify"/><category term="labs"/><category term="legend"/><category term="median"/><category term="mtcars"/><category term="scale_fill_manual"/><category term="scatterplot"/><category term="subset"/><category term="Atajos"/><category term="Base de datos"/><category term="Datos externos"/><category term="Duplicados"/><category term="Duplicar"/><category term="Especificación de importación/exportación"/><category term="Exportar"/><category term="Google Drive"/><category term="Gráfico animado"/><category term="Hipervínculos"/><category term="Histograma"/><category term="ISLR"/><category term="Mejores prácticas"/><category term="Moda"/><category term="factor"/><category term="geom_smooth"/><category term="left_join"/><category term="loop"/><category term="reshape2"/><category term="sample"/><category term="scale_y_continuous"/><category term="set.seed"/><category term="stat_boxplot"/><category term="strsplit"/><category term="t"/><category term="transform"/><category term="unique"/><category term="Agrupar"/><category term="Autoformas"/><category term="Buscar y Remplazar"/><category term="CASE WHEN"/><category term="Contar.si"/><category term="Distinct"/><category term="Fechas"/><category term="Gráfico Q-Q"/><category term="Listas desplegables"/><category term="Mediana"/><category term="Muestra aleatoria"/><category term="RCurl"/><category term="Word"/><category term="cbind"/><category term="coalesce"/><category term="curve"/><category term="describeBy"/><category term="find_by_title"/><category term="ftable"/><category term="geom_ribbon"/><category term="getURLContent"/><category term="gráfico de barras"/><category term="headTail"/><category term="imdbapi"/><category term="legend.margin"/><category term="legend.position"/><category term="list"/><category term="mpg"/><category term="names"/><category term="nrow"/><category term="outer"/><category term="persp"/><category term="points"/><category term="rasterImage"/><category term="readJPEG"/><category term="read_csv"/><category term="readr"/><category term="recta de regresión"/><category term="scale_x_continuous"/><category term="segments"/><category term="strftime"/><category term="sum"/><category term="trans3d"/><category term="txt"/><category term="Benford"/><category term="Cadena"/><category term="Comentarios"/><category term="Comments"/><category term="Contar"/><category term="DIASEM"/><category term="Decimales"/><category term="Días"/><category term="Environ"/><category term="Fecha"/><category term="Fibonacci"/><category term="Invertir"/><category term="MASS"/><category term="Macro"/><category term="Max"/><category term="Media"/><category term="Ordenar"/><category term="Origen de datos"/><category term="PowerPoint"/><category term="Rango"/><category term="Reemplazar"/><category term="SQLite"/><category term="Subconsultas"/><category term="Tabla"/><category term="Texto"/><category term="Total acumulado"/><category term="UDF"/><category term="Vínculos"/><category term="aggregate"/><category term="alpha"/><category term="csv"/><category term="cut"/><category term="duplicated"/><category term="expand.grid"/><category term="facet_grid"/><category term="formato largo a ancho"/><category term="gather"/><category term="ggplotly"/><category term="igraph"/><category term="inner join"/><category term="lapply"/><category term="length"/><category term="levels"/><category term="lm"/><category term="loess"/><category term="matrix"/><category term="merge"/><category term="numbers"/><category term="números primos"/><category term="plot"/><category term="plotly"/><category term="rep"/><category term="rowwise"/><category term="sample_n"/><category term="split"/><category term="stat_smooth"/><category term="strReverse"/><category term="sumproduct"/><category term="transponer"/><category term="which"/><category term="write.csv"/><category term="Aleatorio.entre"/><category term="Animación"/><category term="Análisis de datos"/><category term="Autoajustar anchos de columna"/><category term="Boole"/><category term="Buscarv"/><category term="Campo calculado"/><category term="ChickWeight"/><category term="Clasificar"/><category term="Clearcomments"/><category term="Color"/><category term="Complementos de Excel"/><category term="Conditional formatting"/><category term="Consulta de unión"/><category term="Consulta eliminación"/><category term="Cuadro combinado"/><category term="Dummy"/><category term="Elementos únicos"/><category term="Eliminar duplicados"/><category term="Entero"/><category term="Etiquetar"/><category term="Excel 2013"/><category term="Formularios"/><category term="Fracciones"/><category term="Fuentes web"/><category term="Función en R"/><category term="Fórmulas"/><category term="Google Analytics"/><category term="Google Docs"/><category term="Gráficos Excel"/><category term="Guardar"/><category term="Hash"/><category term="Herramientas para análisis"/><category term="ISOdate"/><category term="If"/><category term="Ilusión óptica"/><category term="Imagen"/><category term="Income"/><category term="Intervalos"/><category term="Jerarquía"/><category term="Listas personalizadas"/><category term="Mes"/><category term="Modo exclusivo"/><category term="Mostrar valores como"/><category term="Ms Access para principiantes"/><category term="MsgBox"/><category term="NA"/><category term="Notepad"/><category term="Producto cartesiano"/><category term="RODBC"/><category term="Redondear"/><category term="Relleno rápido"/><category term="Rosalind"/><category term="SHA-256"/><category term="Si"/><category term="SiInm"/><category term="Sistema de ecuaciones"/><category term="Suma"/><category term="Sys.Date"/><category term="Traducción"/><category term="Union Query"/><category term="UsedRange"/><category term="UserName"/><category term="VBE"/><category term="Validation"/><category term="With"/><category term="Worksheets"/><category term="XKCD"/><category term="addNA"/><category term="aspect.ratio"/><category term="autofiltro"/><category term="ave"/><category term="barplot"/><category term="between"/><category term="bind_cols"/><category term="boxplot.stats"/><category term="calendarHeat"/><category term="caret"/><category term="coef"/><category term="colMeans"/><category term="colSums"/><category term="colnames"/><category term="combinaciones"/><category term="comma"/><category term="complete.cases"/><category term="coord_cartesian"/><category term="coord_equal"/><category term="coord_flip"/><category term="coord_map"/><category term="count"/><category term="createDataPartition"/><category term="cross join"/><category term="datasets"/><category term="date"/><category term="date_format"/><category term="difftime"/><category term="dput"/><category term="droplevels"/><category term="everything"/><category term="expand"/><category term="fct_rev"/><category term="forcats"/><category term="fread"/><category term="function"/><category term="gam"/><category term="generator"/><category term="geom_histogram"/><category term="geom_hline"/><category term="geom_jitter"/><category term="geom_label"/><category term="geom_pointrante"/><category term="geom_polygon"/><category term="geom_rect"/><category term="geom_segment"/><category term="geom_text"/><category term="geom_violin"/><category term="geom_vline"/><category term="getData"/><category term="getSunlightTimes"/><category term="getSymbols"/><category term="ggbeeswarm"/><category term="ggrepl"/><category term="grepl"/><category term="grid"/><category term="grid.arrange"/><category term="gridExtra"/><category term="head"/><category term="heatmap"/><category term="hojas"/><category term="installr"/><category term="interaction"/><category term="joins"/><category term="lag"/><category term="legend.justification"/><category term="legend.spacing.x"/><category term="legend.text"/><category term="legend.title"/><category term="like"/><category term="log"/><category term="lower.tri"/><category term="lubridate"/><category term="mLCM"/><category term="margin"/><category term="match"/><category term="mfrow"/><category term="mgcv"/><category term="microbenchmark"/><category term="modeest"/><category term="one_of"/><category term="packages"/><category term="par"/><category term="paste"/><category term="plyr"/><category term="pottery"/><category term="r_email_addresses"/><category term="raster"/><category term="read."/><category term="read.csv"/><category term="read_csv2"/><category term="read_delim"/><category term="read_tsv"/><category term="rename"/><category term="reorder"/><category term="rep_len"/><category term="round"/><category term="rownames"/><category term="rvest"/><category term="sapply"/><category term="scale_colour_gradient"/><category term="scale_colour_manual"/><category term="scale_fill_distiller"/><category term="scale_size_manual"/><category term="scale_x_datetime"/><category term="scale_x_discrete"/><category term="scales"/><category term="setNames"/><category term="slice"/><category term="solve"/><category term="splines"/><category term="stat_density_2d"/><category term="stat_function"/><category term="stat_qq"/><category term="stat_qq_line"/><category term="stratified"/><category term="stri_rand_strings"/><category term="stringi"/><category term="subconjunto"/><category term="subtotales"/><category term="suffix"/><category term="summarise"/><category term="suncalc"/><category term="tail"/><category term="tensor product"/><category term="theme_minimal"/><category term="tidyquant"/><category term="tidyr"/><category term="trees"/><category term="unlist"/><category term="unstack"/><category term="upper.tri"/><category term="vlookup"/><category term="weighted.mean"/><category term="xlab"/><category term=".Last.value"/><category term="ADO"/><category term="Advertising"/><category term="Ajustar texto"/><category term="Atom"/><category term="Attach"/><category term="Autoejecutable"/><category term="Autonumeración"/><category term="Ayuda"/><category term="Año"/><category term="Años"/><category term="Barra desplazamiento"/><category term="Batch"/><category term="Bloc de notas"/><category term="Buscar al teclear"/><category term="Búsqueda parcial"/><category term="CCur"/><category term="CDbl"/><category term="CONTARA"/><category term="Cadena de texto"/><category term="Caracter"/><category term="Cartesian product"/><category term="Carácter"/><category term="Case"/><category term="Categoría"/><category term="Clave principal"/><category term="Combinación cruzada"/><category term="Comillas"/><category term="Compactar"/><category term="Comparar ficheros"/><category term="Concatenar"/><category term="Conmutador"/><category term="Consulta combinada"/><category term="Consulta de actualización"/><category term="Consulta de parámetros"/><category term="Contraste de hipótesis"/><category term="Controlador de relleno"/><category term="Conversor"/><category term="Corpus"/><category term="Correlación"/><category term="Criterios"/><category term="CrossTable"/><category term="Cuadrado de la suma"/><category term="Cámara"/><category term="DAX"/><category term="DETECTLANGUAGE"/><category term="DIA"/><category term="Delete"/><category term="DisplayZeros"/><category term="Distinctrow"/><category term="Distribución beta"/><category term="Distribución de frecuencias"/><category term="EXACT"/><category term="Ecuación de segundo grado"/><category term="Ejes"/><category term="El Quijote"/><category term="Encad"/><category term="Encontrar"/><category term="Esnumero"/><category term="Estadísticas descriptivas"/><category term="Excel 2003"/><category term="Excel 2007"/><category term="Excel 2010"/><category term="FileSystemObject"/><category term="Filtro"/><category term="Find in Files"/><category term="Format"/><category term="Fraction"/><category term="Función"/><category term="Función resumen"/><category term="GIF"/><category term="GOOGLETRANSLATE"/><category term="Git"/><category term="GitHub"/><category term="Google Reader"/><category term="Google Sets"/><category term="Google Trends"/><category term="Gráfico de línea"/><category term="HTML"/><category term="Hallar"/><category term="Herramientas de imagen"/><category term="Hmisc"/><category term="Hojas de cálculo de Google"/><category term="Hora"/><category term="Hyperlinks"/><category term="IMPORTARDATOSDINAMICOS"/><category term="INDEX"/><category term="ISBLANK"/><category term="Indirecto"/><category term="InputBox"/><category term="Lanzamiento de una moneda"/><category term="MINUTO"/><category term="MULTIPLO.INFERIOR.MAT"/><category term="MacroOptions"/><category term="Mapa"/><category term="Matemáticas financieras"/><category term="Medidas de tendencia central"/><category term="Meses"/><category term="Minería de textos"/><category term="Minigráficos"/><category term="Modelo de datos"/><category term="Modo predeterminado de apertura"/><category term="Negativos"/><category term="Nombres definidos"/><category term="Notas de una presentación"/><category term="Nz"/><category term="Números aleatorios"/><category term="Office"/><category term="Options"/><category term="POSIXct"/><category term="Path"/><category term="Pegado especial"/><category term="Pegar"/><category term="Picture"/><category term="PowerPivot"/><category term="Prestige"/><category term="Problema"/><category term="Proteger hoja"/><category term="Quitar fondo"/><category term="RSS"/><category term="RcppRoll"/><category term="Redondeo del banquero"/><category term="Reducir tamaño"/><category term="Regex"/><category term="Regexp"/><category term="Registros únicos"/><category term="Residuo"/><category term="Resto"/><category term="SQL para principiantes"/><category term="SUMAPRODUCTO"/><category term="SWITCH"/><category term="ScreenUpdating"/><category term="Select Case"/><category term="Selectorgadget"/><category term="Semana Santa"/><category term="Series"/><category term="Shapiro-Wilk"/><category term="Smarket"/><category term="Statistics"/><category term="Suma de los cuadrados"/><category term="Sumar"/><category term="Superponer"/><category term="Tablas de proporciones"/><category term="Tabulación cruzada"/><category term="Term Document Matrix"/><category term="ThisWorkbook.Path"/><category term="ToothGrowth"/><category term="Totales"/><category term="UN"/><category term="URL"/><category term="UTF-8"/><category term="Unicode"/><category term="Union All Query"/><category term="WScript object"/><category term="When"/><category term="WorkbookConnection"/><category term="XML"/><category term="annotate"/><category term="any"/><category term="anyNA"/><category term="as.character"/><category term="as.numeric"/><category term="attr"/><category term="axis"/><category term="barras de error"/><category term="bivariate"/><category term="botones desplazamiento"/><category term="car"/><category term="case_when"/><category term="celdas visibles"/><category term="comandos"/><category term="comf"/><category term="compare"/><category term="conjuntos de datos"/><category term="convert"/><category term="copia de seguridad"/><category term="cor"/><category term="cor.test"/><category term="cowplot"/><category term="cuartil"/><category term="date week number"/><category term="dcast"/><category term="decimal"/><category term="dget"/><category term="diamonds"/><category term="digest"/><category term="dplyr.splitstackshape"/><category term="edit"/><category term="errorbar"/><category term="extrafont"/><category term="fill"/><category term="fix"/><category term="formato personalizado"/><category term="fortify"/><category term="geom_freqpoly"/><category term="geom_line"/><category term="geom_point labs"/><category term="geom_text_repel"/><category term="geoom_point"/><category term="gglot2"/><category term="ggrepel"/><category term="ggtitle"/><category term="gmodels"/><category term="gpglot"/><category term="gtrendsR"/><category term="hillShade"/><category term="hist"/><category term="identical"/><category term="idiomas"/><category term="imágenes"/><category term="interpolation"/><category term="intersect"/><category term="intervalo de confianza"/><category term="is.na"/><category term="leaflet"/><category term="libros recientes"/><category term="list.files."/><category term="listar"/><category term="logarithmic"/><category term="logarítmica"/><category term="lp"/><category term="lpSolve"/><category term="mGCD"/><category term="machine learning"/><category term="manipulate"/><category term="map_data"/><category term="matrices"/><category term="matriz de correlación"/><category term="mean"/><category term="melt"/><category term="month.abb"/><category term="month.name"/><category term="mutate_each"/><category term="n-grams"/><category term="ntile"/><category term="number"/><category term="nycflights13"/><category term="número de ocurrencias"/><category term="one of"/><category term="opciones avanzadas"/><category term="order"/><category term="pares"/><category term="paste0"/><category term="pipe operator"/><category term="polyroot"/><category term="predict"/><category term="primeFactors"/><category term="prueba t de Student"/><category term="purrr"/><category term="qda"/><category term="quartile"/><category term="random"/><category term="rango no contiguo"/><category term="rbind"/><category term="rcorr"/><category term="read.table"/><category term="regular expressions"/><category term="rnorm"/><category term="roll_mean"/><category term="rollmean"/><category term="rowMeans"/><category term="rowSums"/><category term="row_number"/><category term="runif"/><category term="sample_frac. sample"/><category term="sampling"/><category term="scale"/><category term="scale_fill_viridis_c"/><category term="scan"/><category term="setdiff"/><category term="sort"/><category term="splitstackshape"/><category term="spread"/><category term="sprintf"/><category term="stat_boxplot. labs"/><category term="stringr"/><category term="sub"/><category term="subgrupos"/><category term="sumary"/><category term="swirl"/><category term="swiss"/><category term="system of linear equations"/><category term="tableGrob"/><category term="tau"/><category term="terrain"/><category term="theme labs"/><category term="theme_bw"/><category term="theme_xkcd"/><category term="tibble"/><category term="time"/><category term="tipos de datos"/><category term="tm"/><category term="tm_raster"/><category term="tm_shape"/><category term="tmap"/><category term="toString"/><category term="ungroup"/><category term="updat"/><category term="updateR"/><category term="validación de datos"/><category term="valor p"/><category term="vectores"/><category term="weathermetrics"/><category term="within"/><category term="wordcloud"/><category term="xlsb"/><category term="xtabs"/><category term="zoo"/><title type='text'>Nube de datos</title><subtitle type='html'>R, Excel, Access, VBA and SQL.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default?start-index=26&amp;max-results=25'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>600</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-21694095.post-8613042990000782899</id><published>2022-02-07T17:41:00.002+01:00</published><updated>2022-02-07T17:46:58.963+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="DAX"/><category scheme="http://www.blogger.com/atom/ns#" term="Ms Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="weighted.mean"/><title type='text'>How to calculate weighted average in Pivot Table in Excel</title><content type='html'>&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;

  &lt;style type=&quot;text/css&quot;&gt;
    body, td {
       font-family: sans-serif;
       background-color: white;
       font-size: 12px;
       margin: 8px;
    }

    tt, code, pre {
       font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
    }

    h1 {
       font-size:2.2em;
    }

    h2 {
       font-size:1.8em;
    }

    h3 {
       font-size:1.4em;
    }

    h4 {
       font-size:1.0em;
    }

    h5 {
       font-size:0.9em;
    }

    h6 {
       font-size:0.8em;
    }

    a:visited {
       color: #2288bb;
    }


    pre {
       margin-top: 0;
       max-width: 95%;
       border: 1px solid #ccc;
       white-space: pre-wrap;
    }

    pre code {
       display: block; padding: 0.5em;
    }

    code.r, code.cpp {
       background-color: #F8F8F8;
    }

    table, td, th {
      border: none;
    }

    blockquote {
       color:#666666;
       margin:0;
       padding-left: 1em;
       border-left: 0.5em #EEE solid;
    }

    hr {
       height: 0px;
       border-bottom: none;
       border-top-width: thin;
       border-top-style: dotted;
       border-top-color: #999999;
    }

    @media print {
       * {
          background: transparent !important;
          color: black !important;
          filter:none !important;
          -ms-filter: none !important;
       }

       body {
          font-size:12pt;
          max-width:100%;
       }

       a, a:visited {
          text-decoration: underline;
       }

       hr {
          visibility: hidden;
          page-break-before: always;
       }

       pre, blockquote {
          padding-right: 1em;
          page-break-inside: avoid;
       }

       tr, img {
          page-break-inside: avoid;
       }

       img {
          max-width: 100% !important;
       }

       @page :left {
          margin: 15mm 20mm 15mm 10mm;
       }

       @page :right {
          margin: 15mm 10mm 15mm 20mm;
       }

       p, h2, h3 {
          orphans: 3; widows: 3;
       }

       h2, h3 {
          page-break-after: avoid;
       }
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- R syntax highlighter --&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
    hljs.initHighlightingOnLoad();
  &lt;/script&gt;
&lt;/head&gt;

&lt;h3&gt;Problem&lt;/h3&gt;
&lt;p&gt;

We would like to calculate the weighted average in a pivot table in Excel.

  
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh_KNkabgQld0FfSiu06SkCW61nM4dxPf0tJ9U4sI2IyYnGJQWZejmQAP-7iy0IyIaI9WchQ_LXDIRGvaSMwpW_aNvwPjB8Ks_ODjWwMvn1QpvZAZNHOvHPpxbG-KL-2agq5weS6eDk1AAhkWbSsL1DmIL8LnTcLw4CK23VGfojzDXj9C1Xmms&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;207&quot; data-original-width=&quot;490&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh_KNkabgQld0FfSiu06SkCW61nM4dxPf0tJ9U4sI2IyYnGJQWZejmQAP-7iy0IyIaI9WchQ_LXDIRGvaSMwpW_aNvwPjB8Ks_ODjWwMvn1QpvZAZNHOvHPpxbG-KL-2agq5weS6eDk1AAhkWbSsL1DmIL8LnTcLw4CK23VGfojzDXj9C1Xmms&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

In our example, using the &lt;a href=&quot;https://gist.github.com/seankross/a412dfbd88b3db70b74b&quot; target=&quot;_blank&quot;&gt; mtcars data set&lt;/a&gt;, we want to calculate the mpg average weighted by dips.


&lt;p&gt;

&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

Let&#39;s see two alternatives:


  &lt;li&gt;Option1: Adding a column.&lt;/li&gt;
  
   &lt;ol&gt;
  &lt;li&gt;We add a new columng multiplying the variable (mpg) by the weights (disp)&lt;/li&gt;  
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgyeHD8nG8yA7FrOHyK9UtLoqUXwD3xWKPiH6H78N0QnrbC6viQeSqZi8fxp32NQdFw9gy5XPhRR_0MeE_LS9Yft_qZLp7Rb4Qs-3XJ1mB9ZqrR7MOxRyTykubqgbFIpmAnzZpVoFe3KXkYsS5LthCTY9y-ZqAMwwU1jsd7Wzhl3YoNaPLwk5s&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;211&quot; data-original-width=&quot;571&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgyeHD8nG8yA7FrOHyK9UtLoqUXwD3xWKPiH6H78N0QnrbC6viQeSqZi8fxp32NQdFw9gy5XPhRR_0MeE_LS9Yft_qZLp7Rb4Qs-3XJ1mB9ZqrR7MOxRyTykubqgbFIpmAnzZpVoFe3KXkYsS5LthCTY9y-ZqAMwwU1jsd7Wzhl3YoNaPLwk5s&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
&lt;li&gt;We create a Calculated Field dividing the new column (mpg*disp) by the weights (disp) &lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjIV02FKw6nG6iEMY_EO8wrOWvBq_yOjL_y1wvWCdAxerTxgTbc1joaU7NlAfWOgnrQKDJT-JjqDRs_omE6dvrYstKv789R5TfEOPFkv1rvBW5Bdo6_HJ2VeYFRkLSao1Qdq9fsUx24uEdjQn7jdsR_N3W8Nx3BfBJHI9NQ-eScANhHcWfJDtM&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;312&quot; data-original-width=&quot;453&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjIV02FKw6nG6iEMY_EO8wrOWvBq_yOjL_y1wvWCdAxerTxgTbc1joaU7NlAfWOgnrQKDJT-JjqDRs_omE6dvrYstKv789R5TfEOPFkv1rvBW5Bdo6_HJ2VeYFRkLSao1Qdq9fsUx24uEdjQn7jdsR_N3W8Nx3BfBJHI9NQ-eScANhHcWfJDtM&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

 &lt;li&gt;We create a pivot table adding the Calculated Field.&lt;/li&gt;

     
     &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgYWjT9EaYgyNis0nEcuqNloCMsU0PtYYTJM-pXMeuaPD-RqivoiDGIs6sDTik5gJRwLD_FBNm_V55oaZFU1Mkplsx1WOOpdYTLtTh5Hpj1VrKRJTRVMVwjsK-LFMcVyhuT0TghP7heBS9YvpxoO-1XB9ySnIrtT2nopj7Ama1cmVCdvrFAFrI&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;94&quot; data-original-width=&quot;238&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgYWjT9EaYgyNis0nEcuqNloCMsU0PtYYTJM-pXMeuaPD-RqivoiDGIs6sDTik5gJRwLD_FBNm_V55oaZFU1Mkplsx1WOOpdYTLtTh5Hpj1VrKRJTRVMVwjsK-LFMcVyhuT0TghP7heBS9YvpxoO-1XB9ySnIrtT2nopj7Ama1cmVCdvrFAFrI&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
     
      &lt;/ol&gt;

    
&lt;p&gt;
&lt;li&gt;Option 2: Using a DAX functions. &lt;/li&gt;
  
 &lt;ol&gt;
  &lt;li&gt;We add the table to the Data Model.&lt;/li&gt;  

     
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjlz3E5_qciyH7Cx7kgqjK4u7MBtMS7TKsPbhdgG2TGgtZaeFYVXgIyhTpRQQKBMPniSHnHgO_2iZgbK6u_gPF88-M5HQFAZmdFBme9gQ1v97ORlUfyPsl5BruHy5VbYX2VVR6iuppCx63Q0ig_FSwEUFClmtWUfH1AKqfFo90x-mANuO9mmrI&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;132&quot; data-original-width=&quot;412&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjlz3E5_qciyH7Cx7kgqjK4u7MBtMS7TKsPbhdgG2TGgtZaeFYVXgIyhTpRQQKBMPniSHnHgO_2iZgbK6u_gPF88-M5HQFAZmdFBme9gQ1v97ORlUfyPsl5BruHy5VbYX2VVR6iuppCx63Q0ig_FSwEUFClmtWUfH1AKqfFo90x-mANuO9mmrI&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
     
&lt;li&gt;We create a new Measure. &lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjYa1hThEyh2Q5W7wuu3GkO_elFcvQGWEp4Laoo4IYu-gAtD3UpbOuatdqpx3QBWoXSRF04LO28twM0XCD8YBrQJ8Yqt3uyvxOkp5CHcjhCMH0wT_8d2XCLo-8HwulmAUzCuHqSx6Ho7Pwi33R7UsStr_wLSj8uuNBfqr7CWxx-dmgHlxuEt2s&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;119&quot; data-original-width=&quot;610&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjYa1hThEyh2Q5W7wuu3GkO_elFcvQGWEp4Laoo4IYu-gAtD3UpbOuatdqpx3QBWoXSRF04LO28twM0XCD8YBrQJ8Yqt3uyvxOkp5CHcjhCMH0wT_8d2XCLo-8HwulmAUzCuHqSx6Ho7Pwi33R7UsStr_wLSj8uuNBfqr7CWxx-dmgHlxuEt2s&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
     
&lt;pre class=&quot;prettyprint lang-vb&quot;&gt;weighted_average:=SUMX( Table1,[mpg] * [disp]) / SUM([disp])
&lt;/pre&gt;


 &lt;li&gt;We create a pivot table from Data Model as a data source adding the previous Measure.&lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhR_nj0eEp620Vp7zq9q9u8FpW7Sxfk5bzWZ1PlE0GwzwxZtmxALXNug2GlNitRkZ5w8gYSM-M3KpYK9_kbXarsP1AlU0SSWbUjjv5jrIXp0rdGy3QMSTX3Af8WNldchPWp6aMMGA2y_GUiA-OIMw9vm-VonAF12t7Jtzjz9Iu8LNqQju555Ds&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;94&quot; data-original-width=&quot;234&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhR_nj0eEp620Vp7zq9q9u8FpW7Sxfk5bzWZ1PlE0GwzwxZtmxALXNug2GlNitRkZ5w8gYSM-M3KpYK9_kbXarsP1AlU0SSWbUjjv5jrIXp0rdGy3QMSTX3Af8WNldchPWp6aMMGA2y_GUiA-OIMw9vm-VonAF12t7Jtzjz9Iu8LNqQju555Ds&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
     
 &lt;/ol&gt;

 &lt;/ul&gt;
  
&lt;h3&gt;Related posts&lt;/h3&gt;&lt;p&gt;
  
&lt;ul&gt;
 &lt;li&gt; &lt;a href=&quot;https://nubededatos.blogspot.com/2018/06/media-aritmetica-ponderada-en-r.html&quot;&gt;Media aritmética ponderada en R&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;

&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://gist.github.com/seankross/a412dfbd88b3db70b74b&quot; target=&quot;_blank&quot;&gt; mtcars data set&lt;/a&gt;&lt;/li&gt;
  
  &lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/8613042990000782899/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2022/02/how-to-calculate-weighted-average-in.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/8613042990000782899'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/8613042990000782899'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2022/02/how-to-calculate-weighted-average-in.html' title='How to calculate weighted average in Pivot Table in Excel'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEh_KNkabgQld0FfSiu06SkCW61nM4dxPf0tJ9U4sI2IyYnGJQWZejmQAP-7iy0IyIaI9WchQ_LXDIRGvaSMwpW_aNvwPjB8Ks_ODjWwMvn1QpvZAZNHOvHPpxbG-KL-2agq5weS6eDk1AAhkWbSsL1DmIL8LnTcLw4CK23VGfojzDXj9C1Xmms=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-7291506588642880690</id><published>2022-02-04T16:45:00.003+01:00</published><updated>2022-02-07T17:46:13.338+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Media"/><category scheme="http://www.blogger.com/atom/ns#" term="Ms Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Tablas dinámicas"/><title type='text'>Cómo calcular la media ponderada en tablas dinámicas en Excel</title><content type='html'>&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;

  &lt;style type=&quot;text/css&quot;&gt;
    body, td {
       font-family: sans-serif;
       background-color: white;
       font-size: 12px;
       margin: 8px;
    }

    tt, code, pre {
       font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
    }

    h1 {
       font-size:2.2em;
    }

    h2 {
       font-size:1.8em;
    }

    h3 {
       font-size:1.4em;
    }

    h4 {
       font-size:1.0em;
    }

    h5 {
       font-size:0.9em;
    }

    h6 {
       font-size:0.8em;
    }

    a:visited {
       color: #2288bb;
    }


    pre {
       margin-top: 0;
       max-width: 95%;
       border: 1px solid #ccc;
       white-space: pre-wrap;
    }

    pre code {
       display: block; padding: 0.5em;
    }

    code.r, code.cpp {
       background-color: #F8F8F8;
    }

    table, td, th {
      border: none;
    }

    blockquote {
       color:#666666;
       margin:0;
       padding-left: 1em;
       border-left: 0.5em #EEE solid;
    }

    hr {
       height: 0px;
       border-bottom: none;
       border-top-width: thin;
       border-top-style: dotted;
       border-top-color: #999999;
    }

    @media print {
       * {
          background: transparent !important;
          color: black !important;
          filter:none !important;
          -ms-filter: none !important;
       }

       body {
          font-size:12pt;
          max-width:100%;
       }

       a, a:visited {
          text-decoration: underline;
       }

       hr {
          visibility: hidden;
          page-break-before: always;
       }

       pre, blockquote {
          padding-right: 1em;
          page-break-inside: avoid;
       }

       tr, img {
          page-break-inside: avoid;
       }

       img {
          max-width: 100% !important;
       }

       @page :left {
          margin: 15mm 20mm 15mm 10mm;
       }

       @page :right {
          margin: 15mm 10mm 15mm 20mm;
       }

       p, h2, h3 {
          orphans: 3; widows: 3;
       }

       h2, h3 {
          page-break-after: avoid;
       }
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- R syntax highlighter --&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
    hljs.initHighlightingOnLoad();
  &lt;/script&gt;
&lt;/head&gt;

&lt;h3&gt;Problema&lt;/h3&gt;
&lt;p&gt;

Queremos calcular la media ponderada dentro de una tabla dinámica en Excel.
  
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh_KNkabgQld0FfSiu06SkCW61nM4dxPf0tJ9U4sI2IyYnGJQWZejmQAP-7iy0IyIaI9WchQ_LXDIRGvaSMwpW_aNvwPjB8Ks_ODjWwMvn1QpvZAZNHOvHPpxbG-KL-2agq5weS6eDk1AAhkWbSsL1DmIL8LnTcLw4CK23VGfojzDXj9C1Xmms&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;207&quot; data-original-width=&quot;490&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEh_KNkabgQld0FfSiu06SkCW61nM4dxPf0tJ9U4sI2IyYnGJQWZejmQAP-7iy0IyIaI9WchQ_LXDIRGvaSMwpW_aNvwPjB8Ks_ODjWwMvn1QpvZAZNHOvHPpxbG-KL-2agq5weS6eDk1AAhkWbSsL1DmIL8LnTcLw4CK23VGfojzDXj9C1Xmms&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

En nuestro ejemplo, usando el conjunto de datos &lt;a href=&quot;https://gist.github.com/seankross/a412dfbd88b3db70b74b&quot; target=&quot;_blank&quot;&gt; mtcars &lt;/a&gt;, queremos calcular la media de mpg ponderada por disp. 

&lt;p&gt;

&lt;h3&gt;Solución&lt;/h3&gt;&lt;p&gt;

Vamos a ver dos alternativas:


  &lt;li&gt;Opción 1: Mediante una columna auxiliar.&lt;/li&gt;
  
   &lt;ol&gt;
  &lt;li&gt;Añadimos una columna auxiliar multiplicando la variable (mpg) por los pesos (disp)&lt;/li&gt;  
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgyeHD8nG8yA7FrOHyK9UtLoqUXwD3xWKPiH6H78N0QnrbC6viQeSqZi8fxp32NQdFw9gy5XPhRR_0MeE_LS9Yft_qZLp7Rb4Qs-3XJ1mB9ZqrR7MOxRyTykubqgbFIpmAnzZpVoFe3KXkYsS5LthCTY9y-ZqAMwwU1jsd7Wzhl3YoNaPLwk5s&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;211&quot; data-original-width=&quot;571&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgyeHD8nG8yA7FrOHyK9UtLoqUXwD3xWKPiH6H78N0QnrbC6viQeSqZi8fxp32NQdFw9gy5XPhRR_0MeE_LS9Yft_qZLp7Rb4Qs-3XJ1mB9ZqrR7MOxRyTykubqgbFIpmAnzZpVoFe3KXkYsS5LthCTY9y-ZqAMwwU1jsd7Wzhl3YoNaPLwk5s&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
&lt;li&gt;Creamos un campo calculado dividiendo la columna auxiliar (mpg*disp) por los pesos (disp) &lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg7IAXgTAdIJt-KBPBA93xtmaVx16gXxXw7DoQUET_GyVwiGydHH5Fdpk-mJb4ygRDe7RFTDJfD-K-BGLkBIKxT2rq5NaokLGt-k7EQC6SoaBVTEHhcxlsSZXWA0DToUFQz2jhuFfsKrQHzHZ1k839253scXJepx9PKi3miMVaBmnNtJXeEqmc&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;309&quot; data-original-width=&quot;472&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEg7IAXgTAdIJt-KBPBA93xtmaVx16gXxXw7DoQUET_GyVwiGydHH5Fdpk-mJb4ygRDe7RFTDJfD-K-BGLkBIKxT2rq5NaokLGt-k7EQC6SoaBVTEHhcxlsSZXWA0DToUFQz2jhuFfsKrQHzHZ1k839253scXJepx9PKi3miMVaBmnNtJXeEqmc&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

 &lt;li&gt;Creamos la tabla dinámica agrupando por el campo deseado &lt;/li&gt;

     
     &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgYWjT9EaYgyNis0nEcuqNloCMsU0PtYYTJM-pXMeuaPD-RqivoiDGIs6sDTik5gJRwLD_FBNm_V55oaZFU1Mkplsx1WOOpdYTLtTh5Hpj1VrKRJTRVMVwjsK-LFMcVyhuT0TghP7heBS9YvpxoO-1XB9ySnIrtT2nopj7Ama1cmVCdvrFAFrI&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;94&quot; data-original-width=&quot;238&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEgYWjT9EaYgyNis0nEcuqNloCMsU0PtYYTJM-pXMeuaPD-RqivoiDGIs6sDTik5gJRwLD_FBNm_V55oaZFU1Mkplsx1WOOpdYTLtTh5Hpj1VrKRJTRVMVwjsK-LFMcVyhuT0TghP7heBS9YvpxoO-1XB9ySnIrtT2nopj7Ama1cmVCdvrFAFrI&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
     
      &lt;/ol&gt;

    
&lt;p&gt;
&lt;li&gt;Opción 2: Con una fórmula DAX. &lt;/li&gt;
  
 &lt;ol&gt;
  &lt;li&gt;Agregamos la tabla original al modelo de datos. No es necesario crear una columna auxiliar.&lt;/li&gt;  

     
     &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhJ8i4BbPbiJLeEpqJSV_3gdYfbZ-OhxQID8cU_zJQSFN4E-lx_oIV9xQ7OuVe4JlOPSPJhtkPXE3ynjMkAttpXPDxKNl-eBSDHoQj6bvzrS5X5mSwo7fnrEdRKJdGyrVwp9aD-iAmwFhNR_KAo7fL4wdVA5CWqiz_GqMcfJ4Xft7r2vAduUAI&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;139&quot; data-original-width=&quot;491&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhJ8i4BbPbiJLeEpqJSV_3gdYfbZ-OhxQID8cU_zJQSFN4E-lx_oIV9xQ7OuVe4JlOPSPJhtkPXE3ynjMkAttpXPDxKNl-eBSDHoQj6bvzrS5X5mSwo7fnrEdRKJdGyrVwp9aD-iAmwFhNR_KAo7fL4wdVA5CWqiz_GqMcfJ4Xft7r2vAduUAI&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
     
&lt;li&gt;Creamos una nueva medida &lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjR2fb8YYqNwBSkXxZNGaNKqZ6hhOAtGRjhUTqJdJvkR0mw4VP6xK6zuoX7webrfBs9u9eyFZ2Cj2q3WVx5gpJ8QKCDo_eo8MgvVVm1E9422nTwQETkxEaoHV1YHfNNZNTU9iradwLAeyKHQdJ7UZvEXsdvJhn1sauq4HIXVeqfoaUgUeVt34g&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;123&quot; data-original-width=&quot;641&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEjR2fb8YYqNwBSkXxZNGaNKqZ6hhOAtGRjhUTqJdJvkR0mw4VP6xK6zuoX7webrfBs9u9eyFZ2Cj2q3WVx5gpJ8QKCDo_eo8MgvVVm1E9422nTwQETkxEaoHV1YHfNNZNTU9iradwLAeyKHQdJ7UZvEXsdvJhn1sauq4HIXVeqfoaUgUeVt34g&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
     
     
&lt;pre class=&quot;prettyprint lang-vb&quot;&gt;weighted_average:=SUMX( Table1,[mpg] * [disp]) / SUM([disp])
&lt;/pre&gt;


 &lt;li&gt;Creamos la tabla dinámica tomando como origen Desde Modelo de datos, usando la medida recién creada&lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhR_nj0eEp620Vp7zq9q9u8FpW7Sxfk5bzWZ1PlE0GwzwxZtmxALXNug2GlNitRkZ5w8gYSM-M3KpYK9_kbXarsP1AlU0SSWbUjjv5jrIXp0rdGy3QMSTX3Af8WNldchPWp6aMMGA2y_GUiA-OIMw9vm-VonAF12t7Jtzjz9Iu8LNqQju555Ds&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;94&quot; data-original-width=&quot;234&quot; src=&quot;https://blogger.googleusercontent.com/img/a/AVvXsEhR_nj0eEp620Vp7zq9q9u8FpW7Sxfk5bzWZ1PlE0GwzwxZtmxALXNug2GlNitRkZ5w8gYSM-M3KpYK9_kbXarsP1AlU0SSWbUjjv5jrIXp0rdGy3QMSTX3Af8WNldchPWp6aMMGA2y_GUiA-OIMw9vm-VonAF12t7Jtzjz9Iu8LNqQju555Ds&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
     
 &lt;/ol&gt;

 &lt;/ul&gt;
  
&lt;h3&gt;Entradas relacionadas&lt;/h3&gt;&lt;p&gt;
  
&lt;ul&gt;
 &lt;li&gt; &lt;a href=&quot;https://nubededatos.blogspot.com/2018/06/media-aritmetica-ponderada-en-r.html&quot;&gt;Media aritmética ponderada en R&lt;/a&gt; &lt;/li&gt;
  &lt;/ul&gt;
&lt;h3&gt;Referencias&lt;/h3&gt;&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;Conjunto de datos &lt;a href=&quot;https://gist.github.com/seankross/a412dfbd88b3db70b74b&quot; target=&quot;_blank&quot;&gt; mtcars &lt;/a&gt;&lt;/li&gt;
  
  &lt;/ul&gt;
 </content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/7291506588642880690/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2022/02/como-calcular-la-media-ponderada-en.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/7291506588642880690'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/7291506588642880690'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2022/02/como-calcular-la-media-ponderada-en.html' title='Cómo calcular la media ponderada en tablas dinámicas en Excel'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/a/AVvXsEh_KNkabgQld0FfSiu06SkCW61nM4dxPf0tJ9U4sI2IyYnGJQWZejmQAP-7iy0IyIaI9WchQ_LXDIRGvaSMwpW_aNvwPjB8Ks_ODjWwMvn1QpvZAZNHOvHPpxbG-KL-2agq5weS6eDk1AAhkWbSsL1DmIL8LnTcLw4CK23VGfojzDXj9C1Xmms=s72-c" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-3079169381078155306</id><published>2021-03-22T05:00:00.019+01:00</published><updated>2021-03-22T05:00:01.932+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Conditional formatting"/><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="Ms Excel"/><title type='text'> Ignore zero values in conditional formatting in Excel</title><content type='html'>&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;

  &lt;style type=&quot;text/css&quot;&gt;
    body, td {
       font-family: sans-serif;
       background-color: white;
       font-size: 12px;
       margin: 8px;
    }

    tt, code, pre {
       font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
    }

    h1 {
       font-size:2.2em;
    }

    h2 {
       font-size:1.8em;
    }

    h3 {
       font-size:1.4em;
    }

    h4 {
       font-size:1.0em;
    }

    h5 {
       font-size:0.9em;
    }

    h6 {
       font-size:0.8em;
    }

    a:visited {
       color: #2288bb;
    }


    pre {
       margin-top: 0;
       max-width: 95%;
       border: 1px solid #ccc;
       white-space: pre-wrap;
    }

    pre code {
       display: block; padding: 0.5em;
    }

    code.r, code.cpp {
       background-color: #F8F8F8;
    }

    table, td, th {
      border: none;
    }

    blockquote {
       color:#666666;
       margin:0;
       padding-left: 1em;
       border-left: 0.5em #EEE solid;
    }

    hr {
       height: 0px;
       border-bottom: none;
       border-top-width: thin;
       border-top-style: dotted;
       border-top-color: #999999;
    }

    @media print {
       * {
          background: transparent !important;
          color: black !important;
          filter:none !important;
          -ms-filter: none !important;
       }

       body {
          font-size:12pt;
          max-width:100%;
       }

       a, a:visited {
          text-decoration: underline;
       }

       hr {
          visibility: hidden;
          page-break-before: always;
       }

       pre, blockquote {
          padding-right: 1em;
          page-break-inside: avoid;
       }

       tr, img {
          page-break-inside: avoid;
       }

       img {
          max-width: 100% !important;
       }

       @page :left {
          margin: 15mm 20mm 15mm 10mm;
       }

       @page :right {
          margin: 15mm 10mm 15mm 20mm;
       }

       p, h2, h3 {
          orphans: 3; widows: 3;
       }

       h2, h3 {
          page-break-after: avoid;
       }
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- R syntax highlighter --&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
    hljs.initHighlightingOnLoad();
  &lt;/script&gt;
&lt;/head&gt;

&lt;h3&gt;Problem&lt;/h3&gt;
&lt;p&gt;

  
We want conditional formatting in Excel to ignore cells containing zero values. In the example below, after applying colour scales in conditional formatting, we can see that Excel applies red formatting to cells with zero values.
  
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKoxhnXDo3_p07fcEkq5ZVQaqAzh5TS5Qk55ClCWGojfD89V5lWmDwXFkmv06tC5H0TyT7uNnA7k8nYx6767WxnaXEal5te3qr8Xh5ZYrc5btLbAiQfqwJHtq03hwx6bBx3DS2BQ/s0/Screenshot_1.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;172&quot; data-original-width=&quot;270&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKoxhnXDo3_p07fcEkq5ZVQaqAzh5TS5Qk55ClCWGojfD89V5lWmDwXFkmv06tC5H0TyT7uNnA7k8nYx6767WxnaXEal5te3qr8Xh5ZYrc5btLbAiQfqwJHtq03hwx6bBx3DS2BQ/s0/Screenshot_1.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;



&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

To make conditional formatting ignore zero values, we follow these steps:
&lt;ol&gt;
  
&lt;li&gt;Create a new conditional formatting rule. &lt;/li&gt;
  
  
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrLN_5GtZLHy9TWbvfHj_IzIyx8m6cAVf41PdqwLcG6bgnIDBscMcMVUqh6rpImyaBPS_S5wvY83MwVU2aUNeH2UB6vz9TQsSM5OtyRxM3nbKMa3cZ0avc-cPnCCq6HVMSrXWqHQ/s0/Screenshot_6.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;411&quot; data-original-width=&quot;187&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrLN_5GtZLHy9TWbvfHj_IzIyx8m6cAVf41PdqwLcG6bgnIDBscMcMVUqh6rpImyaBPS_S5wvY83MwVU2aUNeH2UB6vz9TQsSM5OtyRxM3nbKMa3cZ0avc-cPnCCq6HVMSrXWqHQ/s0/Screenshot_6.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
&lt;li&gt;Apply no format to cells with value equal to 0. &lt;/li&gt;


&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPjIHciK9nzRay-vQv-CDrzAEmuuVUvO-cPFEWqFr1NEeK0r6Ig2MovvXfDYgi1wH-vZutl6EeDAZfTPumyEAZarD8G1Vw7Mq7SNdgqMHlVQLKGvyVF8PsGx5anTgHPVdqW5Lg1w/s0/Screenshot_7.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;361&quot; data-original-width=&quot;535&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPjIHciK9nzRay-vQv-CDrzAEmuuVUvO-cPFEWqFr1NEeK0r6Ig2MovvXfDYgi1wH-vZutl6EeDAZfTPumyEAZarD8G1Vw7Mq7SNdgqMHlVQLKGvyVF8PsGx5anTgHPVdqW5Lg1w/s0/Screenshot_7.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
 &lt;li&gt;Make sure that this rule is the first to be evaluated, and select the &lt;i&gt;Stop If True&lt;/i&gt; check box. &lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2TkhHR3Kz0JV1OnIfhv5SpF-hUl_ocMgoZ9FSPWMAh80hyEsnwmsoH7AL0Rc090NUhgbFOWen-FUBmEKvW-czHv09G4f2W6jL-utIXa5IHPNGIE9Sz9HYMZBeOpjBJzM3Od65mQ/s0/Screenshot_8.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;296&quot; data-original-width=&quot;835&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2TkhHR3Kz0JV1OnIfhv5SpF-hUl_ocMgoZ9FSPWMAh80hyEsnwmsoH7AL0Rc090NUhgbFOWen-FUBmEKvW-czHv09G4f2W6jL-utIXa5IHPNGIE9Sz9HYMZBeOpjBJzM3Od65mQ/s0/Screenshot_8.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
    
&lt;/ol&gt;


&lt;h3&gt;Results&lt;/h3&gt;&lt;p&gt;
  
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf0zlFxd4bp23GNDnthovrSTj_lal23KE7Z0fjTOIplTjmISqNsK67-YYMgDbfRxgZsnX-hsdTWoLdBFAWlz9oiVGWF6zcODIpsg8ZVfZJhuGfDBliiElhOqBJbW90fnYEzjGpUQ/s0/Screenshot_5.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;172&quot; data-original-width=&quot;272&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf0zlFxd4bp23GNDnthovrSTj_lal23KE7Z0fjTOIplTjmISqNsK67-YYMgDbfRxgZsnX-hsdTWoLdBFAWlz9oiVGWF6zcODIpsg8ZVfZJhuGfDBliiElhOqBJbW90fnYEzjGpUQ/s0/Screenshot_5.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
&lt;h3&gt;Related posts&lt;/h3&gt;&lt;p&gt;
  
&lt;a href=&quot;https://nubededatos.blogspot.com/search/label/Conditional%20formatting&quot;&gt;Formato condicional&lt;/a&gt;
  
&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;
&lt;a href=&quot;https://support.microsoft.com/en-gb/office/use-conditional-formatting-to-highlight-information-fed60dfa-1d3f-4e13-9ecb-f1951ff89d7f?ui=en-US&amp;amp;amp;rs=en-GB&amp;amp;amp;ad=GB&quot; target=&quot;_blank&quot;&gt;Use conditional formatting to highlight information&lt;/a&gt;

 </content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/3079169381078155306/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/03/ignore-zero-values-in-conditional.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3079169381078155306'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3079169381078155306'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/03/ignore-zero-values-in-conditional.html' title=' Ignore zero values in conditional formatting in Excel'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKoxhnXDo3_p07fcEkq5ZVQaqAzh5TS5Qk55ClCWGojfD89V5lWmDwXFkmv06tC5H0TyT7uNnA7k8nYx6767WxnaXEal5te3qr8Xh5ZYrc5btLbAiQfqwJHtq03hwx6bBx3DS2BQ/s72-c/Screenshot_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-9182627333625872072</id><published>2021-03-19T05:00:00.002+01:00</published><updated>2021-03-19T05:00:08.351+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Formato condicional"/><category scheme="http://www.blogger.com/atom/ns#" term="Ms Excel"/><title type='text'>Ignorar ceros en el formato condicional en Excel</title><content type='html'>&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;

  &lt;style type=&quot;text/css&quot;&gt;
    body, td {
       font-family: sans-serif;
       background-color: white;
       font-size: 12px;
       margin: 8px;
    }

    tt, code, pre {
       font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
    }

    h1 {
       font-size:2.2em;
    }

    h2 {
       font-size:1.8em;
    }

    h3 {
       font-size:1.4em;
    }

    h4 {
       font-size:1.0em;
    }

    h5 {
       font-size:0.9em;
    }

    h6 {
       font-size:0.8em;
    }

    a:visited {
       color: #2288bb;
    }


    pre {
       margin-top: 0;
       max-width: 95%;
       border: 1px solid #ccc;
       white-space: pre-wrap;
    }

    pre code {
       display: block; padding: 0.5em;
    }

    code.r, code.cpp {
       background-color: #F8F8F8;
    }

    table, td, th {
      border: none;
    }

    blockquote {
       color:#666666;
       margin:0;
       padding-left: 1em;
       border-left: 0.5em #EEE solid;
    }

    hr {
       height: 0px;
       border-bottom: none;
       border-top-width: thin;
       border-top-style: dotted;
       border-top-color: #999999;
    }

    @media print {
       * {
          background: transparent !important;
          color: black !important;
          filter:none !important;
          -ms-filter: none !important;
       }

       body {
          font-size:12pt;
          max-width:100%;
       }

       a, a:visited {
          text-decoration: underline;
       }

       hr {
          visibility: hidden;
          page-break-before: always;
       }

       pre, blockquote {
          padding-right: 1em;
          page-break-inside: avoid;
       }

       tr, img {
          page-break-inside: avoid;
       }

       img {
          max-width: 100% !important;
       }

       @page :left {
          margin: 15mm 20mm 15mm 10mm;
       }

       @page :right {
          margin: 15mm 10mm 15mm 20mm;
       }

       p, h2, h3 {
          orphans: 3; widows: 3;
       }

       h2, h3 {
          page-break-after: avoid;
       }
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- R syntax highlighter --&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
    hljs.initHighlightingOnLoad();
  &lt;/script&gt;
&lt;/head&gt;

&lt;h3&gt;Problema&lt;/h3&gt;
&lt;p&gt;

Queremos que Excel no aplique el formato condicional a las celdas cuyo valor sea 0. En el siguiente ejemplo vemos como, tras aplicar el formato condicional con escalas de colores, los ceros aparecen en rojo. 
 
  
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKoxhnXDo3_p07fcEkq5ZVQaqAzh5TS5Qk55ClCWGojfD89V5lWmDwXFkmv06tC5H0TyT7uNnA7k8nYx6767WxnaXEal5te3qr8Xh5ZYrc5btLbAiQfqwJHtq03hwx6bBx3DS2BQ/s0/Screenshot_1.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;172&quot; data-original-width=&quot;270&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKoxhnXDo3_p07fcEkq5ZVQaqAzh5TS5Qk55ClCWGojfD89V5lWmDwXFkmv06tC5H0TyT7uNnA7k8nYx6767WxnaXEal5te3qr8Xh5ZYrc5btLbAiQfqwJHtq03hwx6bBx3DS2BQ/s0/Screenshot_1.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;



&lt;h3&gt;Solución&lt;/h3&gt;&lt;p&gt;

Para evitar que aplique un formato condicional a los ceros seguimos los siguientes pasos:
&lt;ol&gt;
  
&lt;li&gt;Creamos una nueva regla. &lt;/li&gt;
  
  
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5JZFKPijdSnqwbt7RWcV9TgDxFY6hTrZaoieHNfF_RyKxt-WUbMKFX1jyznwd-GBIBRAEcYyZs-705BezrvjacvcgI9MVZ48XD6PWmit34PCX-nDPGQBhqZPdenn5HgtLYa31zg/s0/Screenshot_3.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;409&quot; data-original-width=&quot;312&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5JZFKPijdSnqwbt7RWcV9TgDxFY6hTrZaoieHNfF_RyKxt-WUbMKFX1jyznwd-GBIBRAEcYyZs-705BezrvjacvcgI9MVZ48XD6PWmit34PCX-nDPGQBhqZPdenn5HgtLYa31zg/s0/Screenshot_3.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
&lt;li&gt;No aplicamos ningún formato a las celdas cuyo valor sea 0. &lt;/li&gt;


&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiveUZAsy1lB6Kgv74qHvAblwpuQKSChCI8N-QU_9bikwgQqBBZ8PMbaZCUA9FN38yfJp1unsypmRbmskzE63BCCm6VL59zL2XKIa6y7hoRLBFMjUPP_d9glkM_biMG6IRdSYTk9Q/s0/Screenshot_2.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;357&quot; data-original-width=&quot;540&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiveUZAsy1lB6Kgv74qHvAblwpuQKSChCI8N-QU_9bikwgQqBBZ8PMbaZCUA9FN38yfJp1unsypmRbmskzE63BCCm6VL59zL2XKIa6y7hoRLBFMjUPP_d9glkM_biMG6IRdSYTk9Q/s0/Screenshot_2.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

  
 &lt;li&gt;Nos aseguramos de que es la primera regla evaluada y activamos la casilla &lt;i&gt;Detener si es verdad&lt;/i&gt;. &lt;/li&gt;

  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicjK-73M9wV92Y6tzTA2G3VIwRu3A2EeXf8MF2udGuWGfp0atK4ndgvDkuO0aBpoc1MnaRwQVTw9SWw1ty8BQP21xY_iktdU2qS9hkcZg5DVOOFQB0Ky2Zx3W1SFnuwATYThfqoQ/s0/Screenshot_4.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;289&quot; data-original-width=&quot;827&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicjK-73M9wV92Y6tzTA2G3VIwRu3A2EeXf8MF2udGuWGfp0atK4ndgvDkuO0aBpoc1MnaRwQVTw9SWw1ty8BQP21xY_iktdU2qS9hkcZg5DVOOFQB0Ky2Zx3W1SFnuwATYThfqoQ/s0/Screenshot_4.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
    
&lt;/ol&gt;


&lt;h3&gt;Resultado&lt;/h3&gt;&lt;p&gt;
  
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf0zlFxd4bp23GNDnthovrSTj_lal23KE7Z0fjTOIplTjmISqNsK67-YYMgDbfRxgZsnX-hsdTWoLdBFAWlz9oiVGWF6zcODIpsg8ZVfZJhuGfDBliiElhOqBJbW90fnYEzjGpUQ/s0/Screenshot_5.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;172&quot; data-original-width=&quot;272&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhf0zlFxd4bp23GNDnthovrSTj_lal23KE7Z0fjTOIplTjmISqNsK67-YYMgDbfRxgZsnX-hsdTWoLdBFAWlz9oiVGWF6zcODIpsg8ZVfZJhuGfDBliiElhOqBJbW90fnYEzjGpUQ/s0/Screenshot_5.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
&lt;h3&gt;Entradas relacionadas&lt;/h3&gt;&lt;p&gt;
  
&lt;a href=&quot;https://nubededatos.blogspot.com/search/label/Formato%20condicional&quot;&gt;Formato condicional&lt;/a&gt;

 </content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/9182627333625872072/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/03/ignorar-ceros-en-el-formato-condicional.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/9182627333625872072'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/9182627333625872072'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/03/ignorar-ceros-en-el-formato-condicional.html' title='Ignorar ceros en el formato condicional en Excel'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKoxhnXDo3_p07fcEkq5ZVQaqAzh5TS5Qk55ClCWGojfD89V5lWmDwXFkmv06tC5H0TyT7uNnA7k8nYx6767WxnaXEal5te3qr8Xh5ZYrc5btLbAiQfqwJHtq03hwx6bBx3DS2BQ/s72-c/Screenshot_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-5009477954590436692</id><published>2021-03-18T09:36:00.001+01:00</published><updated>2021-03-18T10:01:18.925+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="curve"/><category scheme="http://www.blogger.com/atom/ns#" term="function"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_hline"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_vline"/><category scheme="http://www.blogger.com/atom/ns#" term="ggplot2"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="stat_function"/><title type='text'>Cómo representar funciones en R</title><content type='html'>

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;
&lt;h3&gt;Problema&lt;/h3&gt;&lt;p&gt;
  
Queremos representar funciones en R. 
  


&lt;h3&gt;Solución&lt;/h3&gt;&lt;p&gt;

En nuestro ejemplo queremos representar la siguiente ecuación de segundo grado:

2x&lt;sup&gt;2&lt;/sup&gt; + 20x + 3 = 0

&lt;ul&gt;
&lt;li&gt;Opción 1: base package&lt;/li&gt;&lt;p&gt;
&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;f &lt;- function(x) {
  x ^ 2 + 20 * x + 3
}
curve(expr = f, from = -100, to = 100)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikZKHAlv_p05S9Zjg1Tzdg4zPQzjuzlBrEO27B0hkWPsGZ5mVuD09vZ4R4nfObhRayHZKVmo-CdydGMFwswvyHBCKSdOJebCpKx4UDZJSMCheMBg72GlthH60Sn8qEjKmypdd2Fw/s0/Screenshot_3.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;407&quot; data-original-width=&quot;489&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikZKHAlv_p05S9Zjg1Tzdg4zPQzjuzlBrEO27B0hkWPsGZ5mVuD09vZ4R4nfObhRayHZKVmo-CdydGMFwswvyHBCKSdOJebCpKx4UDZJSMCheMBg72GlthH60Sn8qEjKmypdd2Fw/s0/Screenshot_3.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;


&lt;li&gt;Opción 2: ggplot2&lt;/li&gt;&lt;p&gt;
  
&lt;p&gt;
&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(ggplot2)
ggplot(data.frame(x = c(-100, 100)), aes(x)) +
  stat_function(
    fun = function(x) {
      x ^ 2 + 20 * x + 3
    }
  ) +
  geom_hline(yintercept = 0) +
  geom_vline(xintercept = 0)

 &lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikb3QbS7BJPcLrjFNsjgym3V7JajMzxXsdXsnBxFX1ALZFRXvbNhPlfXwESeFPRvvRFu8ZzkoPR048YmusO3CyX7whvCjtnZ5NHCVu-nypG12YfjI6e5zM0EWQ1J-jO1K2TAeTIA/s0/Screenshot_4.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;481&quot; data-original-width=&quot;512&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikb3QbS7BJPcLrjFNsjgym3V7JajMzxXsdXsnBxFX1ALZFRXvbNhPlfXwESeFPRvvRFu8ZzkoPR048YmusO3CyX7whvCjtnZ5NHCVu-nypG12YfjI6e5zM0EWQ1J-jO1K2TAeTIA/s0/Screenshot_4.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;


&lt;/ul&gt;
&lt;h3&gt;Notas&lt;/h3&gt;&lt;p&gt;

Si queremos añadir más funciones:&lt;p&gt;
  &lt;ul&gt;
&lt;li&gt;Opción 1: Base package&lt;/li&gt;&lt;p&gt;
&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;f1 &lt;- function(x) {
  x ^ 2 + 20 * x + 3
}
f2 &lt;- function(x) {
  x ^ 2 + 50 * x + 100
}
curve(expr = f1, from = -100, to = 100)
curve(expr = f2, from = -100, to = 100, col  = 2, add = TRUE)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

    &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUgQsh9qk3Wnr0LmR1Nb0YI_rZ4Uh5GElc7QWeczGgUcvayMpQebIWQHd2c3jdiECO-Ifohxs4DHkD0RuyPyF03r8ohvXfl09HmdqTxv9NBlRV0Rb0LdWkrhg1SfhMJr2_Jp59gA/s0/Screenshot_5.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;409&quot; data-original-width=&quot;492&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUgQsh9qk3Wnr0LmR1Nb0YI_rZ4Uh5GElc7QWeczGgUcvayMpQebIWQHd2c3jdiECO-Ifohxs4DHkD0RuyPyF03r8ohvXfl09HmdqTxv9NBlRV0Rb0LdWkrhg1SfhMJr2_Jp59gA/s0/Screenshot_5.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

&lt;li&gt;Opción 2: ggplot2&lt;/li&gt;&lt;p&gt;
  
&lt;p&gt;
&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(data.frame(x = c(-100, 100)), aes(x)) +
  stat_function(
    fun = function(x) {
      x ^ 2 + 20 * x + 3
    }
  ) +
  stat_function(
    fun = function(x) {
      x ^ 2 + 50 * x + 100
    },
    colour = &quot;red&quot;
  ) +
  geom_hline(yintercept = 0) +
  geom_vline(xintercept = 0)
 &lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

    &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUJw_E5Ej0UTmVMt2c3IfvXg5FBqiYvzvsbbSo5I2pxGTT24uu1sNiCu3lnMqJzmcaQwHLvZfaabqNgG9Al_KgznXabi4mlEo6B_diS2fbPvpnEvRdWt2Md9bzT8YP3ErizrvKig/s0/Screenshot_6.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;518&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUJw_E5Ej0UTmVMt2c3IfvXg5FBqiYvzvsbbSo5I2pxGTT24uu1sNiCu3lnMqJzmcaQwHLvZfaabqNgG9Al_KgznXabi4mlEo6B_diS2fbPvpnEvRdWt2Md9bzT8YP3ErizrvKig/s0/Screenshot_6.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;


&lt;/ul&gt;
&lt;h3&gt;Entradas relacionadas&lt;/h3&gt;&lt;p&gt;


&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://nubededatos.blogspot.com/2015/06/resolver-ecuaciones-de-segundo-grado-en.html&quot;&gt;Resolver ecuaciones de segundo grado en R&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;Referencias&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;

&lt;li&gt;&lt;a href=&quot;https://ggplot2.tidyverse.org/reference/stat_function.html&quot; target=&quot;_blank&quot;&gt;ggplot2 reference&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;


</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/5009477954590436692/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/03/como-representar-funciones-en-r.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/5009477954590436692'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/5009477954590436692'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/03/como-representar-funciones-en-r.html' title='Cómo representar funciones en R'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikZKHAlv_p05S9Zjg1Tzdg4zPQzjuzlBrEO27B0hkWPsGZ5mVuD09vZ4R4nfObhRayHZKVmo-CdydGMFwswvyHBCKSdOJebCpKx4UDZJSMCheMBg72GlthH60Sn8qEjKmypdd2Fw/s72-c/Screenshot_3.png" height="72" width="72"/><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-382650931582204571</id><published>2021-03-16T12:27:00.000+01:00</published><updated>2021-03-16T12:27:15.980+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="curve"/><category scheme="http://www.blogger.com/atom/ns#" term="function"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_hline"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_vline"/><category scheme="http://www.blogger.com/atom/ns#" term="ggplot2"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="stat_function"/><title type='text'>How to plot functions in R</title><content type='html'>

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;
&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
  
We would like to plot functions in R. 
  


&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

In our example we will plot the following quadratic equation:
2x&lt;sup&gt;2&lt;/sup&gt; + 20x + 3 = 0

&lt;ul&gt;
&lt;li&gt;Option 1: base package&lt;/li&gt;&lt;p&gt;
&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;f &lt;- function(x) {
  x ^ 2 + 20 * x + 3
}
curve(expr = f, from = -100, to = 100)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikZKHAlv_p05S9Zjg1Tzdg4zPQzjuzlBrEO27B0hkWPsGZ5mVuD09vZ4R4nfObhRayHZKVmo-CdydGMFwswvyHBCKSdOJebCpKx4UDZJSMCheMBg72GlthH60Sn8qEjKmypdd2Fw/s0/Screenshot_3.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;407&quot; data-original-width=&quot;489&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikZKHAlv_p05S9Zjg1Tzdg4zPQzjuzlBrEO27B0hkWPsGZ5mVuD09vZ4R4nfObhRayHZKVmo-CdydGMFwswvyHBCKSdOJebCpKx4UDZJSMCheMBg72GlthH60Sn8qEjKmypdd2Fw/s0/Screenshot_3.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;


&lt;li&gt;Option 2: ggplot2&lt;/li&gt;&lt;p&gt;
  
&lt;p&gt;
&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(ggplot2)
ggplot(data.frame(x = c(-100, 100)), aes(x)) +
  stat_function(
    fun = function(x) {
      x ^ 2 + 20 * x + 3
    }
  ) +
  geom_hline(yintercept = 0) +
  geom_vline(xintercept = 0)

 &lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikb3QbS7BJPcLrjFNsjgym3V7JajMzxXsdXsnBxFX1ALZFRXvbNhPlfXwESeFPRvvRFu8ZzkoPR048YmusO3CyX7whvCjtnZ5NHCVu-nypG12YfjI6e5zM0EWQ1J-jO1K2TAeTIA/s0/Screenshot_4.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;481&quot; data-original-width=&quot;512&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikb3QbS7BJPcLrjFNsjgym3V7JajMzxXsdXsnBxFX1ALZFRXvbNhPlfXwESeFPRvvRFu8ZzkoPR048YmusO3CyX7whvCjtnZ5NHCVu-nypG12YfjI6e5zM0EWQ1J-jO1K2TAeTIA/s0/Screenshot_4.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;


&lt;/ul&gt;
&lt;h3&gt;Notes&lt;/h3&gt;&lt;p&gt;

If we want to add more functions:&lt;p&gt;
  &lt;ul&gt;
&lt;li&gt;Option 1: Base package&lt;/li&gt;&lt;p&gt;
&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;f1 &lt;- function(x) {
  x ^ 2 + 20 * x + 3
}
f2 &lt;- function(x) {
  x ^ 2 + 50 * x + 100
}
curve(expr = f1, from = -100, to = 100)
curve(expr = f2, from = -100, to = 100, col  = 2, add = TRUE)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

    &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUgQsh9qk3Wnr0LmR1Nb0YI_rZ4Uh5GElc7QWeczGgUcvayMpQebIWQHd2c3jdiECO-Ifohxs4DHkD0RuyPyF03r8ohvXfl09HmdqTxv9NBlRV0Rb0LdWkrhg1SfhMJr2_Jp59gA/s0/Screenshot_5.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;409&quot; data-original-width=&quot;492&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUgQsh9qk3Wnr0LmR1Nb0YI_rZ4Uh5GElc7QWeczGgUcvayMpQebIWQHd2c3jdiECO-Ifohxs4DHkD0RuyPyF03r8ohvXfl09HmdqTxv9NBlRV0Rb0LdWkrhg1SfhMJr2_Jp59gA/s0/Screenshot_5.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

&lt;li&gt;Option 2: ggplot2&lt;/li&gt;&lt;p&gt;
  
&lt;p&gt;
&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(data.frame(x = c(-100, 100)), aes(x)) +
  stat_function(
    fun = function(x) {
      x ^ 2 + 20 * x + 3
    }
  ) +
  stat_function(
    fun = function(x) {
      x ^ 2 + 50 * x + 100
    },
    colour = &quot;red&quot;
  ) +
  geom_hline(yintercept = 0) +
  geom_vline(xintercept = 0)
 &lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

    &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUJw_E5Ej0UTmVMt2c3IfvXg5FBqiYvzvsbbSo5I2pxGTT24uu1sNiCu3lnMqJzmcaQwHLvZfaabqNgG9Al_KgznXabi4mlEo6B_diS2fbPvpnEvRdWt2Md9bzT8YP3ErizrvKig/s0/Screenshot_6.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;480&quot; data-original-width=&quot;518&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgUJw_E5Ej0UTmVMt2c3IfvXg5FBqiYvzvsbbSo5I2pxGTT24uu1sNiCu3lnMqJzmcaQwHLvZfaabqNgG9Al_KgznXabi4mlEo6B_diS2fbPvpnEvRdWt2Md9bzT8YP3ErizrvKig/s0/Screenshot_6.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;


&lt;/ul&gt;


&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;

&lt;li&gt;&lt;a href=&quot;https://ggplot2.tidyverse.org/reference/stat_function.html&quot; target=&quot;_blank&quot;&gt;ggplot2 reference&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;


</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/382650931582204571/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/03/how-to-plot-functions-in-r.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/382650931582204571'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/382650931582204571'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/03/how-to-plot-functions-in-r.html' title='How to plot functions in R'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikZKHAlv_p05S9Zjg1Tzdg4zPQzjuzlBrEO27B0hkWPsGZ5mVuD09vZ4R4nfObhRayHZKVmo-CdydGMFwswvyHBCKSdOJebCpKx4UDZJSMCheMBg72GlthH60Sn8qEjKmypdd2Fw/s72-c/Screenshot_3.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-7242138440772868900</id><published>2021-03-12T14:59:00.003+01:00</published><updated>2021-03-12T14:59:53.334+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="case_when"/><category scheme="http://www.blogger.com/atom/ns#" term="dplyr"/><category scheme="http://www.blogger.com/atom/ns#" term="mutate"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="sqldf"/><title type='text'>SQL CASE or multiple if else statements in R</title><content type='html'>

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;
&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
  
We would like to create in R a conditional statement equivalent to the CASE statement in SQL. 
  
&lt;pre&gt;&lt;code&gt;    idnat     idbp
1  french mainland
2  french   colony
3  french overseas
4 foreign  foreign
&lt;/pre&gt;&lt;/code&gt;
  
&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df &lt;-structure(list(idnat = structure(c(2L, 2L, 2L, 1L), .Label = c(&quot;foreign&quot;, 
&quot;french&quot;), class = &quot;factor&quot;), idbp = structure(c(3L, 1L, 4L, 
2L), .Label = c(&quot;colony&quot;, &quot;foreign&quot;, &quot;mainland&quot;, &quot;overseas&quot;), class = &quot;factor&quot;)), .Names = c(&quot;idnat&quot;, 
&quot;idbp&quot;), class = &quot;data.frame&quot;, row.names = c(NA, -4L))
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;


&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

There are multiple alternatives. We will provide a couple of options using &lt;i&gt;dplyr&lt;/i&gt; and &lt;i&gt;sqldf&lt;/i&gt;.

&lt;ul&gt;
&lt;li&gt;Option 1: dplyr&lt;/li&gt;&lt;p&gt;
&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(dplyr)
df %&gt;%
  mutate(idnat2 = case_when(
    idbp == &#39;mainland&#39; ~ &quot;mainland&quot;,
    idbp %in% c(&quot;colony&quot;, &quot;overseas&quot;) ~ &quot;overseas&quot;,
    TRUE ~ &quot;foreign&quot;
  ))

&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;


&lt;li&gt;Option 2: sqldf&lt;/li&gt;&lt;p&gt;
  

&lt;p&gt;
&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(sqldf)
sqldf(
  &quot;SELECT idnat, idbp,
        CASE
          WHEN idbp IN (&#39;colony&#39;, &#39;overseas&#39;) THEN &#39;overseas&#39;
          ELSE idbp
        END AS idnat2
       FROM df&quot;
)
 &lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;


&lt;/ul&gt;
&lt;h3&gt;Results&lt;/h3&gt;&lt;p&gt;

&lt;pre&gt;&lt;code&gt;    idnat     idbp   idnat2
1  french mainland mainland
2  french   colony overseas
3  french overseas overseas
4 foreign  foreign  foreign
&lt;/pre&gt;&lt;/code&gt;


&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://dplyr.tidyverse.org/reference/case_when.html&quot; target=&quot;_blank&quot;&gt;A general vectorised if&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.w3schools.com/sql/sql_case.asp&quot; target=&quot;_blank&quot;&gt;SQL CASE Statement&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/18012222/nested-ifelse-statement/42108173#42108173&quot; target=&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;


</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/7242138440772868900/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/03/sql-case-or-multiple-if-else-statements.html#comment-form' title='1 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/7242138440772868900'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/7242138440772868900'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/03/sql-case-or-multiple-if-else-statements.html' title='SQL CASE or multiple if else statements in R'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-5355362032679295706</id><published>2021-03-09T12:19:00.001+01:00</published><updated>2021-03-09T12:28:39.659+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_point"/><category scheme="http://www.blogger.com/atom/ns#" term="ggplot2"/><category scheme="http://www.blogger.com/atom/ns#" term="scale_colour_manual"/><category scheme="http://www.blogger.com/atom/ns#" term="scale_size_manual"/><category scheme="http://www.blogger.com/atom/ns#" term="scatterplot"/><title type='text'>How to highlight specific data points in a scatter plot with ggplot2</title><content type='html'>

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;
&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
  
We would like to highlight specific data points in a scatter plot created with ggplot2. In our example, we will use the  &lt;a href=&quot;http://docs.ggplot2.org/current/mpg.html&quot; target=&quot;_blank&quot;&gt;mpg dataset &lt;/a&gt;(Fuel economy data from 1999 and 2008 for 38 popular models of car). We want to highlight in red and a larger point size those data points whose displ (engine displacement) are greater than 5 and hwy (highway miles per gallon) greater than 20. &lt;p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDUhqjNZ7KG1_QRxXBdCTE3zcVxoIClKiAShBD2P-Tr3PyU4kk86RG2MwfepYVeDERzFdC7JUSyrM3NRZPjwMnaLCaWGNch6kOD_BIL97A-VXnbiNhIct_QDHqOIiWbXs9H9YknA/s1600/highliting+points+ggplot2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDUhqjNZ7KG1_QRxXBdCTE3zcVxoIClKiAShBD2P-Tr3PyU4kk86RG2MwfepYVeDERzFdC7JUSyrM3NRZPjwMnaLCaWGNch6kOD_BIL97A-VXnbiNhIct_QDHqOIiWbXs9H9YknA/s1600/highliting+points+ggplot2.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;


&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

&lt;li&gt;Option 1&lt;/li&gt;&lt;p&gt;
We add the conditions for both attributes, colour and size, inside &lt;i&gt;geom_point&lt;/i&gt;. Then we control manually those using &lt;i&gt;scale_colour_manual&lt;/i&gt; and &lt;i&gt;scale_size_manual&lt;/i&gt; respectively. Finally, we remove the legend.&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy, colour = displ &gt; 5 &amp; hwy &gt; 20, size = displ &gt; 5 &amp; hwy &gt; 20)) + 
  scale_colour_manual(values = c(&quot;black&quot;, &quot;red&quot;)) + 
  scale_size_manual(values =c(1.5, 3))+
  theme(legend.position = &quot;none&quot;)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;



&lt;li&gt;Option 2&lt;/li&gt;&lt;p&gt;
  
We create two layers of data points using geom_point. The first layer include all data points in black (by default but e). The second layer adds the points we would like to highlight in red with a larger point size.
&lt;p&gt;
&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(data = mpg) + 
  geom_point(mapping = aes(x = displ, y = hwy), colour= &quot;black&quot;) +
  geom_point(data = subset(mpg, displ &gt; 5 &amp; hwy &gt; 20), aes(x = displ, y = hwy), colour= &quot;red&quot;, size = 3)
 &lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

In ggplot2 the layers are added sequentially. If we change the order of the layers, we would get the following result.&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(data = mpg) + 
   geom_point(data = subset(mpg, displ &gt; 5 &amp; hwy &gt; 20), aes(x = displ, y = hwy), colour= &quot;red&quot;, size = 3) +
   geom_point(mapping = aes(x = displ, y = hwy), colour= &quot;black&quot;)
 &lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;


&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBGwPx1rWhedBPF17X-PzLs8j2o4qODKqFMnSw-xv2M6h3RAs-mDOIO6udCKJLJoZiBE8ZGcwUpKbLRA0f58-I5oQhJliCjov5uhDtyuJ3Lm-zhZKlV3BwPY01Y-giKv9bpVAFKw/s0/Screenshot_1.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;327&quot; data-original-width=&quot;605&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBGwPx1rWhedBPF17X-PzLs8j2o4qODKqFMnSw-xv2M6h3RAs-mDOIO6udCKJLJoZiBE8ZGcwUpKbLRA0f58-I5oQhJliCjov5uhDtyuJ3Lm-zhZKlV3BwPY01Y-giKv9bpVAFKw/s0/Screenshot_1.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

&lt;!----

&lt;h3&gt;Related posts&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://nubededatos.blogspot.com.es/2015/05/etiquetar-selectivamente-los-puntos-de.html&quot;&gt;Etiquetar los puntos de un diagrama de dispersión con ggplot2 &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://nubededatos.blogspot.com.es/2015/05/etiquetar-selectivamente-los-puntos-de.html&quot;&gt;Etiquetar selectivamente los puntos de un diagrama de dispersión con ggplot2&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://nubededatos.blogspot.com.es/2015/11/diagramas-de-dispersion-con-el-paquete.html&quot;&gt;Diagramas de dispersión con el paquete car en R&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


----&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/5355362032679295706/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/03/how-to-highlight-specific-data-points.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/5355362032679295706'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/5355362032679295706'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/03/how-to-highlight-specific-data-points.html' title='How to highlight specific data points in a scatter plot with ggplot2'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDUhqjNZ7KG1_QRxXBdCTE3zcVxoIClKiAShBD2P-Tr3PyU4kk86RG2MwfepYVeDERzFdC7JUSyrM3NRZPjwMnaLCaWGNch6kOD_BIL97A-VXnbiNhIct_QDHqOIiWbXs9H9YknA/s72-c/highliting+points+ggplot2.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-8104938149371571587</id><published>2021-03-04T15:24:00.001+01:00</published><updated>2021-03-04T15:31:56.895+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="%in%"/><category scheme="http://www.blogger.com/atom/ns#" term="data.table"/><category scheme="http://www.blogger.com/atom/ns#" term="dplyr"/><category scheme="http://www.blogger.com/atom/ns#" term="filter"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><title type='text'>Cómo filtrar múltiples valores en una columna en R</title><content type='html'>
&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;
&lt;h3&gt;Problema&lt;/h3&gt;&lt;p&gt;
  
  
Queremos filtrar múltiples valores en una columna en R. En nuestro ejemplo, queremos filtrar las filas que contengan la cadena de texto &lt;i&gt;Tom&lt;/i&gt; o &lt;i&gt;Lynn&lt;/i&gt; en la columna &lt;i&gt;name&lt;/i&gt;.
&lt;p&gt;
  
  
&lt;h3&gt;Ejemplo&lt;/h3&gt;&lt;p&gt;
&lt;pre&gt;&lt;code&gt;  days  name
1   88  Lynn
2   11   Tom
3    2 Chris
4    5  Lisa
5   22  Kyla
6    1   Tom
7  222  Lynn
8    2  Lynn
&lt;/pre&gt;&lt;/code&gt;



&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df &lt;-
  data.frame(
    days = c(88, 11, 2, 5, 22, 1, 222, 2),
    name = c(&quot;Lynn&quot;, &quot;Tom&quot;, &quot;Chris&quot;, &quot;Lisa&quot;, &quot;Kyla&quot;, &quot;Tom&quot;, &quot;Lynn&quot;, &quot;Lynn&quot;)
  ) 
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;p&gt;

  
&lt;h3&gt;Solución&lt;/h3&gt;&lt;p&gt;
  

&lt;li&gt;Base package&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df[df$name %in% c(&quot;Tom&quot;, &quot;Lynn&quot;), ] # or
target &lt;- c(&quot;Tom&quot;, &quot;Lynn&quot;)
df[df$name %in% target, ]
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;pre&gt;&lt;code class&gt;  days name
1   88 Lynn
2   11  Tom
6    1  Tom
7  222 Lynn
8    2 Lynn
&lt;/pre&gt;&lt;/code class&gt;


&lt;li&gt;dplyr&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(dplyr)
filter(df, name %in% c(&quot;Tom&quot;, &quot;Lynn&quot;)) # or
target &lt;- c(&quot;Tom&quot;, &quot;Lynn&quot;)
filter(df, name %in% target)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;li&gt;data.table&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(data.table)
DT &lt;- data.table(df)
DT[name %in% target]
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;li&gt;sqldf&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(sqldf)
# Dos alternativas:
sqldf(&#39;SELECT *
      FROM df 
      WHERE name = &quot;Tom&quot; OR name = &quot;Lynn&quot;&#39;)
sqldf(&#39;SELECT *
      FROM df 
      WHERE name IN (&quot;Tom&quot;, &quot;Lynn&quot;)&#39;)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;


&lt;h3&gt;Entradas relacionadas&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://nubededatos.blogspot.com/2020/10/filtrar-filas-que-contengan-una-cadena.html&quot;&gt;Filtrar filas que contengan una cadena de texto en R&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;Referencias&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/25647470/filter-multiple-values-on-a-string-column-in-dplyr/30922431#30922431&quot; target=&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;

&lt;/li&gt;

&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/8104938149371571587/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/03/como-filtrar-multiples-valores-en-una.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/8104938149371571587'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/8104938149371571587'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/03/como-filtrar-multiples-valores-en-una.html' title='Cómo filtrar múltiples valores en una columna en R'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-7200132869178913826</id><published>2021-03-04T15:19:00.004+01:00</published><updated>2021-03-04T15:31:06.291+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="%in%"/><category scheme="http://www.blogger.com/atom/ns#" term="data.table"/><category scheme="http://www.blogger.com/atom/ns#" term="dplyr"/><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="filter"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><title type='text'>How to filter multiple values on a column in R</title><content type='html'>
&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;
&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
  
We want to filter multiple values on a column in R. In our example, we want to subset the rows containing the string &lt;i&gt;Tom&lt;/i&gt; or &lt;i&gt;Lynn&lt;/i&gt; for the column &lt;i&gt;name&lt;/i&gt;.
&lt;p&gt;
  
  
&lt;h3&gt;Example&lt;/h3&gt;&lt;p&gt;
&lt;pre&gt;&lt;code&gt;  days  name
1   88  Lynn
2   11   Tom
3    2 Chris
4    5  Lisa
5   22  Kyla
6    1   Tom
7  222  Lynn
8    2  Lynn
&lt;/pre&gt;&lt;/code&gt;



&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df &lt;-
  data.frame(
    days = c(88, 11, 2, 5, 22, 1, 222, 2),
    name = c(&quot;Lynn&quot;, &quot;Tom&quot;, &quot;Chris&quot;, &quot;Lisa&quot;, &quot;Kyla&quot;, &quot;Tom&quot;, &quot;Lynn&quot;, &quot;Lynn&quot;)
  ) 
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;p&gt;

  
&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;
  

&lt;li&gt;Base package&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df[df$name %in% c(&quot;Tom&quot;, &quot;Lynn&quot;), ] # or
target &lt;- c(&quot;Tom&quot;, &quot;Lynn&quot;)
df[df$name %in% target, ]
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;pre&gt;&lt;code class&gt;  days name
1   88 Lynn
2   11  Tom
6    1  Tom
7  222 Lynn
8    2 Lynn
&lt;/pre&gt;&lt;/code class&gt;


&lt;li&gt;dplyr&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(dplyr)
filter(df, name %in% c(&quot;Tom&quot;, &quot;Lynn&quot;)) # or
target &lt;- c(&quot;Tom&quot;, &quot;Lynn&quot;)
filter(df, name %in% target)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;li&gt;data.table&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(data.table)
DT &lt;- data.table(df)
DT[name %in% target]
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;li&gt;sqldf&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(sqldf)
# Two alternatives:
sqldf(&#39;SELECT *
      FROM df 
      WHERE name = &quot;Tom&quot; OR name = &quot;Lynn&quot;&#39;)
sqldf(&#39;SELECT *
      FROM df 
      WHERE name IN (&quot;Tom&quot;, &quot;Lynn&quot;)&#39;)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;h3&gt;Related posts&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://nubededatos.blogspot.com/2020/10/filter-rows-containing-certain-string.html&quot;&gt;Filter rows containing a certain string in R&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/25647470/filter-multiple-values-on-a-string-column-in-dplyr/30922431#30922431&quot; target=&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;

&lt;/li&gt;

&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/7200132869178913826/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/03/how-to-filter-multiple-values-on-column.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/7200132869178913826'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/7200132869178913826'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/03/how-to-filter-multiple-values-on-column.html' title='How to filter multiple values on a column in R'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-2817256027848938515</id><published>2021-03-01T16:08:00.005+01:00</published><updated>2021-03-03T09:02:47.095+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="dplyr"/><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="iris"/><category scheme="http://www.blogger.com/atom/ns#" term="lapply"/><category scheme="http://www.blogger.com/atom/ns#" term="mtcars"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="R for beginners"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="sample_n"/><category scheme="http://www.blogger.com/atom/ns#" term="split"/><title type='text'>How to draw a stratified sample in R</title><content type='html'>
&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;
&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
  
We want to draw a stratified sample from a data frame in R.
&lt;p&gt;

&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;
  
Let&#39;s look at two examples, with one or several groups.
&lt;p&gt;

&lt;b&gt;One group&lt;/b&gt;&lt;p&gt;
 
We extract 3 records from each of the species: setosa, versicolor y virginica.&lt;p&gt;


&lt;li&gt;Base package&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;set.seed(1)
iris1 &lt;- lapply(split(iris, iris$Species), function(x) x[sample(nrow(x), 3), ])
do.call(&quot;rbind&quot;, iris1) 
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;pre&gt;&lt;code class&gt;              Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
setosa.14              4.3         3.0          1.1         0.1     setosa
setosa.19              5.7         3.8          1.7         0.3     setosa
setosa.28              5.2         3.5          1.5         0.2     setosa
versicolor.96          5.7         3.0          4.2         1.2 versicolor
versicolor.60          5.2         2.7          3.9         1.4 versicolor
versicolor.94          5.0         2.3          3.3         1.0 versicolor
virginica.148          6.5         3.0          5.2         2.0  virginica
virginica.133          6.4         2.8          5.6         2.2  virginica
virginica.131          7.4         2.8          6.1         1.9  virginica
&lt;/pre&gt;&lt;/code class&gt;


&lt;li&gt;dplyr&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(dplyr)
set.seed(1)
iris %&gt;%
  group_by(Species) %&gt;%
  sample_n(., 3)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;pre&gt;&lt;code class&gt; Source: local data frame [9 x 5]
Groups: Species

  Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
1          4.3         3.0          1.1         0.1     setosa
2          5.7         3.8          1.7         0.3     setosa
3          5.2         3.5          1.5         0.2     setosa
4          5.7         3.0          4.2         1.2 versicolor
5          5.2         2.7          3.9         1.4 versicolor
6          5.0         2.3          3.3         1.0 versicolor
7          6.5         3.0          5.2         2.0  virginica
8          6.4         2.8          5.6         2.2  virginica
9          7.4         2.8          6.1         1.9  virginica
&lt;/pre&gt;&lt;/code class&gt; 



&lt;b&gt;Two groups&lt;/b&gt;&lt;p&gt;
For each number of cylinders (4, 6 u 8) we will extract 2 records with automatic transmission (am = 0) and 2 with manual transmission (am = 1).&lt;p&gt;
&lt;p&gt;
&lt;li&gt;Base package&lt;/li&gt;&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;set.seed(1)
mtcars1 &lt;- lapply(split(mtcars, list(mtcars$cyl, mtcars$am)), function(x) x[sample(nrow(x), 2), ])
do.call(&quot;rbind&quot;, mtcars1) 
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;


&lt;pre&gt;&lt;code class&gt;                       mpg cyl  disp  hp drat    wt  qsec vs am gear carb
0.4.Merc 240D         24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
0.4.Toyota Corona     21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1
1.4.Fiat X1-9         27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1
1.4.Lotus Europa      30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2
0.6.Hornet 4 Drive    21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
0.6.Merc 280          19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
1.6.Ferrari Dino      19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6
1.6.Mazda RX4 Wag     21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
0.8.Chrysler Imperial 14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4
0.8.Hornet Sportabout 18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
1.8.Ford Pantera L    15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4
1.8.Maserati Bora     15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8
&lt;/pre&gt;&lt;/code class&gt;




&lt;li&gt; dplyr&lt;/li&gt;&lt;p&gt;


&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;set.seed(1)
mtcars %&gt;%
  group_by(cyl, am) %&gt;%
  sample_n(., 2)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;pre&gt;&lt;code class&gt;Source: local data frame [12 x 11]
Groups: cyl, am

    mpg cyl  disp  hp drat    wt  qsec vs am gear carb
1  24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2
2  21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1
3  27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1
4  30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2
5  21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1
6  19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4
7  19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6
8  21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4
9  14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4
10 18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2
11 15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4
12 15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8
&lt;/pre&gt;&lt;/code class&gt; 

&lt;h3&gt;Related posts&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://nubededatos.blogspot.com/2020/04/how-to-select-random-sample-in-r.html&quot;&gt;How to select a random sample in R&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://stackoverflow.com/questions/7950834/drawing-a-stratified-sample-in-r&quot; target=&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;

&lt;/li&gt;

&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/2817256027848938515/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/03/how-to-draw-stratified-sample-in-r.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/2817256027848938515'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/2817256027848938515'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/03/how-to-draw-stratified-sample-in-r.html' title='How to draw a stratified sample in R'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-3781055161035811644</id><published>2021-02-09T17:31:00.000+01:00</published><updated>2021-02-09T17:31:03.862+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_point"/><category scheme="http://www.blogger.com/atom/ns#" term="ggplot2"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="scale_colour_gradient"/><category scheme="http://www.blogger.com/atom/ns#" term="scatterplot"/><title type='text'>How to set tick labels to the edges of a continuous ggplot2 legend</title><content type='html'>
&lt;head&gt;


&lt;title&gt;Title&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;

&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
  
We want to show the minimum and maximum values in the legend of our plot in ggplot2.
&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(ggplot2)
d &lt;- subset(diamonds, price &gt;= 257 &amp; price &lt;= 8888)
ggplot(d, aes(depth, carat, colour = price)) +
  geom_point() +
  scale_colour_gradient(limits = c(257, 8888))
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;


&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsreeskShN-9xjMqa-N760dzh32NO7tWgJO4evvrJb5oX1VpVKaHZXC_ASDGInOAPi8stACo8WrjaRjoJMF33OXHtxLtG3Pt5FYGz8I5tNfoz34czo9Qjwyzohq7k3vtaJ3KCRuQ/s1600/CropperCapture%255B279%255D.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsreeskShN-9xjMqa-N760dzh32NO7tWgJO4evvrJb5oX1VpVKaHZXC_ASDGInOAPi8stACo8WrjaRjoJMF33OXHtxLtG3Pt5FYGz8I5tNfoz34czo9Qjwyzohq7k3vtaJ3KCRuQ/s1600/CropperCapture%255B279%255D.png&quot;&gt;&lt;/a&gt;&lt;/div&gt;

&lt;p&gt;
The legend shows values from 2.000 al 8.000 but we do not know the minimum and the maximum values.&lt;p&gt;

 


&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;



Within scale_colour_gradient, we pass the arguments breaks and labels. 

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(d, aes(depth, carat, colour = price)) +
  geom_point() +
  scale_colour_gradient(limits = c(257, 8888), 
                        breaks = c(257, 2000, 4000, 6000, 8000, 8888),
                        labels = c(257, 2000, 4000, 6000, 8000, 8888))
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN2DrpQ3rGEXly7O3R1XGdSuq22FPutMdiV2QCkbd-zXnZY_ZXzGykaRg99p8TsPkP36Wai6tChG9Vx-Y9vHN_tEoX-MudteKuqvB2O6_Lhhj-RptqNXM3ZK8sgZc3g3CiR1Hzfw/s1600/CropperCapture%255B280%255D.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgN2DrpQ3rGEXly7O3R1XGdSuq22FPutMdiV2QCkbd-zXnZY_ZXzGykaRg99p8TsPkP36Wai6tChG9Vx-Y9vHN_tEoX-MudteKuqvB2O6_Lhhj-RptqNXM3ZK8sgZc3g3CiR1Hzfw/s1600/CropperCapture%255B280%255D.png&quot;&gt;&lt;/a&gt;&lt;/div&gt;


&lt;p&gt;

Now we have added to the legend the minimum 257 and the maximum 8.888 values.&lt;p&gt;


&lt;h3&gt;Notes&lt;/h3&gt;&lt;p&gt;
Instead of using the default colour scale colours from light blue to dark blue, we can adjust colour choices with the arguments &lt;i&gt;low&lt;/i&gt; and &lt;i&gt;high&lt;/i&gt;.

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(d, aes(depth, carat, colour = price)) +
  geom_point() +
  scale_colour_gradient(limits = c(257, 8888), 
                        breaks=c(257, 2000, 4000, 6000, 8000, 8888),
                        labels=c(257, 2000, 4000, 6000, 8000, 8888), low = &quot;red&quot;)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFjmcB-Mv06MfoR6ubIuRrbjQsIjbNHU70WBNavwxW3JDpTQIHE638BVp1o4_GxcgvUWxVZ6OOYQdP0o_ThWkmUkU4Fr3g52GNpUGXGtdq708lQ2TQXFSSl-lFnJCt7VH19GZUDw/s1600/CropperCapture%255B281%255D.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgFjmcB-Mv06MfoR6ubIuRrbjQsIjbNHU70WBNavwxW3JDpTQIHE638BVp1o4_GxcgvUWxVZ6OOYQdP0o_ThWkmUkU4Fr3g52GNpUGXGtdq708lQ2TQXFSSl-lFnJCt7VH19GZUDw/s1600/CropperCapture%255B281%255D.png&quot;&gt;&lt;/a&gt;&lt;/div&gt;

&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;
&lt;ul&gt;

&lt;li&gt;&lt;a href=&quot;http://docs.ggplot2.org/0.9.3.1/scale_gradient.html&quot;target =&quot;_blank&quot;&gt;Smooth gradient between two colours&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/34638810/how-to-set-tick-labels-to-edges-of-continuous-ggplot2-legend/34639099#34639099&quot; target =&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;



&lt;!---
&lt;h3&gt;Entradas relacionadas&lt;/h3&gt;&lt;p&gt;
&lt;ul&gt;



&lt;li&gt;&lt;a href=&quot;http://nubededatos.blogspot.com.es/search?q=geom_point&quot;&gt;Entradas que utilizan &lt;i&gt;geom_point&lt;/i&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;http://nubededatos.blogspot.com.es/search/label/diagrama%20de%20dispersi%C3%B3n&quot;&gt;Diagramas de dispersión&lt;/a&gt;&lt;/li&gt;



&lt;/ul&gt;

---&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/3781055161035811644/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/02/how-to-set-tick-labels-to-edges-of.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3781055161035811644'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3781055161035811644'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/02/how-to-set-tick-labels-to-edges-of.html' title='How to set tick labels to the edges of a continuous ggplot2 legend'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsreeskShN-9xjMqa-N760dzh32NO7tWgJO4evvrJb5oX1VpVKaHZXC_ASDGInOAPi8stACo8WrjaRjoJMF33OXHtxLtG3Pt5FYGz8I5tNfoz34czo9Qjwyzohq7k3vtaJ3KCRuQ/s72-c/CropperCapture%255B279%255D.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-2506233375007144509</id><published>2021-01-29T05:33:00.001+01:00</published><updated>2021-01-29T05:33:01.410+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="comma"/><category scheme="http://www.blogger.com/atom/ns#" term="dplyr"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_bar"/><category scheme="http://www.blogger.com/atom/ns#" term="ggplot2"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><title type='text'>Cómo crear una pirámide de población con ggplot2</title><content type='html'>&lt;head&gt;


&lt;title&gt;Title&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;

&lt;h3&gt;Problema&lt;/h3&gt;&lt;p&gt;
  
Queremos crear una pirámide de población con ggplot2. Nuestro ejemplo es la población española por edad y sexo en 2020.&lt;p&gt;

&lt;h3&gt;Ejemplo&lt;/h3&gt;&lt;p&gt;
&lt;pre&gt;&lt;code&gt;# A tibble: 42 x 3
   Age      Gender   Total
   &lt;chr&gt;    &lt;chr&gt;    &lt;int&gt;
 1 &quot;0-4 &quot;   male   1018039
 2 &quot;0-4 &quot;   female  963653
 3 &quot;5-9&quot;    male   1196380
 4 &quot;5-9&quot;    female 1129063
 5 &quot;10-14&quot;  male   1297635
 6 &quot;10-14&quot;  female 1225863
 7 &quot;15-19 &quot; male   1232566
 8 &quot;15-19 &quot; female 1156455
 9 &quot;20-24 &quot; male   1207902
10 &quot;20-24 &quot; female 1152765
# ... with 32 more rows
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;
  

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df &lt;- structure(list(Age = c(&quot;0-4 &quot;, &quot;0-4 &quot;, &quot;5-9&quot;, &quot;5-9&quot;, &quot;10-14&quot;, 
&quot;10-14&quot;, &quot;15-19 &quot;, &quot;15-19 &quot;, &quot;20-24 &quot;, &quot;20-24 &quot;, &quot;25-29 &quot;, &quot;25-29 &quot;, 
&quot;30-34 &quot;, &quot;30-34 &quot;, &quot;35-39 &quot;, &quot;35-39 &quot;, &quot;40-44 &quot;, &quot;40-44 &quot;, &quot;45-49 &quot;, 
&quot;45-49 &quot;, &quot;50-54 &quot;, &quot;50-54 &quot;, &quot;55-59 &quot;, &quot;55-59 &quot;, &quot;60-64 &quot;, &quot;60-64 &quot;, 
&quot;65-69 &quot;, &quot;65-69 &quot;, &quot;70-74 &quot;, &quot;70-74 &quot;, &quot;75-79 &quot;, &quot;75-79 &quot;, &quot;80-84 &quot;, 
&quot;80-84 &quot;, &quot;85-89 &quot;, &quot;85-89 &quot;, &quot;90-94 &quot;, &quot;90-94 &quot;, &quot;95-99 &quot;, &quot;95-99 &quot;, 
&quot;100+&quot;, &quot;100+&quot;), Gender = c(&quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, 
&quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, 
&quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, 
&quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, 
&quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, 
&quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, 
&quot;female&quot;, &quot;male&quot;, &quot;female&quot;), Total = c(1018039L, 963653L, 1196380L, 
1129063L, 1297635L, 1225863L, 1232566L, 1156455L, 1207902L, 1152765L, 
1308197L, 1275776L, 1421558L, 1417845L, 1702135L, 1688865L, 2024303L, 
1971909L, 1968659L, 1926866L, 1828015L, 1840434L, 1652558L, 1712299L, 
1410111L, 1502563L, 1153768L, 1270544L, 1020478L, 1191698L, 773823L, 
974046L, 513692L, 759379L, 361702L, 634714L, 133032L, 302885L, 
27305L, 84007L, 3732L, 13576L)), class = &quot;data.frame&quot;, row.names = c(NA, 
-42L))
tibble(df)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;&lt;p&gt;  

&lt;h3&gt;Solución&lt;/h3&gt;&lt;p&gt;

Primero necesitamos crear dos columnas. En la primera cambiamos el signo de la población masculina para mostrarla invertida en el gráfico. En la segunda calculamos el porcentaje de población por edad y sexo.

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df &lt;- df %&gt;%
  group_by(Gender) %&gt;% 
  mutate(
    Population = ifelse(Gender == &quot;female&quot;, Total,-Total),
    Percent = ifelse(Gender == &quot;female&quot;, 100 * (Total / sum(Total)),-100 * (Total / sum(Total))))
df$Age &lt;- factor(df$Age, levels=unique(df$Age)) # Para mantener el orden original de vector carácter
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;&lt;p&gt;

&lt;li&gt;Totales&lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB_93M13TiH6Iasi9HOj7Lh6vth4VSoIShUm4zHQSMtwrJ3MfwAAb-0BLBi4bcr3ZM5GqOi6sxVM2B_Gh6dzeGOmcqXaaR3F80GuaTW7oXWELYJePpJuQdx6YrfWA5Hr4BtZCkgQ/s0/Screenshot_1.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;398&quot; data-original-width=&quot;686&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB_93M13TiH6Iasi9HOj7Lh6vth4VSoIShUm4zHQSMtwrJ3MfwAAb-0BLBi4bcr3ZM5GqOi6sxVM2B_Gh6dzeGOmcqXaaR3F80GuaTW7oXWELYJePpJuQdx6YrfWA5Hr4BtZCkgQ/s0/Screenshot_1.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(df, aes(x = Age, Population, fill = Gender)) + 
  geom_bar(data = filter(df, Gender == &quot;female&quot;), stat = &quot;identity&quot;) + 
  geom_bar(data = filter(df, Gender == &quot;male&quot;),  stat = &quot;identity&quot;) + 
  scale_y_continuous(breaks = seq(-2000000, 2000000, 500000), labels = comma(abs(seq(-2000000, 2000000, 500000))))+
  coord_flip()
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;&lt;p&gt;


&lt;li&gt;Porcentajes&lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXDHUfjZhEriSo8BokBYsBpAeyQm4qG5vr8KG9KeJQkInkbwRR0spZdjJ51zan5RSdrNHufCf2ildOPoor8ejcyj0x8iEDcc_l3FTVsc3UGEnJj2ivr1hb9nznqpDN7eCq_bLtTQ/s0/Screenshot_2.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;396&quot; data-original-width=&quot;694&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXDHUfjZhEriSo8BokBYsBpAeyQm4qG5vr8KG9KeJQkInkbwRR0spZdjJ51zan5RSdrNHufCf2ildOPoor8ejcyj0x8iEDcc_l3FTVsc3UGEnJj2ivr1hb9nznqpDN7eCq_bLtTQ/s0/Screenshot_2.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(df, aes(x = Age, Percent, fill = Gender)) +
  geom_bar(data = filter(df, Gender == &quot;female&quot;), stat = &quot;identity&quot;) +
  geom_bar(data = filter(df, Gender == &quot;male&quot;),  stat = &quot;identity&quot;) +
  scale_y_continuous(breaks = seq(-10, 10, 2), labels = comma(abs(seq(-10, 10, 2)))) +
  coord_flip()
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;&lt;p&gt;


&lt;h3&gt;Referencias&lt;/h3&gt;&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/31897329/population-pyramid-plot-with-ggplot2-and-dplyr-instead-of-plyr&quot; target=&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.ine.es/dynt3/inebase/es/index.htm?type=pcaxis&amp;amp;path=/t20/e245/p08/&amp;amp;file=pcaxis&amp;amp;dh=0&amp;amp;capsel=0&quot; target=&quot;_blank&quot;&gt;Principales series de población (INE)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/2506233375007144509/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/01/como-crear-una-piramide-de-poblacion.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/2506233375007144509'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/2506233375007144509'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/01/como-crear-una-piramide-de-poblacion.html' title='Cómo crear una pirámide de población con ggplot2'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB_93M13TiH6Iasi9HOj7Lh6vth4VSoIShUm4zHQSMtwrJ3MfwAAb-0BLBi4bcr3ZM5GqOi6sxVM2B_Gh6dzeGOmcqXaaR3F80GuaTW7oXWELYJePpJuQdx6YrfWA5Hr4BtZCkgQ/s72-c/Screenshot_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-1896956918970621839</id><published>2021-01-27T12:30:00.006+01:00</published><updated>2021-01-27T12:30:47.897+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="comma"/><category scheme="http://www.blogger.com/atom/ns#" term="dplyr"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_bar"/><category scheme="http://www.blogger.com/atom/ns#" term="ggplot2"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><title type='text'>How to create a population pyramid with ggplot2</title><content type='html'>&lt;head&gt;


&lt;title&gt;Title&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;

&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
  
We want to create a population pyramid with ggplot2. Our example is the Spanish population by age and gender in 2020.&lt;p&gt;

&lt;h3&gt;Example&lt;/h3&gt;&lt;p&gt;
&lt;pre&gt;&lt;code&gt;# A tibble: 42 x 3
   Age      Gender   Total
   &lt;chr&gt;    &lt;chr&gt;    &lt;int&gt;
 1 &quot;0-4 &quot;   male   1018039
 2 &quot;0-4 &quot;   female  963653
 3 &quot;5-9&quot;    male   1196380
 4 &quot;5-9&quot;    female 1129063
 5 &quot;10-14&quot;  male   1297635
 6 &quot;10-14&quot;  female 1225863
 7 &quot;15-19 &quot; male   1232566
 8 &quot;15-19 &quot; female 1156455
 9 &quot;20-24 &quot; male   1207902
10 &quot;20-24 &quot; female 1152765
# ... with 32 more rows
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;

  

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df &lt;- structure(list(Age = c(&quot;0-4 &quot;, &quot;0-4 &quot;, &quot;5-9&quot;, &quot;5-9&quot;, &quot;10-14&quot;, 
&quot;10-14&quot;, &quot;15-19 &quot;, &quot;15-19 &quot;, &quot;20-24 &quot;, &quot;20-24 &quot;, &quot;25-29 &quot;, &quot;25-29 &quot;, 
&quot;30-34 &quot;, &quot;30-34 &quot;, &quot;35-39 &quot;, &quot;35-39 &quot;, &quot;40-44 &quot;, &quot;40-44 &quot;, &quot;45-49 &quot;, 
&quot;45-49 &quot;, &quot;50-54 &quot;, &quot;50-54 &quot;, &quot;55-59 &quot;, &quot;55-59 &quot;, &quot;60-64 &quot;, &quot;60-64 &quot;, 
&quot;65-69 &quot;, &quot;65-69 &quot;, &quot;70-74 &quot;, &quot;70-74 &quot;, &quot;75-79 &quot;, &quot;75-79 &quot;, &quot;80-84 &quot;, 
&quot;80-84 &quot;, &quot;85-89 &quot;, &quot;85-89 &quot;, &quot;90-94 &quot;, &quot;90-94 &quot;, &quot;95-99 &quot;, &quot;95-99 &quot;, 
&quot;100+&quot;, &quot;100+&quot;), Gender = c(&quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, 
&quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, 
&quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, 
&quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, 
&quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, 
&quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, &quot;female&quot;, &quot;male&quot;, 
&quot;female&quot;, &quot;male&quot;, &quot;female&quot;), Total = c(1018039L, 963653L, 1196380L, 
1129063L, 1297635L, 1225863L, 1232566L, 1156455L, 1207902L, 1152765L, 
1308197L, 1275776L, 1421558L, 1417845L, 1702135L, 1688865L, 2024303L, 
1971909L, 1968659L, 1926866L, 1828015L, 1840434L, 1652558L, 1712299L, 
1410111L, 1502563L, 1153768L, 1270544L, 1020478L, 1191698L, 773823L, 
974046L, 513692L, 759379L, 361702L, 634714L, 133032L, 302885L, 
27305L, 84007L, 3732L, 13576L)), class = &quot;data.frame&quot;, row.names = c(NA, 
-42L))
tibble(df)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;&lt;p&gt;  

&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

First we need to create two columns. One to convert male population to negative so it is reversed in the plot. Another column with the population percentage by age and sex.

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df &lt;- df %&gt;%
  group_by(Gender) %&gt;% 
  mutate(
    Population = ifelse(Gender == &quot;female&quot;, Total,-Total),
    Percent = ifelse(Gender == &quot;female&quot;, 100 * (Total / sum(Total)),-100 * (Total / sum(Total))))
df$Age &lt;- factor(df$Age, levels=unique(df$Age)) # To keep the original order of the character vector
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;&lt;p&gt;

&lt;li&gt;Absolute numbers&lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB_93M13TiH6Iasi9HOj7Lh6vth4VSoIShUm4zHQSMtwrJ3MfwAAb-0BLBi4bcr3ZM5GqOi6sxVM2B_Gh6dzeGOmcqXaaR3F80GuaTW7oXWELYJePpJuQdx6YrfWA5Hr4BtZCkgQ/s0/Screenshot_1.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;398&quot; data-original-width=&quot;686&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB_93M13TiH6Iasi9HOj7Lh6vth4VSoIShUm4zHQSMtwrJ3MfwAAb-0BLBi4bcr3ZM5GqOi6sxVM2B_Gh6dzeGOmcqXaaR3F80GuaTW7oXWELYJePpJuQdx6YrfWA5Hr4BtZCkgQ/s0/Screenshot_1.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(df, aes(x = Age, Population, fill = Gender)) + 
  geom_bar(data = filter(df, Gender == &quot;female&quot;), stat = &quot;identity&quot;) + 
  geom_bar(data = filter(df, Gender == &quot;male&quot;),  stat = &quot;identity&quot;) + 
  scale_y_continuous(breaks = seq(-2000000, 2000000, 500000), labels = comma(abs(seq(-2000000, 2000000, 500000))))+
  coord_flip()
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;&lt;p&gt;


&lt;li&gt;Percentage&lt;/li&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXDHUfjZhEriSo8BokBYsBpAeyQm4qG5vr8KG9KeJQkInkbwRR0spZdjJ51zan5RSdrNHufCf2ildOPoor8ejcyj0x8iEDcc_l3FTVsc3UGEnJj2ivr1hb9nznqpDN7eCq_bLtTQ/s0/Screenshot_2.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;396&quot; data-original-width=&quot;694&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXDHUfjZhEriSo8BokBYsBpAeyQm4qG5vr8KG9KeJQkInkbwRR0spZdjJ51zan5RSdrNHufCf2ildOPoor8ejcyj0x8iEDcc_l3FTVsc3UGEnJj2ivr1hb9nznqpDN7eCq_bLtTQ/s0/Screenshot_2.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;ggplot(df, aes(x = Age, Percent, fill = Gender)) +
  geom_bar(data = filter(df, Gender == &quot;female&quot;), stat = &quot;identity&quot;) +
  geom_bar(data = filter(df, Gender == &quot;male&quot;),  stat = &quot;identity&quot;) +
  scale_y_continuous(breaks = seq(-10, 10, 2), labels = comma(abs(seq(-10, 10, 2)))) +
  coord_flip()
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;&lt;p&gt;


&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/31897329/population-pyramid-plot-with-ggplot2-and-dplyr-instead-of-plyr&quot; target=&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://www.ine.es/dynt3/inebase/es/index.htm?type=pcaxis&amp;amp;path=/t20/e245/p08/&amp;amp;file=pcaxis&amp;amp;dh=0&amp;amp;capsel=0&quot; target=&quot;_blank&quot;&gt;Population series from INE (Spanish Statistical Office)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/1896956918970621839/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/01/how-to-create-population-pyramid-with.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/1896956918970621839'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/1896956918970621839'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/01/how-to-create-population-pyramid-with.html' title='How to create a population pyramid with ggplot2'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB_93M13TiH6Iasi9HOj7Lh6vth4VSoIShUm4zHQSMtwrJ3MfwAAb-0BLBi4bcr3ZM5GqOi6sxVM2B_Gh6dzeGOmcqXaaR3F80GuaTW7oXWELYJePpJuQdx6YrfWA5Hr4BtZCkgQ/s72-c/Screenshot_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-8685071549739104996</id><published>2021-01-06T07:47:00.005+01:00</published><updated>2021-03-17T11:04:33.236+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Comments"/><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="Ms Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Picture"/><title type='text'>How to insert a picture in an Excel comment</title><content type='html'>&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;

  &lt;style type=&quot;text/css&quot;&gt;
    body, td {
       font-family: sans-serif;
       background-color: white;
       font-size: 12px;
       margin: 8px;
    }

    tt, code, pre {
       font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
    }

    h1 {
       font-size:2.2em;
    }

    h2 {
       font-size:1.8em;
    }

    h3 {
       font-size:1.4em;
    }

    h4 {
       font-size:1.0em;
    }

    h5 {
       font-size:0.9em;
    }

    h6 {
       font-size:0.8em;
    }

    a:visited {
       color: #2288bb;
    }


    pre {
       margin-top: 0;
       max-width: 95%;
       border: 1px solid #ccc;
       white-space: pre-wrap;
    }

    pre code {
       display: block; padding: 0.5em;
    }

    code.r, code.cpp {
       background-color: #F8F8F8;
    }

    table, td, th {
      border: none;
    }

    blockquote {
       color:#666666;
       margin:0;
       padding-left: 1em;
       border-left: 0.5em #EEE solid;
    }

    hr {
       height: 0px;
       border-bottom: none;
       border-top-width: thin;
       border-top-style: dotted;
       border-top-color: #999999;
    }

    @media print {
       * {
          background: transparent !important;
          color: black !important;
          filter:none !important;
          -ms-filter: none !important;
       }

       body {
          font-size:12pt;
          max-width:100%;
       }

       a, a:visited {
          text-decoration: underline;
       }

       hr {
          visibility: hidden;
          page-break-before: always;
       }

       pre, blockquote {
          padding-right: 1em;
          page-break-inside: avoid;
       }

       tr, img {
          page-break-inside: avoid;
       }

       img {
          max-width: 100% !important;
       }

       @page :left {
          margin: 15mm 20mm 15mm 10mm;
       }

       @page :right {
          margin: 15mm 10mm 15mm 20mm;
       }

       p, h2, h3 {
          orphans: 3; widows: 3;
       }

       h2, h3 {
          page-break-after: avoid;
       }
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- R syntax highlighter --&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
    hljs.initHighlightingOnLoad();
  &lt;/script&gt;
&lt;/head&gt;

&lt;h3&gt;Problem&lt;/h3&gt;
&lt;p&gt;

  We want to insert a picture in an Excel comment
 
  
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOS9UfXhdhz0uFU_bVeGXR2uGOarbvWbdaHloRZHWGBmXmwDX9U5J7j2DXlx2YAV9N0JJIHJU1fQs80VtadE4zy7IqQcnetMptAYvo6-LMYVGTenODOEvEiXbLcGUXimdshjO4lw/s0/Screenshot_5.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;390&quot; data-original-width=&quot;342&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOS9UfXhdhz0uFU_bVeGXR2uGOarbvWbdaHloRZHWGBmXmwDX9U5J7j2DXlx2YAV9N0JJIHJU1fQs80VtadE4zy7IqQcnetMptAYvo6-LMYVGTenODOEvEiXbLcGUXimdshjO4lw/s0/Screenshot_5.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;



&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

&lt;ol&gt;
  
&lt;li&gt;Select cell, right click, and Insert Comment.&lt;/li&gt;

  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga_E9SEcZ7jGFgJ6BkjaTWPODUgJPfFJ1gEfvckS7aSw-Qb2pYPgbxj0wYpw2TIpQQzp4i-UWcQNR5RFUVpriLY9hPMX67Tzm5hzPsOvL9x_jmAYFKxomCPAxD71lF4v_fYd11RA/s0/Screenshot_6.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;429&quot; data-original-width=&quot;204&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEga_E9SEcZ7jGFgJ6BkjaTWPODUgJPfFJ1gEfvckS7aSw-Qb2pYPgbxj0wYpw2TIpQQzp4i-UWcQNR5RFUVpriLY9hPMX67Tzm5hzPsOvL9x_jmAYFKxomCPAxD71lF4v_fYd11RA/s0/Screenshot_6.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
  &lt;li&gt;Right click on the border of the comment and clic on Format Comment.&lt;/li&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7aEoG_KEj5V-hfoKpQyV4bekjeJ8y5jaBcAkom9BjrfZyowbN0QwXp5PUf5VUoTDdzNIylbM2ixJHm7LO-Jb6yuY6uOhUZh2WDbQhRVNv0OjgCBIlJaSJ83dSSGKRmjmnw0vULA/s0/Screenshot_7.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;343&quot; data-original-width=&quot;214&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7aEoG_KEj5V-hfoKpQyV4bekjeJ8y5jaBcAkom9BjrfZyowbN0QwXp5PUf5VUoTDdzNIylbM2ixJHm7LO-Jb6yuY6uOhUZh2WDbQhRVNv0OjgCBIlJaSJ83dSSGKRmjmnw0vULA/s0/Screenshot_7.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
  &lt;li&gt;On the Colors and Lines tab, click on the drop-down arrow for Color and select Fill Effects.&lt;/li&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDB9UtbqVdNGi9rAvqNA93_1fVFhDBGVlKdVDjKQDRV1pXNzTNmJsDgvU6lwIM6R2mUcnq5yBbUStuSDXosAaw-FFWyt5qwTtVWGBxqcqtGdhjJrOAMd9V4-P56GSRG0IpjvSc-g/s0/Screenshot_8.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;438&quot; data-original-width=&quot;440&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDB9UtbqVdNGi9rAvqNA93_1fVFhDBGVlKdVDjKQDRV1pXNzTNmJsDgvU6lwIM6R2mUcnq5yBbUStuSDXosAaw-FFWyt5qwTtVWGBxqcqtGdhjJrOAMd9V4-P56GSRG0IpjvSc-g/s0/Screenshot_8.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
  
  &lt;li&gt;On the picture tab, click on Select Picture.&lt;/li&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhf5-uSnoaSRCRZTJOx3txoT3N13IctSfs5WIxu9ET7_40bU-AfvUmm2D3qrv2WHba1ZGVkInXkMT4kRU9pUcljlApaRCfSR-1qGfMWrpjggJFjBBTboaWi5qXFQ8uiXyl4OghCQ/s0/Screenshot_9.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;466&quot; data-original-width=&quot;394&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhf5-uSnoaSRCRZTJOx3txoT3N13IctSfs5WIxu9ET7_40bU-AfvUmm2D3qrv2WHba1ZGVkInXkMT4kRU9pUcljlApaRCfSR-1qGfMWrpjggJFjBBTboaWi5qXFQ8uiXyl4OghCQ/s0/Screenshot_9.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  &lt;li&gt;Select the picture, insert, and click OK.&lt;/li&gt;
  &lt;li&gt;Resize the picture by draggin the border of the comment.&lt;/li&gt;
  &lt;li&gt;Hide if you only want to show the picture when you hover over the cell.&lt;/li&gt;
  
  
&lt;/ol&gt;
  
&lt;h3&gt;Related Posts&lt;/h3&gt;&lt;p&gt;
  


 </content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/8685071549739104996/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/01/how-to-insert-picture-in-excel-comment.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/8685071549739104996'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/8685071549739104996'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/01/how-to-insert-picture-in-excel-comment.html' title='How to insert a picture in an Excel comment'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOS9UfXhdhz0uFU_bVeGXR2uGOarbvWbdaHloRZHWGBmXmwDX9U5J7j2DXlx2YAV9N0JJIHJU1fQs80VtadE4zy7IqQcnetMptAYvo6-LMYVGTenODOEvEiXbLcGUXimdshjO4lw/s72-c/Screenshot_5.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-3328080645461800557</id><published>2021-01-04T07:50:00.001+01:00</published><updated>2021-01-04T07:50:01.497+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Comentarios"/><category scheme="http://www.blogger.com/atom/ns#" term="Imagen"/><category scheme="http://www.blogger.com/atom/ns#" term="Ms Excel"/><title type='text'>Cómo insertar una imagen en comentario de una celda en Excel</title><content type='html'>&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;

  &lt;style type=&quot;text/css&quot;&gt;
    body, td {
       font-family: sans-serif;
       background-color: white;
       font-size: 12px;
       margin: 8px;
    }

    tt, code, pre {
       font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
    }

    h1 {
       font-size:2.2em;
    }

    h2 {
       font-size:1.8em;
    }

    h3 {
       font-size:1.4em;
    }

    h4 {
       font-size:1.0em;
    }

    h5 {
       font-size:0.9em;
    }

    h6 {
       font-size:0.8em;
    }

    a:visited {
       color: #2288bb;
    }


    pre {
       margin-top: 0;
       max-width: 95%;
       border: 1px solid #ccc;
       white-space: pre-wrap;
    }

    pre code {
       display: block; padding: 0.5em;
    }

    code.r, code.cpp {
       background-color: #F8F8F8;
    }

    table, td, th {
      border: none;
    }

    blockquote {
       color:#666666;
       margin:0;
       padding-left: 1em;
       border-left: 0.5em #EEE solid;
    }

    hr {
       height: 0px;
       border-bottom: none;
       border-top-width: thin;
       border-top-style: dotted;
       border-top-color: #999999;
    }

    @media print {
       * {
          background: transparent !important;
          color: black !important;
          filter:none !important;
          -ms-filter: none !important;
       }

       body {
          font-size:12pt;
          max-width:100%;
       }

       a, a:visited {
          text-decoration: underline;
       }

       hr {
          visibility: hidden;
          page-break-before: always;
       }

       pre, blockquote {
          padding-right: 1em;
          page-break-inside: avoid;
       }

       tr, img {
          page-break-inside: avoid;
       }

       img {
          max-width: 100% !important;
       }

       @page :left {
          margin: 15mm 20mm 15mm 10mm;
       }

       @page :right {
          margin: 15mm 10mm 15mm 20mm;
       }

       p, h2, h3 {
          orphans: 3; widows: 3;
       }

       h2, h3 {
          page-break-after: avoid;
       }
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- R syntax highlighter --&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
    hljs.initHighlightingOnLoad();
  &lt;/script&gt;
&lt;/head&gt;

&lt;h3&gt;Problema&lt;/h3&gt;
&lt;p&gt;
Queremos insertar una imagen en el comentario de una celda en Excel
  
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOS9UfXhdhz0uFU_bVeGXR2uGOarbvWbdaHloRZHWGBmXmwDX9U5J7j2DXlx2YAV9N0JJIHJU1fQs80VtadE4zy7IqQcnetMptAYvo6-LMYVGTenODOEvEiXbLcGUXimdshjO4lw/s0/Screenshot_5.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;390&quot; data-original-width=&quot;342&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOS9UfXhdhz0uFU_bVeGXR2uGOarbvWbdaHloRZHWGBmXmwDX9U5J7j2DXlx2YAV9N0JJIHJU1fQs80VtadE4zy7IqQcnetMptAYvo6-LMYVGTenODOEvEiXbLcGUXimdshjO4lw/s0/Screenshot_5.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;



&lt;h3&gt;Solución&lt;/h3&gt;&lt;p&gt;

&lt;ol&gt;
  
&lt;li&gt;Seleccionamo una celda, clic con el botón derecho e insertamos un comentario.&lt;/li&gt;
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimwrMyaCkXIj7C9kdpnhIcxyZW4JVwI3VnEeJNVsI7FpynpK599JH5nr_oVZ9LcNOwGU0CYN7Y2X5GIm-KcMHfVX6VRLs4TY5NrSp0cFsvV4Kvlyl6rkg2w8OSCUeFbBaqkUhZJQ/s0/Screenshot_1.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;427&quot; data-original-width=&quot;215&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimwrMyaCkXIj7C9kdpnhIcxyZW4JVwI3VnEeJNVsI7FpynpK599JH5nr_oVZ9LcNOwGU0CYN7Y2X5GIm-KcMHfVX6VRLs4TY5NrSp0cFsvV4Kvlyl6rkg2w8OSCUeFbBaqkUhZJQ/s0/Screenshot_1.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  &lt;li&gt;Clic con el botón derecho en el borde del comentario y luego en Formato de comentario.&lt;/li&gt;
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHOd0_a54IWMWFZQHKmpGK22c4pdheEDo3sDr_nfQJavLsVDP48ezpmR8MhdK1GmM2Rl4ZrcqNzNRlwdlDMYPT2w3WaT-aj_v0lzDXJWH1SSrUxqciJMIxqKY7ra7GRg_ac41XfQ/s0/Screenshot_2.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;380&quot; data-original-width=&quot;318&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHOd0_a54IWMWFZQHKmpGK22c4pdheEDo3sDr_nfQJavLsVDP48ezpmR8MhdK1GmM2Rl4ZrcqNzNRlwdlDMYPT2w3WaT-aj_v0lzDXJWH1SSrUxqciJMIxqKY7ra7GRg_ac41XfQ/s0/Screenshot_2.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  &lt;li&gt;En la pestaña Colores y líneas,  clic en el desplegable color y selecciona Efectos de relleno.&lt;/li&gt;
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR59tmuR0QQJinFnqQ_ye4zFb0JbUDhqLROFdLo5jpiS5v_fYIwYVqOhcrw1U6xKLDxOp1eSEUtVsRaPSHumXS5iSHG1nR8e15Xix4eLVsciM9mtoLafQUUHuusuvWSmKuy4wBDQ/s0/Screenshot_3.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;437&quot; data-original-width=&quot;435&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR59tmuR0QQJinFnqQ_ye4zFb0JbUDhqLROFdLo5jpiS5v_fYIwYVqOhcrw1U6xKLDxOp1eSEUtVsRaPSHumXS5iSHG1nR8e15Xix4eLVsciM9mtoLafQUUHuusuvWSmKuy4wBDQ/s0/Screenshot_3.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  &lt;li&gt;En la pestaña imagen, clic en Seleccionar Imagen.&lt;/li&gt;
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjD_BeSBOS_XNhMzcyZibR5BCuYmOgzYwdi5KGesCRQhc8Zjq_KUShQoWKrosYatTHCi77QG1KZbXFGeLSuSVkbTPMArcY-JGypBoZB1OYTCElVL1PpA9zvAa3JEqYcZWcr-g_p_Q/s0/Screenshot_4.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;461&quot; data-original-width=&quot;409&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjD_BeSBOS_XNhMzcyZibR5BCuYmOgzYwdi5KGesCRQhc8Zjq_KUShQoWKrosYatTHCi77QG1KZbXFGeLSuSVkbTPMArcY-JGypBoZB1OYTCElVL1PpA9zvAa3JEqYcZWcr-g_p_Q/s0/Screenshot_4.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  &lt;li&gt;Seleccionamos la imagen, insertar, y aceptar.&lt;/li&gt;
  &lt;li&gt;Ajustamos el tamaño de la imagen arrastrando los bordes del comentario.&lt;/li&gt;
  &lt;li&gt;Ocultamos el comentario si solamente queremos que aparezca al pasar el cursor por encima.&lt;/li&gt;
  
  
&lt;/ol&gt;
  
&lt;h3&gt;Entradas relacionadas&lt;/h3&gt;&lt;p&gt;
  


 </content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/3328080645461800557/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/01/como-insertar-una-imagen-en-comentario.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3328080645461800557'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3328080645461800557'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/01/como-insertar-una-imagen-en-comentario.html' title='Cómo insertar una imagen en comentario de una celda en Excel'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOS9UfXhdhz0uFU_bVeGXR2uGOarbvWbdaHloRZHWGBmXmwDX9U5J7j2DXlx2YAV9N0JJIHJU1fQs80VtadE4zy7IqQcnetMptAYvo6-LMYVGTenODOEvEiXbLcGUXimdshjO4lw/s72-c/Screenshot_5.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-2644042685352685088</id><published>2021-01-01T05:54:00.001+01:00</published><updated>2021-01-01T05:54:04.663+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="as.POSIXct"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="seq"/><title type='text'>Cómo crear una serie temporal con intervalos de 30 minutos</title><content type='html'>&lt;head&gt;


&lt;title&gt;Title&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;

&lt;h3&gt;Problema&lt;/h3&gt;&lt;p&gt;

Queremos crear una serie temporal de intervalos de 30 minutos.
  &lt;p&gt;

&lt;h3&gt;Ejemplo&lt;/h3&gt;&lt;p&gt;
&lt;pre&gt;&lt;code&gt;[1] &quot;2017-01-01 00:00:00 UTC&quot;
[2] &quot;2017-01-01 00:30:00 UTC&quot;
[3] &quot;2017-01-01 01:00:00 UTC&quot;
[4] &quot;2017-01-01 01:30:00 UTC&quot;
[5] &quot;2017-01-01 02:00:00 UTC&quot;
[6] &quot;2017-01-01 02:30:00 UTC&quot;&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;


&lt;h3&gt;Solución&lt;/h3&gt;&lt;p&gt;

Usamos la función &lt;i&gt;seq&lt;/i&gt; y especificando los minutos en el argumento &lt;i&gt;by&lt;/i&gt;, así como el uso horario &quot;UTC&quot;. Tecleamos ?seq.POSIXt para obtener más detalles sobre el argumento que podemos especificar como cadena sde texto:
  
 &lt;blockquote&gt;A character string, containing one of &quot;sec&quot;, &quot;min&quot;, &quot;hour&quot;, &quot;day&quot;, &quot;DSTday&quot;, &quot;week&quot;, &quot;month&quot;, &quot;quarter&quot; or &quot;year&quot;. This can optionally be preceded by a (positive or negative) integer and a space, or followed by &quot;s&quot;.
&lt;/blockquote&gt; &lt;p&gt;


&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;seq(as.POSIXct(&quot;2017-01-01&quot;, tz = &quot;UTC&quot;),
    as.POSIXct(&quot;2017-01-02&quot;, tz = &quot;UTC&quot;),
    by = &quot;30 min&quot;)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;&lt;p&gt;


&lt;h3&gt;Referencias&lt;/h3&gt;&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/35296749/create-a-time-series-by-30-minute-intervals/32831598#32831598&quot; target=&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/2644042685352685088/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2021/01/como-crear-una-serie-temporal-con.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/2644042685352685088'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/2644042685352685088'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2021/01/como-crear-una-serie-temporal-con.html' title='Cómo crear una serie temporal con intervalos de 30 minutos'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-3036182501185798666</id><published>2020-12-23T05:35:00.008+01:00</published><updated>2020-12-23T05:35:04.661+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="as.POSIXct"/><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="seq"/><title type='text'>How to create a time series by 30 minute intervals</title><content type='html'>&lt;head&gt;


&lt;title&gt;Title&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;

&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
  
We want to create a time series by 30 minute intervals.&lt;p&gt;

&lt;h3&gt;Example&lt;/h3&gt;&lt;p&gt;
&lt;pre&gt;&lt;code&gt;[1] &quot;2017-01-01 00:00:00 UTC&quot;
[2] &quot;2017-01-01 00:30:00 UTC&quot;
[3] &quot;2017-01-01 01:00:00 UTC&quot;
[4] &quot;2017-01-01 01:30:00 UTC&quot;
[5] &quot;2017-01-01 02:00:00 UTC&quot;
[6] &quot;2017-01-01 02:30:00 UTC&quot;&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;


&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;


We use the function &lt;i&gt;seq&lt;/i&gt; and specify minutes in the &lt;i&gt;by&lt;/i&gt; argument, and pass the time zone &quot;UTC&quot;. Type ?seq.POSIXt for more details about the by argument specified as a character string:
  
 &lt;blockquote&gt;A character string, containing one of &quot;sec&quot;, &quot;min&quot;, &quot;hour&quot;, &quot;day&quot;, &quot;DSTday&quot;, &quot;week&quot;, &quot;month&quot;, &quot;quarter&quot; or &quot;year&quot;. This can optionally be preceded by a (positive or negative) integer and a space, or followed by &quot;s&quot;.
&lt;/blockquote&gt; &lt;p&gt;


&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;seq(as.POSIXct(&quot;2017-01-01&quot;, tz = &quot;UTC&quot;),
    as.POSIXct(&quot;2017-01-02&quot;, tz = &quot;UTC&quot;),
    by = &quot;30 min&quot;)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;&lt;p&gt;


&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/35296749/create-a-time-series-by-30-minute-intervals/32831598#32831598&quot; target=&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/3036182501185798666/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-create-time-series-by-30-minute.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3036182501185798666'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3036182501185798666'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-create-time-series-by-30-minute.html' title='How to create a time series by 30 minute intervals'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-276642097056628331</id><published>2020-12-21T05:50:00.000+01:00</published><updated>2020-12-21T05:50:01.682+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Data frame"/><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="lower.tri"/><category scheme="http://www.blogger.com/atom/ns#" term="matrix"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="t"/><category scheme="http://www.blogger.com/atom/ns#" term="upper.tri"/><title type='text'>How to create a symmetric matrix in R</title><content type='html'>&lt;head&gt;


&lt;title&gt;Title&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;

&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
  
We want to create a symmetric matrix based on the following example.&lt;p&gt;

&lt;h3&gt;Example&lt;/h3&gt;&lt;p&gt;
&lt;pre&gt;&lt;code&gt;  V1 V2 V3 V4 V5
1  0  2  3  4  5
2  0  0  6  8 10
3  0  0  0 12 15
4  0  0  0  0 20
5  0  0  0  0  0
&lt;/pre&gt;&lt;/code&gt;



&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df &lt;- structure(list(V1 = c(0L, 0L, 0L, 0L, 0L), V2 = c(2L, 0L, 0L, 
0L, 0L), V3 = c(3L, 6L, 0L, 0L, 0L), V4 = c(4L, 8L, 12L, 0L, 
0L), V5 = c(5L, 10L, 15L, 20L, 0L)), .Names = c(&quot;V1&quot;, &quot;V2&quot;, &quot;V3&quot;, 
&quot;V4&quot;, &quot;V5&quot;), class = &quot;data.frame&quot;, row.names = c(&quot;1&quot;, &quot;2&quot;, &quot;3&quot;, 
&quot;4&quot;, &quot;5&quot;))
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;



&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;


&lt;li&gt;Adding the transpose of the matrix.&lt;/li&gt;&lt;p&gt;


&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df + t(df)&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;



&lt;li&gt;Function &lt;i&gt;lower.tri&lt;/i&gt;&lt;/li&gt;&lt;p&gt;
We assign to the lower triangle of the matrix the transpose of the lower triangle.&lt;p&gt;
&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df[lower.tri(df)] &lt;- t(df)[lower.tri(df)]&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;pre&gt;&lt;code&gt;  V1 V2 V3 V4 V5
1  0  2  3  4  5
2  2  0  6  8 10
3  3  6  0 12 15
4  4  8 12  0 20
5  5 10 15 20  0&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;

 Using &lt;i&gt;upper.tri&lt;/i&gt; would not create a symmetrical matrix.

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;df[lower.tri(df)] &lt;- df[upper.tri(df)]&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;


&lt;pre&gt;&lt;code&gt;  V1 V2 V3 V4 V5
1  0  2  3  4  5
2  2  0  6  8 10
3  3  8  0 12 15
4  6 12 10  0 20
5  4  5 15 20  0
&lt;/pre&gt;&lt;/code&gt;

&lt;/ul&gt;




&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/32770004/most-efficient-way-to-create-a-symmetric-matrix/32770064#32770064&quot; target=&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/276642097056628331/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-create-symmetric-matrix-in-r.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/276642097056628331'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/276642097056628331'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-create-symmetric-matrix-in-r.html' title='How to create a symmetric matrix in R'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-6405819008146064845</id><published>2020-12-18T06:01:00.001+01:00</published><updated>2020-12-18T06:01:12.189+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="ggplot2"/><category scheme="http://www.blogger.com/atom/ns#" term="grid"/><category scheme="http://www.blogger.com/atom/ns#" term="legend"/><category scheme="http://www.blogger.com/atom/ns#" term="legend.margin"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><title type='text'>How to change the spacing between the legend and the panel in ggplot2</title><content type='html'>&lt;head&gt;


&lt;title&gt;Title&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 1;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;

&lt;/head&gt;

&lt;h3&gt;Problema&lt;/h3&gt;&lt;p&gt;
We want to increase the spacing between the legend and the panel in ggplot2.&lt;p&gt;



&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(ggplot2)
xy &lt;- data.frame(x = 1:10, y = 10:1, type = rep(LETTERS[1:2], each=5))
plot &lt;- ggplot(data = xy) +
        geom_point(aes(x = x, y = y, colo r= type))
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKF6QvT5fcya4t5Fw6LK-MI1sQ-WMLcvkVoD9WjhTTCIUz-EJ_lxQoHHhT0x_zd04yX2IeeMfVNvBlEUNn3S_cOpb5LC9mZ8YwxS59-ehfUhQUYCe-QxmnQjZjEjNxEy0uuThTFQ/s0/Screenshot_7.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;389&quot; data-original-width=&quot;464&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKF6QvT5fcya4t5Fw6LK-MI1sQ-WMLcvkVoD9WjhTTCIUz-EJ_lxQoHHhT0x_zd04yX2IeeMfVNvBlEUNn3S_cOpb5LC9mZ8YwxS59-ehfUhQUYCe-QxmnQjZjEjNxEy0uuThTFQ/s0/Screenshot_7.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
&lt;p&gt;

&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

We use the argument &lt;i&gt;legend.box.margin&lt;/i&gt; to add 20 points to the left. &lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;plot &lt;- plot + theme(legend.box.margin = margin(0, 0, 0, 20))
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxj5fDpjjhv2yLPyKGSTIVG5IEGNqb6eLAmnllxvFmEb-TAUpOjI6ztBMGreCmqkQethrFw_tQkoGYAkyTOITfmhQfibKOS1gqd9eUHYuk8XpgogYMZduKRzu7v341FukVe4pGNA/s0/Screenshot_6.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;385&quot; data-original-width=&quot;460&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhxj5fDpjjhv2yLPyKGSTIVG5IEGNqb6eLAmnllxvFmEb-TAUpOjI6ztBMGreCmqkQethrFw_tQkoGYAkyTOITfmhQfibKOS1gqd9eUHYuk8XpgogYMZduKRzu7v341FukVe4pGNA/s0/Screenshot_6.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;


&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://stackoverflow.com/questions/33615936/adjusting-legends-spacing-to-main-plot/33616502#33616502&quot; target =&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/6405819008146064845/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-change-spacing-between-legend.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/6405819008146064845'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/6405819008146064845'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-change-spacing-between-legend.html' title='How to change the spacing between the legend and the panel in ggplot2'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKF6QvT5fcya4t5Fw6LK-MI1sQ-WMLcvkVoD9WjhTTCIUz-EJ_lxQoHHhT0x_zd04yX2IeeMfVNvBlEUNn3S_cOpb5LC9mZ8YwxS59-ehfUhQUYCe-QxmnQjZjEjNxEy0uuThTFQ/s72-c/Screenshot_7.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-3990995542213420533</id><published>2020-12-17T11:45:00.002+01:00</published><updated>2020-12-17T11:45:48.081+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clearcomments"/><category scheme="http://www.blogger.com/atom/ns#" term="Comments"/><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Ms Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="UsedRange"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><category scheme="http://www.blogger.com/atom/ns#" term="Worksheets"/><title type='text'>Cómo eliminar todos los comentarios en Excel</title><content type='html'>&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;

  &lt;style type=&quot;text/css&quot;&gt;
    body, td {
       font-family: sans-serif;
       background-color: white;
       font-size: 12px;
       margin: 8px;
    }

    tt, code, pre {
       font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
    }

    h1 {
       font-size:2.2em;
    }

    h2 {
       font-size:1.8em;
    }

    h3 {
       font-size:1.4em;
    }

    h4 {
       font-size:1.0em;
    }

    h5 {
       font-size:0.9em;
    }

    h6 {
       font-size:0.8em;
    }

    a:visited {
       color: #2288bb;
    }


    pre {
       margin-top: 0;
       max-width: 95%;
       border: 1px solid #ccc;
       white-space: pre-wrap;
    }

    pre code {
       display: block; padding: 0.5em;
    }

    code.r, code.cpp {
       background-color: #F8F8F8;
    }

    table, td, th {
      border: none;
    }

    blockquote {
       color:#666666;
       margin:0;
       padding-left: 1em;
       border-left: 0.5em #EEE solid;
    }

    hr {
       height: 0px;
       border-bottom: none;
       border-top-width: thin;
       border-top-style: dotted;
       border-top-color: #999999;
    }

    @media print {
       * {
          background: transparent !important;
          color: black !important;
          filter:none !important;
          -ms-filter: none !important;
       }

       body {
          font-size:12pt;
          max-width:100%;
       }

       a, a:visited {
          text-decoration: underline;
       }

       hr {
          visibility: hidden;
          page-break-before: always;
       }

       pre, blockquote {
          padding-right: 1em;
          page-break-inside: avoid;
       }

       tr, img {
          page-break-inside: avoid;
       }

       img {
          max-width: 100% !important;
       }

       @page :left {
          margin: 15mm 20mm 15mm 10mm;
       }

       @page :right {
          margin: 15mm 10mm 15mm 20mm;
       }

       p, h2, h3 {
          orphans: 3; widows: 3;
       }

       h2, h3 {
          page-break-after: avoid;
       }
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- R syntax highlighter --&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
    hljs.initHighlightingOnLoad();
  &lt;/script&gt;
&lt;/head&gt;

&lt;h3&gt;Problema&lt;/h3&gt;
&lt;p&gt;
Queremos borrar todos los comentarios en Excel. Veremos tres alternativas, en la última usaremos VBA
  
  



&lt;h3&gt;Solución&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
  &lt;li&gt;Opción 1&lt;/li&gt;
&lt;ol&gt;
  
  &lt;li&gt;En la pestaña Revisar clic en Mostrar todos los comentarios&lt;/li&gt;
  
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiil6IrcPyS2513OdqvMgq4ixCMbBJjU3ZUl8n_I1X1OxWzyhs6igWd-5SnLBrtBZi0_6lkOWviDs24S-QL0dx55sVEZCXLskU27x5idGSdGoofYTLlx8L5b4CKUAgPMbuZBjrdHA/s0/Screenshot_1.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;264&quot; data-original-width=&quot;505&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiil6IrcPyS2513OdqvMgq4ixCMbBJjU3ZUl8n_I1X1OxWzyhs6igWd-5SnLBrtBZi0_6lkOWviDs24S-QL0dx55sVEZCXLskU27x5idGSdGoofYTLlx8L5b4CKUAgPMbuZBjrdHA/s0/Screenshot_1.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
  &lt;li&gt;Press Ctrl+E para seleccionar todos los comentarios&lt;/li&gt;
  
  &lt;li&gt;Clic en Eliminar&lt;/li&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpdim2o4-T1Z75QKfXlmaweg9rdi9rZRGjm3on_pe-oSU7ip1byUO7nRXYlPC7hxJKLGZP6SockL05G-1JjdjF0Zok7K4u-ccEvxjkme8jDn5-fNMmq2sqrrgtCBzkDK73JnFmgg/s0/Screenshot_3.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;452&quot; data-original-width=&quot;673&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjpdim2o4-T1Z75QKfXlmaweg9rdi9rZRGjm3on_pe-oSU7ip1byUO7nRXYlPC7hxJKLGZP6SockL05G-1JjdjF0Zok7K4u-ccEvxjkme8jDn5-fNMmq2sqrrgtCBzkDK73JnFmgg/s0/Screenshot_3.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
  
  
&lt;/ol&gt;
  
  &lt;li&gt;Opción 2&lt;/li&gt;
  
  &lt;ol&gt;
  &lt;li&gt;Presionamos F5 o Ctrl + I para abrir el cuadro de diálogo Ir a, clic en Especial &lt;/li&gt;

    &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHKxX7cEKz0XEKvcGroaBM3N_R6RVJeGwNZOicDDG2UjXUDDlYh6qDgvpjqUS7mDgztVGUOYe80USyj_p2yWXdOhNs_YtCEFDB_H5dZrnGGjeZSNm7G4JAuWPVf39mK2Qsl2K4LA/s0/Screenshot_2.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;334&quot; data-original-width=&quot;471&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgHKxX7cEKz0XEKvcGroaBM3N_R6RVJeGwNZOicDDG2UjXUDDlYh6qDgvpjqUS7mDgztVGUOYe80USyj_p2yWXdOhNs_YtCEFDB_H5dZrnGGjeZSNm7G4JAuWPVf39mK2Qsl2K4LA/s0/Screenshot_2.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
    &lt;li&gt;Todos los comentarios serán seleccionados&lt;/li&gt;
    
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSqRNsp4j9qXzyJ5FPOAb9u70O4_k66nOsa14vPp57Y0iynA44_fqB7KX7qZQeCjWvWpq-QG0czy_1PVMNYbpZImGyRY3Ky3_2Zli7zIn2bLgBBgGuuz5Ip4ox6QdGPEqRSLWNhQ/s0/Screenshot_4.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;257&quot; data-original-width=&quot;508&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSqRNsp4j9qXzyJ5FPOAb9u70O4_k66nOsa14vPp57Y0iynA44_fqB7KX7qZQeCjWvWpq-QG0czy_1PVMNYbpZImGyRY3Ky3_2Zli7zIn2bLgBBgGuuz5Ip4ox6QdGPEqRSLWNhQ/s0/Screenshot_4.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
 
    &lt;li&gt;Clic con el botón derecho para abrir el menú contextual y clic en Eliminar comentario&lt;/li&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimmFeF7L_glKjbj2pkKuxLBTnJob5ExG4wD2ZN25aFHnaOXCwt63EKTL9V4wtx5qDaxy2ld93HbCuIBuHM978pK8NbrK-xRgCY1GkkBCzu8k3X-9HUbe4vgcyxHlgSEfiWMUYMew/s0/Screenshot_5.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;477&quot; data-original-width=&quot;214&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEimmFeF7L_glKjbj2pkKuxLBTnJob5ExG4wD2ZN25aFHnaOXCwt63EKTL9V4wtx5qDaxy2ld93HbCuIBuHM978pK8NbrK-xRgCY1GkkBCzu8k3X-9HUbe4vgcyxHlgSEfiWMUYMew/s0/Screenshot_5.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
    
    
&lt;/ol&gt;
  &lt;li&gt;Opción 3 - VBA&lt;/li&gt;
&lt;ol&gt;  
  &lt;li&gt;Borra todos los comentarios de la hoja activa&lt;/li&gt;
  
 &lt;pre class=&quot;prettyprint lang-vb&quot;&gt;Sub Borra_Comentarios_de_la_Hoja()
 Cells.ClearComments
End Sub
&lt;/pre&gt; 
    &lt;li&gt;Borra todos los comentarios del libro de Excel&lt;/li&gt;
 &lt;pre class=&quot;prettyprint lang-vb&quot;&gt;Sub Borra_todos_los_Comentarios()
    Dim ws As Worksheet

    For Each ws In Worksheets
        ws.UsedRange.ClearComments
    Next

End Sub
&lt;/pre&gt;  


    &lt;/ol&gt;
  &lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/3990995542213420533/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2020/12/como-eliminar-todos-los-comentarios-en.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3990995542213420533'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3990995542213420533'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2020/12/como-eliminar-todos-los-comentarios-en.html' title='Cómo eliminar todos los comentarios en Excel'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiil6IrcPyS2513OdqvMgq4ixCMbBJjU3ZUl8n_I1X1OxWzyhs6igWd-5SnLBrtBZi0_6lkOWviDs24S-QL0dx55sVEZCXLskU27x5idGSdGoofYTLlx8L5b4CKUAgPMbuZBjrdHA/s72-c/Screenshot_1.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-6350026318321042731</id><published>2020-12-14T05:57:00.001+01:00</published><updated>2020-12-14T05:57:00.246+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Clearcomments"/><category scheme="http://www.blogger.com/atom/ns#" term="Comments"/><category scheme="http://www.blogger.com/atom/ns#" term="Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="Ms Excel"/><category scheme="http://www.blogger.com/atom/ns#" term="UsedRange"/><category scheme="http://www.blogger.com/atom/ns#" term="VBA"/><category scheme="http://www.blogger.com/atom/ns#" term="Worksheets"/><title type='text'>How to remove all comments in Excel</title><content type='html'>&lt;head&gt;
  &lt;title&gt;Title&lt;/title&gt;

  &lt;style type=&quot;text/css&quot;&gt;
    body, td {
       font-family: sans-serif;
       background-color: white;
       font-size: 12px;
       margin: 8px;
    }

    tt, code, pre {
       font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
    }

    h1 {
       font-size:2.2em;
    }

    h2 {
       font-size:1.8em;
    }

    h3 {
       font-size:1.4em;
    }

    h4 {
       font-size:1.0em;
    }

    h5 {
       font-size:0.9em;
    }

    h6 {
       font-size:0.8em;
    }

    a:visited {
       color: #2288bb;
    }


    pre {
       margin-top: 0;
       max-width: 95%;
       border: 1px solid #ccc;
       white-space: pre-wrap;
    }

    pre code {
       display: block; padding: 0.5em;
    }

    code.r, code.cpp {
       background-color: #F8F8F8;
    }

    table, td, th {
      border: none;
    }

    blockquote {
       color:#666666;
       margin:0;
       padding-left: 1em;
       border-left: 0.5em #EEE solid;
    }

    hr {
       height: 0px;
       border-bottom: none;
       border-top-width: thin;
       border-top-style: dotted;
       border-top-color: #999999;
    }

    @media print {
       * {
          background: transparent !important;
          color: black !important;
          filter:none !important;
          -ms-filter: none !important;
       }

       body {
          font-size:12pt;
          max-width:100%;
       }

       a, a:visited {
          text-decoration: underline;
       }

       hr {
          visibility: hidden;
          page-break-before: always;
       }

       pre, blockquote {
          padding-right: 1em;
          page-break-inside: avoid;
       }

       tr, img {
          page-break-inside: avoid;
       }

       img {
          max-width: 100% !important;
       }

       @page :left {
          margin: 15mm 20mm 15mm 10mm;
       }

       @page :right {
          margin: 15mm 10mm 15mm 20mm;
       }

       p, h2, h3 {
          orphans: 3; widows: 3;
       }

       h2, h3 {
          page-break-after: avoid;
       }
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- Styles for R syntax highlighter --&gt;
  &lt;style type=&quot;text/css&quot;&gt;
    pre .operator,
    pre .paren {
      color: rgb(104, 118, 135)
    }

    pre .literal {
      color: rgb(88, 72, 246)
    }

    pre .number {
      color: rgb(0, 0, 205);
    }

    pre .comment {
      color: rgb(76, 136, 107);
    }

    pre .keyword {
      color: rgb(0, 0, 255);
    }

    pre .identifier {
      color: rgb(0, 0, 0);
    }

    pre .string {
      color: rgb(3, 106, 7);
    }
  &lt;/style&gt;

  &lt;!-- R syntax highlighter --&gt;
  &lt;script type=&quot;text/javascript&quot;&gt;
    var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
    hljs.initHighlightingOnLoad();
  &lt;/script&gt;
&lt;/head&gt;

&lt;h3&gt;Problem&lt;/h3&gt;
&lt;p&gt;
We want to delete all comments in Excel. We will see three alternative, the last one using VBA.
  



&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
  &lt;li&gt;Option 1&lt;/li&gt;
&lt;ol&gt;
  
  &lt;li&gt;On the Review tab click on Show all comments&lt;/li&gt;
  
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfVUa26gvvp0JZslmNE8HVa-mUhf8CV_IWbHCu5BxiBo1yDRhhO0JFP4q8GphokuwGZVMUAotmCKkXy5p7c8342TBaoTLX92H_nNzbmPywlc-C3O8FRNvfqGX0f7SPGJvvlmVXDA/s0/Screenshot_2.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;400&quot; data-original-width=&quot;566&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfVUa26gvvp0JZslmNE8HVa-mUhf8CV_IWbHCu5BxiBo1yDRhhO0JFP4q8GphokuwGZVMUAotmCKkXy5p7c8342TBaoTLX92H_nNzbmPywlc-C3O8FRNvfqGX0f7SPGJvvlmVXDA/s0/Screenshot_2.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
  &lt;li&gt;Press Ctrl+A to select all comments&lt;/li&gt;
  
  &lt;li&gt;Click on Delete&lt;/li&gt;
 &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-s4rB4p5or4PRha_8-87yI5tw5btwjIZEI6BzYR53Nwo6kQQQJ0rivHHH8HRVg9bYrToXLqr4txwwY7NM_CABRSmFwE9lGBqaIAOEi_YCzE_N-CqUXmY_sGdIIDHNibKSLrxGmA/s0/Screenshot_3.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;451&quot; data-original-width=&quot;564&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-s4rB4p5or4PRha_8-87yI5tw5btwjIZEI6BzYR53Nwo6kQQQJ0rivHHH8HRVg9bYrToXLqr4txwwY7NM_CABRSmFwE9lGBqaIAOEi_YCzE_N-CqUXmY_sGdIIDHNibKSLrxGmA/s0/Screenshot_3.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt; 
  
  
  
&lt;/ol&gt;
  
  &lt;li&gt;Option 2&lt;/li&gt;
  
  &lt;ol&gt;
  &lt;li&gt;Press F5 or Ctrl + G to open Go To dialog box, click on Special and then OK&lt;/li&gt;
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjt5mSo4wZmxTXeofyDFN9SJJ4EHJtL4EToYG2DDKSOW9LFCp04GFfc-ZpyKdON2VtynydZK-QfdvwvLiE7GSsebXQoNSnj5N8zCjDQamni14BVnpSa_yxKsN_bHODp0T-y6TlnuQ/s0/Screenshot_4.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;337&quot; data-original-width=&quot;323&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjt5mSo4wZmxTXeofyDFN9SJJ4EHJtL4EToYG2DDKSOW9LFCp04GFfc-ZpyKdON2VtynydZK-QfdvwvLiE7GSsebXQoNSnj5N8zCjDQamni14BVnpSa_yxKsN_bHODp0T-y6TlnuQ/s0/Screenshot_4.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  
    &lt;li&gt;All comments will be selected&lt;/li&gt;
    
   &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-kiPjuGMOdpL8Hmu1VzNKnVY2ztaTIhtH2nluo4IBvlK4y9EpKXuaQc6csUk8Md2fVJNXD7cdGovqXYuDJ-27DI35RqlE0f9QHAlfvE_AUaM0avrd2yH5YQi0KlJVkAgOOyJbfg/s0/Screenshot_5.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;259&quot; data-original-width=&quot;456&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh-kiPjuGMOdpL8Hmu1VzNKnVY2ztaTIhtH2nluo4IBvlK4y9EpKXuaQc6csUk8Md2fVJNXD7cdGovqXYuDJ-27DI35RqlE0f9QHAlfvE_AUaM0avrd2yH5YQi0KlJVkAgOOyJbfg/s0/Screenshot_5.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt; 
 
    &lt;li&gt;Right click to open context menu and click on Delete Comment&lt;/li&gt;
    &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSeKHgnoYceJ76_JlmMxXllNol1b1S_mkbLjKTrHuVz0FN8H_BuqENl_s6Z58xT0vloY_961rekO6AJt6XMtyFRXxT1EbOX1-jceM_amYgfc1nemDne0lvSuVMIv03QFmTjiHExg/s0/Screenshot_6.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;468&quot; data-original-width=&quot;202&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhSeKHgnoYceJ76_JlmMxXllNol1b1S_mkbLjKTrHuVz0FN8H_BuqENl_s6Z58xT0vloY_961rekO6AJt6XMtyFRXxT1EbOX1-jceM_amYgfc1nemDne0lvSuVMIv03QFmTjiHExg/s0/Screenshot_6.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
    
    
&lt;/ol&gt;
  &lt;li&gt;Option 3 - VBA&lt;/li&gt;
&lt;ol&gt;  
  &lt;li&gt;Delete all comments from active sheet&lt;/li&gt;
  
 &lt;pre class=&quot;prettyprint lang-vb&quot;&gt;Sub Delete_Comments_from_Sheet()
 Cells.ClearComments
End Sub
&lt;/pre&gt; 
    &lt;li&gt;Delete all comments from the workbook&lt;/li&gt;
 &lt;pre class=&quot;prettyprint lang-vb&quot;&gt;Sub Delete_All_Comments()
    Dim ws As Worksheet

    For Each ws In Worksheets
        ws.UsedRange.ClearComments
    Next

End Sub
&lt;/pre&gt;  


    &lt;/ol&gt;
  &lt;/ul&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/6350026318321042731/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-remove-all-comments-in-excel.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/6350026318321042731'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/6350026318321042731'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-remove-all-comments-in-excel.html' title='How to remove all comments in Excel'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfVUa26gvvp0JZslmNE8HVa-mUhf8CV_IWbHCu5BxiBo1yDRhhO0JFP4q8GphokuwGZVMUAotmCKkXy5p7c8342TBaoTLX92H_nNzbmPywlc-C3O8FRNvfqGX0f7SPGJvvlmVXDA/s72-c/Screenshot_2.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-7130897540666812229</id><published>2020-12-11T05:30:00.002+01:00</published><updated>2020-12-11T09:09:02.775+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="boxplot"/><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_boxplot"/><category scheme="http://www.blogger.com/atom/ns#" term="ggplot2"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="stat_boxplot"/><title type='text'>How to modify whiskers of a boxplot in ggplot2?</title><content type='html'>&lt;head&gt;


&lt;title&gt;Title&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;



&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
  
  
We want to modify the colour of the whiskers in a boxplot using ggplot2. In our example, the default colour (black) to red.&lt;p&gt;&lt;p&gt;


&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(ggplot2)
p &lt;- ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(am)))
p + geom_boxplot()
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzbHLZi1gra3SLvdGS7dlx33yAiWUOmQRs1MVKUXVtV9A4bxV2Ig8JlrTGvL31oSrqDKPh9no91mW0Yab4uAnu1JRoKq1hQL3Orwfiu_GZD4rg9U33K8JtPSekoG9-AkBXCrIvvA/s1600/CropperCapture%255B58%255D.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzbHLZi1gra3SLvdGS7dlx33yAiWUOmQRs1MVKUXVtV9A4bxV2Ig8JlrTGvL31oSrqDKPh9no91mW0Yab4uAnu1JRoKq1hQL3Orwfiu_GZD4rg9U33K8JtPSekoG9-AkBXCrIvvA/s1600/CropperCapture%255B58%255D.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;

&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt; 
&lt;li&gt;Option 1&lt;/li&gt;&lt;p&gt;

We plot error bars in red and then superimpose the boxplots in black.&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(ggplot)
p + stat_boxplot(
  geom = &quot;errorbar&quot;,
  colour = &quot;red&quot;,
  width = 0,
  position = position_dodge(0.75)
) +
  geom_boxplot(coef = 0, outlier.shape = NA)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjguadqGZBtXEkOfMd-h7_vEUlurzhG7zvLqvA3WK1LyHSaPs6NPUeiROCMjvesjKXFZ8IEJWGzUyIP5ZjGo_natrdMbYEJzyZCpAMfyJv0k2BJod6l2v9nBfMuRAGqyk3jdzuN-w/s0/Screenshot_1.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;479&quot; data-original-width=&quot;520&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjguadqGZBtXEkOfMd-h7_vEUlurzhG7zvLqvA3WK1LyHSaPs6NPUeiROCMjvesjKXFZ8IEJWGzUyIP5ZjGo_natrdMbYEJzyZCpAMfyJv0k2BJod6l2v9nBfMuRAGqyk3jdzuN-w/s0/Screenshot_1.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;


&lt;li&gt;Option 2&lt;/li&gt;&lt;p&gt;
We superimpose two boxplots on top of each other. The first one with red borders and the secong one without whiskers in black.&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;p + geom_boxplot(color=&quot;red&quot;) + 
  geom_boxplot(aes(ymin=..lower.., ymax=..upper..)) 
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;


   
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSfNMTR7nZCNAYTNJKnHIbBgsAYYjGYeIlstZAiKy2gLCp4IMDR0nEGlDLYM-A9Hjh5ZR9XpY_Z1L3LusCocwynQcmYSv64IuMQ3IBZiAgzSukQz2nRlsJwa4gzFLkZxd4TAyz7g/s1600/CropperCapture%255B60%255D.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSfNMTR7nZCNAYTNJKnHIbBgsAYYjGYeIlstZAiKy2gLCp4IMDR0nEGlDLYM-A9Hjh5ZR9XpY_Z1L3LusCocwynQcmYSv64IuMQ3IBZiAgzSukQz2nRlsJwa4gzFLkZxd4TAyz7g/s1600/CropperCapture%255B60%255D.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;



&lt;/ul&gt;



&lt;h3&gt;References&lt;/h3&gt;&lt;p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;http://docs.ggplot2.org/current/geom_boxplot.html&quot; target=&quot;_blank&quot;&gt;Box and whiskers plot.&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/22068770/how-to-modify-whiskers-of-a-boxplot-in-ggplot2/32831598#32831598&quot; target=&quot;_blank&quot;&gt;stackoverflow&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;!--- See rscript C

--&gt;</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/7130897540666812229/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-modify-whiskers-of-boxplot-in.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/7130897540666812229'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/7130897540666812229'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-modify-whiskers-of-boxplot-in.html' title='How to modify whiskers of a boxplot in ggplot2?'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzbHLZi1gra3SLvdGS7dlx33yAiWUOmQRs1MVKUXVtV9A4bxV2Ig8JlrTGvL31oSrqDKPh9no91mW0Yab4uAnu1JRoKq1hQL3Orwfiu_GZD4rg9U33K8JtPSekoG9-AkBXCrIvvA/s72-c/CropperCapture%255B58%255D.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-3593034402453309798</id><published>2020-12-10T06:28:00.001+01:00</published><updated>2020-12-10T06:28:03.562+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aspect.ratio"/><category scheme="http://www.blogger.com/atom/ns#" term="coord_flip"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_bar"/><category scheme="http://www.blogger.com/atom/ns#" term="ggplot2"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="theme"/><title type='text'>Cómo reducir el espacio entre barras de un diagramas de barra con ggplot2</title><content type='html'>&lt;head&gt;


&lt;title&gt;Title&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;



&lt;h3&gt;Problema&lt;/h3&gt;&lt;p&gt;
 
Queremos reducir el espacio entre las barras de un diagrama de barras con ggplot2.&lt;p&gt;

  Diagrama de barras vertical&lt;p&gt;
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4hbDqB3f0AYCyxJcgZe1-MP5vP76ABwhivHz8qpIh0FEorzzZTcClBEW8xlWbIlazWdFeJs99PM3eRa8DWBUhwgHeq_I7N4JgD4HODDQDb893TG5wEV68n0HLAY0vns8jVaagtA/s0/Screenshot_3.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;394&quot; data-original-width=&quot;493&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4hbDqB3f0AYCyxJcgZe1-MP5vP76ABwhivHz8qpIh0FEorzzZTcClBEW8xlWbIlazWdFeJs99PM3eRa8DWBUhwgHeq_I7N4JgD4HODDQDb893TG5wEV68n0HLAY0vns8jVaagtA/s0/Screenshot_3.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

Diagrama de barras horizontal&lt;p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnNbtdHvr8bviid1VccoPcdIDgaitThnI2ZKvmJtNGh9kIcJd8CZQiz9qm_f7FEUiU4L037YwC3HxKvEuidvSWqSONTvAKmtffRnZNTho0KBH7di5VzM9ioQRXAcnFhTka3FJ-3A/s0/Screenshot_1.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;401&quot; data-original-width=&quot;499&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnNbtdHvr8bviid1VccoPcdIDgaitThnI2ZKvmJtNGh9kIcJd8CZQiz9qm_f7FEUiU4L037YwC3HxKvEuidvSWqSONTvAKmtffRnZNTho0KBH7di5VzM9ioQRXAcnFhTka3FJ-3A/s0/Screenshot_1.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(ggthemes)
library(ggplot2)
df &lt;- data.frame(x = c(&quot;firm&quot;, &quot;vendor&quot;), y = c(50, 20))

# Vertical
ggplot(df, aes(x = x, y = y)) + 
  geom_bar(stat = &quot;identity&quot;, width = 0.4) + 
  theme_tufte() + 
  labs(x = &quot;&quot;, y = &quot;&quot;)

# Horizontal
ggplot(df, aes(x = x, y = y)) + 
  geom_bar(stat = &quot;identity&quot;, width = 0.4) + 
  theme_tufte() +  coord_flip() +
  labs(x = &quot;&quot;, y = &quot;&quot;)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;p&gt;


&lt;h3&gt;Solución&lt;/h3&gt;&lt;p&gt;

Tan sólo necesitamos añadir &lt;i&gt;theme(aspect.ratio = xx)&lt;/i&gt;, y luego necesitamos ajustar el ese ratio para conseguir las distancia deseada. Con &lt;i&gt;coord_flip() podemos voltear el gráfico&lt;/i&gt;

&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;
# Vertical
ggplot(df, aes(x = x, y = y)) + 
  geom_bar(stat = &quot;identity&quot;) + 
  theme_tufte() + theme(aspect.ratio = 2) +
  labs(x = &quot;&quot;, y = &quot;&quot;)

# Horizontal
ggplot(df, aes(x = x, y = y)) + 
  geom_bar(stat = &quot;identity&quot;) + 
  theme_tufte() + theme(aspect.ratio = .2) +
  coord_flip() +
  labs(x = &quot;&quot;, y = &quot;&quot;)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;h3&gt;Resultados&lt;/h3&gt;&lt;p&gt;

  Diagrama de barras vertical&lt;p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWZHM_ErX9_Cx_s7cIo4C0tM-eE82R5EEgW10RdhLkwgVnj0vuslWDBQvJLVJZJIfkF1-QZCOzWI3Goos8dTkISOFTL75NAwSshxoZWNkTMVugOUatv2Ay4b31DnzaR7OjpvveFw/s0/Screenshot_4.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;385&quot; data-original-width=&quot;223&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWZHM_ErX9_Cx_s7cIo4C0tM-eE82R5EEgW10RdhLkwgVnj0vuslWDBQvJLVJZJIfkF1-QZCOzWI3Goos8dTkISOFTL75NAwSshxoZWNkTMVugOUatv2Ay4b31DnzaR7OjpvveFw/s0/Screenshot_4.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

  Diagrama de barras horizontal&lt;p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9nNz_qI_psG1ofsJMdxHwmuaxNhrkpPmedNgQG0kJhbekLFeSv4GMc_hwy5MazMOG5fbcmUH3bCqRzfoHvqdvJHEmB0D7f5zIbXH35LCjMOKw8N4FZipVVBoLAxGCeP_azhv-_g/s0/Screenshot_2.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;184&quot; data-original-width=&quot;491&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9nNz_qI_psG1ofsJMdxHwmuaxNhrkpPmedNgQG0kJhbekLFeSv4GMc_hwy5MazMOG5fbcmUH3bCqRzfoHvqdvJHEmB0D7f5zIbXH35LCjMOKw8N4FZipVVBoLAxGCeP_azhv-_g/s0/Screenshot_2.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;



&lt;!----
&lt;h3&gt;Entradas relacionadas&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://nubededatos.blogspot.com/2020/12/how-to-remove-whiskers-in-boxplot-with.html&quot; target=&quot;_blank&quot;&gt;How to remove whiskers in a boxplot with the R Base Package&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;


---&gt;
</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/3593034402453309798/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2020/12/como-reducir-el-espacio-entre-barras-de.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3593034402453309798'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/3593034402453309798'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2020/12/como-reducir-el-espacio-entre-barras-de.html' title='Cómo reducir el espacio entre barras de un diagramas de barra con ggplot2'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4hbDqB3f0AYCyxJcgZe1-MP5vP76ABwhivHz8qpIh0FEorzzZTcClBEW8xlWbIlazWdFeJs99PM3eRa8DWBUhwgHeq_I7N4JgD4HODDQDb893TG5wEV68n0HLAY0vns8jVaagtA/s72-c/Screenshot_3.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-21694095.post-57254623647253328</id><published>2020-12-09T06:09:00.001+01:00</published><updated>2020-12-09T06:09:00.188+01:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="aspect.ratio"/><category scheme="http://www.blogger.com/atom/ns#" term="coord_flip"/><category scheme="http://www.blogger.com/atom/ns#" term="English"/><category scheme="http://www.blogger.com/atom/ns#" term="geom_bar"/><category scheme="http://www.blogger.com/atom/ns#" term="ggplot2"/><category scheme="http://www.blogger.com/atom/ns#" term="R"/><category scheme="http://www.blogger.com/atom/ns#" term="Rstats"/><category scheme="http://www.blogger.com/atom/ns#" term="theme"/><title type='text'>How to reduce space between bars in ggplot2</title><content type='html'>&lt;head&gt;


&lt;title&gt;Title&lt;/title&gt;

&lt;style type=&quot;text/css&quot;&gt;
body, td {
   font-family: sans-serif;
   background-color: white;
   font-size: 12px;
   margin: 8px;
}

tt, code, pre {
   font-family: &#39;DejaVu Sans Mono&#39;, &#39;Droid Sans Mono&#39;, &#39;Lucida Console&#39;, Consolas, Monaco, monospace;
}

h1 { 
   font-size:2.2em; 
}

h2 { 
   font-size:1.8em; 
}

h3 { 
   font-size:1.4em; 
}

h4 { 
   font-size:1.0em; 
}

h5 { 
   font-size:0.9em; 
}

h6 { 
   font-size:0.8em; 
}

a:visited {
   color: #2288bb;
}


pre { 
   margin-top: 0;
   max-width: 95%;
   border: 1px solid #ccc;
   white-space: pre-wrap;
}

pre code {
   display: block; padding: 0.5em;
}

code.r, code.cpp {
   background-color: #F8F8F8;
}

table, td, th {
  border: none;
}

blockquote {
   color:#666666;
   margin:0;
   padding-left: 1em;
   border-left: 0.5em #EEE solid;
}

hr {
   height: 0px;
   border-bottom: none;
   border-top-width: thin;
   border-top-style: dotted;
   border-top-color: #999999;
}

@media print {
   * { 
      background: transparent !important; 
      color: black !important; 
      filter:none !important; 
      -ms-filter: none !important; 
   }

   body { 
      font-size:12pt; 
      max-width:100%; 
   }
       
   a, a:visited { 
      text-decoration: underline; 
   }

   hr { 
      visibility: hidden;
      page-break-before: always;
   }

   pre, blockquote { 
      padding-right: 1em; 
      page-break-inside: avoid; 
   }

   tr, img { 
      page-break-inside: avoid; 
   }

   img { 
      max-width: 100% !important; 
   }

   @page :left { 
      margin: 15mm 20mm 15mm 10mm; 
   }
     
   @page :right { 
      margin: 15mm 10mm 15mm 20mm; 
   }

   p, h2, h3 { 
      orphans: 3; widows: 3; 
   }

   h2, h3 { 
      page-break-after: avoid; 
   }
}

&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- Styles for R syntax highlighter --&gt;
&lt;style type=&quot;text/css&quot;&gt;
   pre .operator,
   pre .paren {
     color: rgb(104, 118, 135)
   }

   pre .literal {
     color: rgb(88, 72, 246)
   }

   pre .number {
     color: rgb(0, 0, 205);
   }

   pre .comment {
     color: rgb(76, 136, 107);
   }

   pre .keyword {
     color: rgb(0, 0, 255);
   }

   pre .identifier {
     color: rgb(0, 0, 0);
   }

   pre .string {
     color: rgb(3, 106, 7);
   }
&lt;/style&gt;

&lt;!-- R syntax highlighter --&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var hljs=new function(){function m(p){return p.replace(/&amp;/gm,&quot;&amp;amp;&quot;).replace(/&lt;/gm,&quot;&amp;lt;&quot;)}function f(r,q,p){return RegExp(q,&quot;m&quot;+(r.cI?&quot;i&quot;:&quot;&quot;)+(p?&quot;g&quot;:&quot;&quot;))}function b(r){for(var p=0;p&lt;r.childNodes.length;p++){var q=r.childNodes[p];if(q.nodeName==&quot;CODE&quot;){return q}if(!(q.nodeType==3&amp;&amp;q.nodeValue.match(/\s+/))){break}}}function h(t,s){var p=&quot;&quot;;for(var r=0;r&lt;t.childNodes.length;r++){if(t.childNodes[r].nodeType==3){var q=t.childNodes[r].nodeValue;if(s){q=q.replace(/\n/g,&quot;&quot;)}p+=q}else{if(t.childNodes[r].nodeName==&quot;BR&quot;){p+=&quot;\n&quot;}else{p+=h(t.childNodes[r])}}}if(/MSIE [678]/.test(navigator.userAgent)){p=p.replace(/\r/g,&quot;\n&quot;)}return p}function a(s){var r=s.className.split(/\s+/);r=r.concat(s.parentNode.className.split(/\s+/));for(var q=0;q&lt;r.length;q++){var p=r[q].replace(/^language-/,&quot;&quot;);if(e[p]){return p}}}function c(q){var p=[];(function(s,t){for(var r=0;r&lt;s.childNodes.length;r++){if(s.childNodes[r].nodeType==3){t+=s.childNodes[r].nodeValue.length}else{if(s.childNodes[r].nodeName==&quot;BR&quot;){t+=1}else{if(s.childNodes[r].nodeType==1){p.push({event:&quot;start&quot;,offset:t,node:s.childNodes[r]});t=arguments.callee(s.childNodes[r],t);p.push({event:&quot;stop&quot;,offset:t,node:s.childNodes[r]})}}}}return t})(q,0);return p}function k(y,w,x){var q=0;var z=&quot;&quot;;var s=[];function u(){if(y.length&amp;&amp;w.length){if(y[0].offset!=w[0].offset){return(y[0].offset&lt;w[0].offset)?y:w}else{return w[0].event==&quot;start&quot;?y:w}}else{return y.length?y:w}}function t(D){var A=&quot;&lt;&quot;+D.nodeName.toLowerCase();for(var B=0;B&lt;D.attributes.length;B++){var C=D.attributes[B];A+=&quot; &quot;+C.nodeName.toLowerCase();if(C.value!==undefined&amp;&amp;C.value!==false&amp;&amp;C.value!==null){A+=&#39;=&quot;&#39;+m(C.value)+&#39;&quot;&#39;}}return A+&quot;&gt;&quot;}while(y.length||w.length){var v=u().splice(0,1)[0];z+=m(x.substr(q,v.offset-q));q=v.offset;if(v.event==&quot;start&quot;){z+=t(v.node);s.push(v.node)}else{if(v.event==&quot;stop&quot;){var p,r=s.length;do{r--;p=s[r];z+=(&quot;&lt;/&quot;+p.nodeName.toLowerCase()+&quot;&gt;&quot;)}while(p!=v.node);s.splice(r,1);while(r&lt;s.length){z+=t(s[r]);r++}}}}return z+m(x.substr(q))}function j(){function q(x,y,v){if(x.compiled){return}var u;var s=[];if(x.k){x.lR=f(y,x.l||hljs.IR,true);for(var w in x.k){if(!x.k.hasOwnProperty(w)){continue}if(x.k[w] instanceof Object){u=x.k[w]}else{u=x.k;w=&quot;keyword&quot;}for(var r in u){if(!u.hasOwnProperty(r)){continue}x.k[r]=[w,u[r]];s.push(r)}}}if(!v){if(x.bWK){x.b=&quot;\\b(&quot;+s.join(&quot;|&quot;)+&quot;)\\s&quot;}x.bR=f(y,x.b?x.b:&quot;\\B|\\b&quot;);if(!x.e&amp;&amp;!x.eW){x.e=&quot;\\B|\\b&quot;}if(x.e){x.eR=f(y,x.e)}}if(x.i){x.iR=f(y,x.i)}if(x.r===undefined){x.r=1}if(!x.c){x.c=[]}x.compiled=true;for(var t=0;t&lt;x.c.length;t++){if(x.c[t]==&quot;self&quot;){x.c[t]=x}q(x.c[t],y,false)}if(x.starts){q(x.starts,y,false)}}for(var p in e){if(!e.hasOwnProperty(p)){continue}q(e[p].dM,e[p],true)}}function d(B,C){if(!j.called){j();j.called=true}function q(r,M){for(var L=0;L&lt;M.c.length;L++){if((M.c[L].bR.exec(r)||[null])[0]==r){return M.c[L]}}}function v(L,r){if(D[L].e&amp;&amp;D[L].eR.test(r)){return 1}if(D[L].eW){var M=v(L-1,r);return M?M+1:0}return 0}function w(r,L){return L.i&amp;&amp;L.iR.test(r)}function K(N,O){var M=[];for(var L=0;L&lt;N.c.length;L++){M.push(N.c[L].b)}var r=D.length-1;do{if(D[r].e){M.push(D[r].e)}r--}while(D[r+1].eW);if(N.i){M.push(N.i)}return f(O,M.join(&quot;|&quot;),true)}function p(M,L){var N=D[D.length-1];if(!N.t){N.t=K(N,E)}N.t.lastIndex=L;var r=N.t.exec(M);return r?[M.substr(L,r.index-L),r[0],false]:[M.substr(L),&quot;&quot;,true]}function z(N,r){var L=E.cI?r[0].toLowerCase():r[0];var M=N.k[L];if(M&amp;&amp;M instanceof Array){return M}return false}function F(L,P){L=m(L);if(!P.k){return L}var r=&quot;&quot;;var O=0;P.lR.lastIndex=0;var M=P.lR.exec(L);while(M){r+=L.substr(O,M.index-O);var N=z(P,M);if(N){x+=N[1];r+=&#39;&lt;span class=&quot;&#39;+N[0]+&#39;&quot;&gt;&#39;+M[0]+&quot;&lt;/span&gt;&quot;}else{r+=M[0]}O=P.lR.lastIndex;M=P.lR.exec(L)}return r+L.substr(O,L.length-O)}function J(L,M){if(M.sL&amp;&amp;e[M.sL]){var r=d(M.sL,L);x+=r.keyword_count;return r.value}else{return F(L,M)}}function I(M,r){var L=M.cN?&#39;&lt;span class=&quot;&#39;+M.cN+&#39;&quot;&gt;&#39;:&quot;&quot;;if(M.rB){y+=L;M.buffer=&quot;&quot;}else{if(M.eB){y+=m(r)+L;M.buffer=&quot;&quot;}else{y+=L;M.buffer=r}}D.push(M);A+=M.r}function G(N,M,Q){var R=D[D.length-1];if(Q){y+=J(R.buffer+N,R);return false}var P=q(M,R);if(P){y+=J(R.buffer+N,R);I(P,M);return P.rB}var L=v(D.length-1,M);if(L){var O=R.cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;if(R.rE){y+=J(R.buffer+N,R)+O}else{if(R.eE){y+=J(R.buffer+N,R)+O+m(M)}else{y+=J(R.buffer+N+M,R)+O}}while(L&gt;1){O=D[D.length-2].cN?&quot;&lt;/span&gt;&quot;:&quot;&quot;;y+=O;L--;D.length--}var r=D[D.length-1];D.length--;D[D.length-1].buffer=&quot;&quot;;if(r.starts){I(r.starts,&quot;&quot;)}return R.rE}if(w(M,R)){throw&quot;Illegal&quot;}}var E=e[B];var D=[E.dM];var A=0;var x=0;var y=&quot;&quot;;try{var s,u=0;E.dM.buffer=&quot;&quot;;do{s=p(C,u);var t=G(s[0],s[1],s[2]);u+=s[0].length;if(!t){u+=s[1].length}}while(!s[2]);if(D.length&gt;1){throw&quot;Illegal&quot;}return{r:A,keyword_count:x,value:y}}catch(H){if(H==&quot;Illegal&quot;){return{r:0,keyword_count:0,value:m(C)}}else{throw H}}}function g(t){var p={keyword_count:0,r:0,value:m(t)};var r=p;for(var q in e){if(!e.hasOwnProperty(q)){continue}var s=d(q,t);s.language=q;if(s.keyword_count+s.r&gt;r.keyword_count+r.r){r=s}if(s.keyword_count+s.r&gt;p.keyword_count+p.r){r=p;p=s}}if(r.language){p.second_best=r}return p}function i(r,q,p){if(q){r=r.replace(/^((&lt;[^&gt;]+&gt;|\t)+)/gm,function(t,w,v,u){return w.replace(/\t/g,q)})}if(p){r=r.replace(/\n/g,&quot;&lt;br&gt;&quot;)}return r}function n(t,w,r){var x=h(t,r);var v=a(t);var y,s;if(v){y=d(v,x)}else{return}var q=c(t);if(q.length){s=document.createElement(&quot;pre&quot;);s.innerHTML=y.value;y.value=k(q,c(s),x)}y.value=i(y.value,w,r);var u=t.className;if(!u.match(&quot;(\\s|^)(language-)?&quot;+v+&quot;(\\s|$)&quot;)){u=u?(u+&quot; &quot;+v):v}if(/MSIE [678]/.test(navigator.userAgent)&amp;&amp;t.tagName==&quot;CODE&quot;&amp;&amp;t.parentNode.tagName==&quot;PRE&quot;){s=t.parentNode;var p=document.createElement(&quot;div&quot;);p.innerHTML=&quot;&lt;pre&gt;&lt;code&gt;&quot;+y.value+&quot;&lt;/code&gt;&lt;/pre&gt;&quot;;t=p.firstChild.firstChild;p.firstChild.cN=s.cN;s.parentNode.replaceChild(p.firstChild,s)}else{t.innerHTML=y.value}t.className=u;t.result={language:v,kw:y.keyword_count,re:y.r};if(y.second_best){t.second_best={language:y.second_best.language,kw:y.second_best.keyword_count,re:y.second_best.r}}}function o(){if(o.called){return}o.called=true;var r=document.getElementsByTagName(&quot;pre&quot;);for(var p=0;p&lt;r.length;p++){var q=b(r[p]);if(q){n(q,hljs.tabReplace)}}}function l(){if(window.addEventListener){window.addEventListener(&quot;DOMContentLoaded&quot;,o,false);window.addEventListener(&quot;load&quot;,o,false)}else{if(window.attachEvent){window.attachEvent(&quot;onload&quot;,o)}else{window.onload=o}}}var e={};this.LANGUAGES=e;this.highlight=d;this.highlightAuto=g;this.fixMarkup=i;this.highlightBlock=n;this.initHighlighting=o;this.initHighlightingOnLoad=l;this.IR=&quot;[a-zA-Z][a-zA-Z0-9_]*&quot;;this.UIR=&quot;[a-zA-Z_][a-zA-Z0-9_]*&quot;;this.NR=&quot;\\b\\d+(\\.\\d+)?&quot;;this.CNR=&quot;\\b(0[xX][a-fA-F0-9]+|(\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)&quot;;this.BNR=&quot;\\b(0b[01]+)&quot;;this.RSR=&quot;!|!=|!==|%|%=|&amp;|&amp;&amp;|&amp;=|\\*|\\*=|\\+|\\+=|,|\\.|-|-=|/|/=|:|;|&lt;|&lt;&lt;|&lt;&lt;=|&lt;=|=|==|===|&gt;|&gt;=|&gt;&gt;|&gt;&gt;=|&gt;&gt;&gt;|&gt;&gt;&gt;=|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~&quot;;this.ER=&quot;(?![\\s\\S])&quot;;this.BE={b:&quot;\\\\.&quot;,r:0};this.ASM={cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.QSM={cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,i:&quot;\\n&quot;,c:[this.BE],r:0};this.CLCM={cN:&quot;comment&quot;,b:&quot;//&quot;,e:&quot;$&quot;};this.CBLCLM={cN:&quot;comment&quot;,b:&quot;/\\*&quot;,e:&quot;\\*/&quot;};this.HCM={cN:&quot;comment&quot;,b:&quot;#&quot;,e:&quot;$&quot;};this.NM={cN:&quot;number&quot;,b:this.NR,r:0};this.CNM={cN:&quot;number&quot;,b:this.CNR,r:0};this.BNM={cN:&quot;number&quot;,b:this.BNR,r:0};this.inherit=function(r,s){var p={};for(var q in r){p[q]=r[q]}if(s){for(var q in s){p[q]=s[q]}}return p}}();hljs.LANGUAGES.cpp=function(){var a={keyword:{&quot;false&quot;:1,&quot;int&quot;:1,&quot;float&quot;:1,&quot;while&quot;:1,&quot;private&quot;:1,&quot;char&quot;:1,&quot;catch&quot;:1,&quot;export&quot;:1,virtual:1,operator:2,sizeof:2,dynamic_cast:2,typedef:2,const_cast:2,&quot;const&quot;:1,struct:1,&quot;for&quot;:1,static_cast:2,union:1,namespace:1,unsigned:1,&quot;long&quot;:1,&quot;throw&quot;:1,&quot;volatile&quot;:2,&quot;static&quot;:1,&quot;protected&quot;:1,bool:1,template:1,mutable:1,&quot;if&quot;:1,&quot;public&quot;:1,friend:2,&quot;do&quot;:1,&quot;return&quot;:1,&quot;goto&quot;:1,auto:1,&quot;void&quot;:2,&quot;enum&quot;:1,&quot;else&quot;:1,&quot;break&quot;:1,&quot;new&quot;:1,extern:1,using:1,&quot;true&quot;:1,&quot;class&quot;:1,asm:1,&quot;case&quot;:1,typeid:1,&quot;short&quot;:1,reinterpret_cast:2,&quot;default&quot;:1,&quot;double&quot;:1,register:1,explicit:1,signed:1,typename:1,&quot;try&quot;:1,&quot;this&quot;:1,&quot;switch&quot;:1,&quot;continue&quot;:1,wchar_t:1,inline:1,&quot;delete&quot;:1,alignof:1,char16_t:1,char32_t:1,constexpr:1,decltype:1,noexcept:1,nullptr:1,static_assert:1,thread_local:1,restrict:1,_Bool:1,complex:1},built_in:{std:1,string:1,cin:1,cout:1,cerr:1,clog:1,stringstream:1,istringstream:1,ostringstream:1,auto_ptr:1,deque:1,list:1,queue:1,stack:1,vector:1,map:1,set:1,bitset:1,multiset:1,multimap:1,unordered_set:1,unordered_map:1,unordered_multiset:1,unordered_multimap:1,array:1,shared_ptr:1}};return{dM:{k:a,i:&quot;&lt;/&quot;,c:[hljs.CLCM,hljs.CBLCLM,hljs.QSM,{cN:&quot;string&quot;,b:&quot;&#39;\\\\?.&quot;,e:&quot;&#39;&quot;,i:&quot;.&quot;},{cN:&quot;number&quot;,b:&quot;\\b(\\d+(\\.\\d*)?|\\.\\d+)(u|U|l|L|ul|UL|f|F)&quot;},hljs.CNM,{cN:&quot;preprocessor&quot;,b:&quot;#&quot;,e:&quot;$&quot;},{cN:&quot;stl_container&quot;,b:&quot;\\b(deque|list|queue|stack|vector|map|set|bitset|multiset|multimap|unordered_map|unordered_set|unordered_multiset|unordered_multimap|array)\\s*&lt;&quot;,e:&quot;&gt;&quot;,k:a,r:10,c:[&quot;self&quot;]}]}}}();hljs.LANGUAGES.r={dM:{c:[hljs.HCM,{cN:&quot;number&quot;,b:&quot;\\b0[xX][0-9a-fA-F]+[Li]?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:[eE][+\\-]?\\d*)?L\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\b\\d+\\.(?!\\d)(?:i\\b)?&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;number&quot;,b:&quot;\\b\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;number&quot;,b:&quot;\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;keyword&quot;,b:&quot;(?:tryCatch|library|setGeneric|setGroupGeneric)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\.&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\.\\.\\d+(?![\\w.])&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;keyword&quot;,b:&quot;\\b(?:function)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;keyword&quot;,b:&quot;(?:if|in|break|next|repeat|else|for|return|switch|while|try|stop|warning|require|attach|detach|source|setMethod|setClass)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;literal&quot;,b:&quot;(?:NA|NA_integer_|NA_real_|NA_character_|NA_complex_)\\b&quot;,e:hljs.IMMEDIATE_RE,r:10},{cN:&quot;literal&quot;,b:&quot;(?:NULL|TRUE|FALSE|T|F|Inf|NaN)\\b&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;identifier&quot;,b:&quot;[a-zA-Z.][a-zA-Z0-9._]*\\b&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;&lt;\\-(?!\\s*\\d)&quot;,e:hljs.IMMEDIATE_RE,r:2},{cN:&quot;operator&quot;,b:&quot;\\-&gt;|&lt;\\-&quot;,e:hljs.IMMEDIATE_RE,r:1},{cN:&quot;operator&quot;,b:&quot;%%|~&quot;,e:hljs.IMMEDIATE_RE},{cN:&quot;operator&quot;,b:&quot;&gt;=|&lt;=|==|!=|\\|\\||&amp;&amp;|=|\\+|\\-|\\*|/|\\^|&gt;|&lt;|!|&amp;|\\||\\$|:&quot;,e:hljs.IMMEDIATE_RE,r:0},{cN:&quot;operator&quot;,b:&quot;%&quot;,e:&quot;%&quot;,i:&quot;\\n&quot;,r:1},{cN:&quot;identifier&quot;,b:&quot;`&quot;,e:&quot;`&quot;,r:0},{cN:&quot;string&quot;,b:&#39;&quot;&#39;,e:&#39;&quot;&#39;,c:[hljs.BE],r:0},{cN:&quot;string&quot;,b:&quot;&#39;&quot;,e:&quot;&#39;&quot;,c:[hljs.BE],r:0},{cN:&quot;paren&quot;,b:&quot;[[({\\])}]&quot;,e:hljs.IMMEDIATE_RE,r:0}]}};
hljs.initHighlightingOnLoad();
&lt;/script&gt;


&lt;/head&gt;



&lt;h3&gt;Problem&lt;/h3&gt;&lt;p&gt;
 
We want to reduce the space between bars using geom_bar with ggplot2.&lt;p&gt;

  Vertical bar plot &lt;p&gt;
  &lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4hbDqB3f0AYCyxJcgZe1-MP5vP76ABwhivHz8qpIh0FEorzzZTcClBEW8xlWbIlazWdFeJs99PM3eRa8DWBUhwgHeq_I7N4JgD4HODDQDb893TG5wEV68n0HLAY0vns8jVaagtA/s0/Screenshot_3.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;394&quot; data-original-width=&quot;493&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4hbDqB3f0AYCyxJcgZe1-MP5vP76ABwhivHz8qpIh0FEorzzZTcClBEW8xlWbIlazWdFeJs99PM3eRa8DWBUhwgHeq_I7N4JgD4HODDQDb893TG5wEV68n0HLAY0vns8jVaagtA/s0/Screenshot_3.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

Horizontal bar plot&lt;p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnNbtdHvr8bviid1VccoPcdIDgaitThnI2ZKvmJtNGh9kIcJd8CZQiz9qm_f7FEUiU4L037YwC3HxKvEuidvSWqSONTvAKmtffRnZNTho0KBH7di5VzM9ioQRXAcnFhTka3FJ-3A/s0/Screenshot_1.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;401&quot; data-original-width=&quot;499&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnNbtdHvr8bviid1VccoPcdIDgaitThnI2ZKvmJtNGh9kIcJd8CZQiz9qm_f7FEUiU4L037YwC3HxKvEuidvSWqSONTvAKmtffRnZNTho0KBH7di5VzM9ioQRXAcnFhTka3FJ-3A/s0/Screenshot_1.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;
  

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;library(ggthemes)
library(ggplot2)
df &lt;- data.frame(x = c(&quot;firm&quot;, &quot;vendor&quot;), y = c(50, 20))

# Vertical
ggplot(df, aes(x = x, y = y)) + 
  geom_bar(stat = &quot;identity&quot;, width = 0.4) + 
  theme_tufte() + 
  labs(x = &quot;&quot;, y = &quot;&quot;)

# Horizontal
ggplot(df, aes(x = x, y = y)) + 
  geom_bar(stat = &quot;identity&quot;, width = 0.4) + 
  theme_tufte() +  coord_flip() +
  labs(x = &quot;&quot;, y = &quot;&quot;)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;p&gt;


&lt;h3&gt;Solution&lt;/h3&gt;&lt;p&gt;
We just need to to introduce &lt;i&gt;theme(aspect.ratio = xx)&lt;/i&gt;, then we need to play with the ratio to find the desired width. To flip cartesian coordinates we use &lt;i&gt;coord_flip()&lt;/i&gt;

&lt;p&gt;

&lt;pre&gt;&lt;code class=&quot;r&quot;&gt;
# Vertical
ggplot(df, aes(x = x, y = y)) + 
  geom_bar(stat = &quot;identity&quot;) + 
  theme_tufte() + theme(aspect.ratio = 2) +
  labs(x = &quot;&quot;, y = &quot;&quot;)

# Horizontal
ggplot(df, aes(x = x, y = y)) + 
  geom_bar(stat = &quot;identity&quot;) + 
  theme_tufte() + theme(aspect.ratio = .2) +
  coord_flip() +
  labs(x = &quot;&quot;, y = &quot;&quot;)
&lt;/pre&gt;&lt;/code class=&quot;r&quot;&gt;

&lt;h3&gt;Results&lt;/h3&gt;&lt;p&gt;

Vertical bar plot &lt;p&gt;

&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWZHM_ErX9_Cx_s7cIo4C0tM-eE82R5EEgW10RdhLkwgVnj0vuslWDBQvJLVJZJIfkF1-QZCOzWI3Goos8dTkISOFTL75NAwSshxoZWNkTMVugOUatv2Ay4b31DnzaR7OjpvveFw/s0/Screenshot_4.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;385&quot; data-original-width=&quot;223&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjWZHM_ErX9_Cx_s7cIo4C0tM-eE82R5EEgW10RdhLkwgVnj0vuslWDBQvJLVJZJIfkF1-QZCOzWI3Goos8dTkISOFTL75NAwSshxoZWNkTMVugOUatv2Ay4b31DnzaR7OjpvveFw/s0/Screenshot_4.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

Horizontal bar plot&lt;p&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both;&quot;&gt;&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9nNz_qI_psG1ofsJMdxHwmuaxNhrkpPmedNgQG0kJhbekLFeSv4GMc_hwy5MazMOG5fbcmUH3bCqRzfoHvqdvJHEmB0D7f5zIbXH35LCjMOKw8N4FZipVVBoLAxGCeP_azhv-_g/s0/Screenshot_2.png&quot; style=&quot;display: block; padding: 1em 0; text-align: center; &quot;&gt;&lt;img alt=&quot;&quot; border=&quot;0&quot; data-original-height=&quot;184&quot; data-original-width=&quot;491&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9nNz_qI_psG1ofsJMdxHwmuaxNhrkpPmedNgQG0kJhbekLFeSv4GMc_hwy5MazMOG5fbcmUH3bCqRzfoHvqdvJHEmB0D7f5zIbXH35LCjMOKw8N4FZipVVBoLAxGCeP_azhv-_g/s0/Screenshot_2.png&quot;/&gt;&lt;/a&gt;&lt;/div&gt;

&lt;h3&gt;Related posts&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href=&quot;https://nubededatos.blogspot.com/2020/12/how-to-remove-whiskers-in-boxplot-with.html&quot; target=&quot;_blank&quot;&gt;How to remove whiskers in a boxplot with the R Base Package&lt;/a&gt;&lt;/li&gt;

&lt;/ul&gt;

</content><link rel='replies' type='application/atom+xml' href='https://nubededatos.blogspot.com/feeds/57254623647253328/comments/default' title='Enviar comentarios'/><link rel='replies' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-reduce-space-between-bars-in.html#comment-form' title='0 comentarios'/><link rel='edit' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/57254623647253328'/><link rel='self' type='application/atom+xml' href='https://www.blogger.com/feeds/21694095/posts/default/57254623647253328'/><link rel='alternate' type='text/html' href='https://nubededatos.blogspot.com/2020/12/how-to-reduce-space-between-bars-in.html' title='How to reduce space between bars in ggplot2'/><author><name>Unknown</name><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg4hbDqB3f0AYCyxJcgZe1-MP5vP76ABwhivHz8qpIh0FEorzzZTcClBEW8xlWbIlazWdFeJs99PM3eRa8DWBUhwgHeq_I7N4JgD4HODDQDb893TG5wEV68n0HLAY0vns8jVaagtA/s72-c/Screenshot_3.png" height="72" width="72"/><thr:total>0</thr:total></entry></feed>