UnalR R Package

website·Indexed 30 days ago

https://estadisticaun.github.io/UnalR/index.html

An R package for creating dynamic and static data visualizations and HTML widgets. It provides functions for generating various charts including histograms, boxplots, radar charts, pie charts, treemaps, and interactive maps using Leaflet, as well as HTML tables via the DT package. The library includes specialized tools for processing and visualizing Saber Pro test results and university graduate microdata.

Tokens
22.1K
Snippets
69
Records
121
Agent score
72%

What's inside UnalR

  1. Overview of the UnalR package

    UnalR is an R package designed for the management and visualization of institutional statistics and microdata from the Universidad Nacional de Colombia. It includes a library of static and interactive graphical functions (supported by JavaScript/htmlwidgets) for creating HTML tables, time series, bar and pie charts, maps, boxplots, radar charts, treemaps, and drilldown visualizations.
  2. Use the ejGraduados sample dataset

    The ejGraduados dataset provides a sample of microdata for graduates from academic programs at the Universidad Nacional de Colombia (covering the period from 2019-I to 2021-I). This dataset is specifically designed for use with the Tabla.General() and Plot.Treemap() functions.
    # Access the dataset
    ejGraduados
    
    # Preview the first 5 rows and 10 columns
    ejGraduados[1:5, 1:10]
  3. Create interactive HTML tables with Tabla.General

    The Tabla.General function simplifies the creation of visually appealing HTML tables for reports and publications by wrapping the DT package. It returns an object of class datatables and htmlwidget. It provides features such as column filtering, pagination, and custom CSS styling.
  4. Create a boxplot using Plot.Boxplot()

    The Plot.Boxplot() function generates dynamic boxplots. It supports two different rendering libraries via the libreria argument: "highcharter" and "plotly". The function allows for grouping by one or two variables, customization of colors, axis labels, and the inclusion of violin plots or jittered points.
    Plot.Boxplot(
      datos       = iris,
      variable    = Sepal.Length,
      grupo1      = Species,
      violin      = TRUE,
      colores     = c("#FF1D58", "#FDB911", "#00E527"),
      titulo      = "BOXPLOT OF SEPAL LENGTH",
      labelX       = "Species",
      labelY       = "Sepal Length",
      libreria    = "plotly"
    )
  5. Troubleshoot UnalR installation and bugs

    If you encounter errors or installation issues with UnalR, try the following steps:

    1. Install the latest development version via devtools to see if the bug has been fixed.
    2. Check the GitHub issues page at https://github.com/estadisticaun.
    3. Contact the email addresses provided in the package documentation for installation support.
  6. Create interactive drill-down charts with Plot.Drilldown

    The Plot.Drilldown function creates a dynamic visualization (using Highcharter/JavaScript) that allows users to click on elements (like pie slices or bars) to inspect data at a more detailed secondary level without leaving the chart. It returns an htmlwidget object of class highchart.
    Plot.Drilldown(
      datos,
      varPrincipal,
      varSecundaria,
      ano,
      periodo,
      torta = TRUE,
      vertical = TRUE,
      colores,
      colores2,
      titulo = "",
      label = "",
      textInfo = "",
      addPeriodo = TRUE,
      estilo = NULL
    )
  7. Create interactive world maps with Plot.Mundo

    The Plot.Mundo function creates dynamic, mobile-compatible interactive maps using the Leaflet JavaScript library. It allows for zooming, panning, and toggling layers. It can be embedded in websites, R Markdown documents, and Shiny applications. By default, it returns an HTML widget of class 'leaflet' and 'htmlwidget'.
    LATAM <- data.frame(
      Country = c("Chile", "Venezuela", "Colombia", "Argentina", "Brazil"),
      PIB = c(1, 10, 100, 1000, 10000)*1:5
    )
    Plot.Mundo(
      datos    = LATAM,
      paises   = "Country",
      variable = "PIB",
      tipo     = "Pais",
      titulo   = "PIB 2023-Q1",
      naTo0    = FALSE,
      colNA    = "#3DBC25",
      centroideMapa = "Peru",
      zoomMapa = 3,
      cortes   = c(0, 10, 100, 1000, 10000, Inf),
      colores  = c("#DFA86A", "#FFBB00", "#FF5100", "#F20034", "#76009D"),
      opacidad = 0.5,
      colBorde = "#0E9BEE",
      compacto = TRUE,
      textSize = 4,
      limpio   = FALSE
    )
  8. Troubleshoot and handle Plot.Series constraints

    When using Plot.Series, keep the following constraints and behaviors in mind:

    • Dygraphs Requirement: The "dygraphs" library requires exactly two variables in the tiempo argument (YEAR and SEMESTRE) to match its expected structure; otherwise, it will throw an error.
    • Highcharter Exports: When downloading plots via Highcharter, the filename is automatically generated as PlotSeries_{category}.png.
    • Custom ggplot2 Themes: While gg.Tema provides 11 presets, you can use any other ggplot2 compatible theme (e.g., from hrbrthemes or ggtech).
  9. Create interactive Saber Pro result tables with Tabla.SaberPro

    The Tabla.SaberPro function generates an HTML widget (of class datatables and htmlwidget) using the DT package to visualize data frames containing Saber Pro test results. It provides built-in features for filtering, pagination, and sorting via the JavaScript DataTables library.
    # Basic usage example
    Tabla.SaberPro(
      datos      = VariosYears,
      variable   = "SEXO",
      encabezado = "PUNTAJES POR SEXO",
      leyenda    = "Custom table description",
      colorHead  = "#FF5B5B",
      estilo     = list(
        PaletaYear = c("#F9CA00", "#F68118"),
        PaletaCategoria = c("#2458C5", "#F0006D", "#42C501")
      )
    )
  10. Consolidate microdata using the Agregar function

    The Agregar function transforms a microdata base into a consolidated data frame or tibble. This consolidated format is required by most of the graphical functions available in the UnalR package. It allows grouping data by one or more temporal variables and filtering by specific time intervals.
    Agregar(
      datos,
      formula,
      frecuencia,
      intervalo,
      textNA = "Sin Información",
      ask = FALSE
    )
  11. Create interactive geographic maps with Plot.Mapa

    The Plot.Mapa function creates interactive maps compatible with mobile and desktop platforms using the Leaflet JavaScript library. These maps include controls for zooming, panning, and toggling layers. They can be embedded in websites, R Markdown documents, and Shiny applications. The function supports mapping data based on Colombia's Political-Administrative Division (DIVIPOLA) coding from DANE.
    Plot.Mapa(
      datos,
      depto,
      mpio,
      variable,
      agregado = TRUE,
      zoomIslas = FALSE,
      estadistico = c("Conteo", "Promedio", "Mediana", "Varianza", "SD", "CV", "Min", "Max"),
      tipo = c("Deptos", "SiNoMpios", "Mpios", "DeptoMpio"),
      SiNoLegend,
      titulo,
      naTo0 = TRUE,
      colNA = "#EEEEEE",
      centroideMapa,
      zoomMapa = 6,
      baldosas,
      cortes,
      colores,
      showSedes = TRUE,
      colSedes,
      opacidad = 0.7,
      colBorde,
      compacto = TRUE,
      textSize = 10,
      limpio = FALSE,
      estatico = FALSE,
      estilo,
      ...
    )
  12. Perform multiple simultaneous aggregations with Agregar()

    Starting from version 1.0.0, the Agregar() function supports multiple simultaneous aggregations by allowing the specification of more than one variable of interest. The function processes these as individual aggregations and concatenates them by row.