h|1i|0g|3h|2c|1h|2a|1r|3t|2e|1r
en 30 minutos o menos
…o másJoshua Kunst, @jbkunst, Meetup UseRchile Junio 2019

Antes de partir

  • slides, código y material en https://github.com/jbkunst y jkunst.com/slides
  • Twitter, gmail, github username jbkunst
  • Muchos de los ejemplos vienen de jkunst.com/blog

Hola! Qué haremos?

  • Por qué la visualización?
  • Qué es HighchartsJS, y que es highcharter?
  • Mostraremos las mejores características

Así me siento
cuando uso highcharter

Pero la realidad:
Donde está la documentación?!?!?

Porque
visualización
de dados?

Ejercicio


Cuál gráfico funciona mejor con: La región del sur mostró un mayor aumento


region Q1 Q2 Q3 Q4
sur 100 150 225 290
norte 150 160 180 300
este 180 200 200 240
oeste 250 250 300 170

Opción #1

Opción #2

Opción #3


En el gráfico va
n|1u|0e|3s|2t|1r|2o|1
mensaje

h|1i|0g|3h|2c|1h|2a|1r|3t|2e|1r

HighchartsJS & Highcharter

  • HighchartsJS es una librería javascript (como plotly)
  • HighchartsJS es una librería madura, lleva tiempo
  • Highcharter es apenas un wrapper de highcharts…
  • …más algunas funcionalidades

1. hchart

hchart

  • hchart es una función genérica (similar a plot)
  • Dependiendo de la clase del objeto graficará algo particular
  • Interactividad con una línea de código

Importante: datos y paquetes

## Observations: 53,940
## Variables: 10
## $ precio      <int> 326, 326, 327, 334, 335, 336, 336, 337, 337, 338, 33…
## $ quilate     <dbl> 0.23, 0.21, 0.23, 0.29, 0.31, 0.24, 0.24, 0.26, 0.22…
## $ corte       <ord> Ideal, Premium, Bueno, Premium, Bueno, Muy bueno, Mu…
## $ color       <ord> E, E, E, I, J, J, I, H, E, H, J, J, F, J, E, E, I, J…
## $ claridad    <ord> SI2, SI1, VS1, VS2, SI2, VVS2, VVS1, SI1, VS2, VS1, …
## $ profundidad <dbl> 61.5, 59.8, 56.9, 62.4, 63.3, 62.8, 62.3, 61.9, 65.1…
## $ tabla       <dbl> 55, 61, 65, 58, 58, 57, 57, 55, 61, 61, 55, 56, 61, …
## $ x           <dbl> 3.95, 3.89, 4.05, 4.20, 4.34, 3.94, 3.95, 4.07, 3.87…
## $ y           <dbl> 3.98, 3.84, 4.07, 4.23, 4.35, 3.96, 3.98, 4.11, 3.78…
## $ z           <dbl> 2.43, 2.31, 2.31, 2.63, 2.75, 2.48, 2.47, 2.53, 2.49…

Variables numéricas

Factores

Series temporales

Y más:

via GIPHY

2. Opciones y Documentación

Opciones y Documentación

## Observations: 48
## Variables: 3
## $ month <fct> Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec…
## $ city  <chr> "tokyo", "tokyo", "tokyo", "tokyo", "tokyo", "tokyo", "tok…
## $ temp  <dbl> 7.0, 6.9, 9.5, 14.5, 18.2, 21.5, 25.2, 26.5, 23.3, 18.3, 1…

3. Flexibilidad
y Estilo

Flexibilidad

HighchartsJS (y entonces highcharter) tienen muchos tipos de plots:

  • Los clásicos: pie, column, point
  • streamgraphs, sankey
  • pucketbubbles, items list
  • funnel, waterfall, pyramid, wordclouds
  • y más…

http://jkunst.com/highcharter/highcharts.html

Estilo

  • A veces es bueno dar contexto o enfatizarlo
  • Como vimos antes, la flexibilidad de highcharts es inmensa
  • highcharter tiene incluído algunos temas (http://jkunst.com/highcharts-themes-collection)
  • highcharter tambien tiene la funcionalidad de obtener fuentes de font.google.com

ggplot2

Financial times

Flatdark

O modificar/crear un tema

O modificar/crear un tema


Ejemplo de http://jkunst.com/blog/posts/2017-03-03-giving-a-thematic-touch-to-your-interactive-chart/

## Observations: 86
## Variables: 3
## $ x   <dbl> 0.00000e+00, 3.15569e+10, 6.31138e+10, 9.46707e+10, 1.26228e…
## $ y   <int> 30, 14, 27, 31, 27, 20, 26, 16, 23, 32, 13, 7, 4, 13, 8, 8, …
## $ key <chr> ">700 Tonnes", ">700 Tonnes", ">700 Tonnes", ">700 Tonnes", …


Exprésate con tu propio estilo!

via GIPHY

4. Shiny

highcharter y shiny

  • highcharter es un htmlwidget, por lo que es shiny-ready
  • Y con la flexibilidad de shiny y highcharter puedes hacer lo que te de la gana

Por que más diseño?

Al principio, todas as aplicaciónes se parecen mucho

Ejemplo de la vida real

Este era un sitio…

Se remodeló y ahora tiene una aplicación shiny

http://www.piaschile.cl/

Y…

5. Tooltips

Tooltips

  • Buen recurso para no saturar de información un gráfico con información
  • Permite dar detalle que el usuario decide ver
  • (Y son bknes porque a mi me gustan)

Otro ejemplo

Ejemplos de http://jkunst.com/blog/posts/2019-02-04-using-tooltips-in-unexpected-ways/

## Observations: 1,704
## Variables: 6
## $ pais              <fct> Afganistán, Afganistán, Afganistán, Afganistán…
## $ continente        <fct> Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia…
## $ anio              <int> 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987…
## $ esperanza_de_vida <dbl> 28.801, 30.332, 31.997, 34.020, 36.088, 38.438…
## $ poblacion         <int> 8425333, 9240934, 10267083, 11537966, 13079460…
## $ pib_per_capita    <dbl> 779.4453, 820.8530, 853.1007, 836.1971, 739.98…

tooltip_table permite hacer: “tooltip”s como “tablas” ;)

## # A tibble: 142 x 2
##    pais       ttdata     
##    <fct>      <list>     
##  1 Afganistán <list [12]>
##  2 Albania    <list [12]>
##  3 Argelia    <list [12]>
##  4 Angola     <list [12]>
##  5 Argentina  <list [12]>
##  6 Australia  <list [12]>
##  7 Austria    <list [12]>
##  8 Baréin     <list [12]>
##  9 Bangladesh <list [12]>
## 10 Bélgica    <list [12]>
## # … with 132 more rows

tooltip_chart permite…

# mi torpedo
tooltip_chart -> pointFormatter
tooltip_table -> pointFormat
## Observations: 5
## Variables: 2
## $ continente <fct> África, Américas, Asia, Europa, Oceanía
## $ poblacion  <dbl> 929539692, 898871184, 3811953827, 586098529, 24549947
## Observations: 5
## Variables: 3
## $ continente <fct> Asia, Europa, África, Américas, Oceanía
## $ ttdata     <list> [[[43.828, 974.5803], [75.635, 29796.05], [64.062, 1…
## $ poblacion  <dbl> 3811953827, 586098529, 929539692, 898871184, 24549947

Bonus

## Downloading 1311 record(s)...
## Downloading 31 record(s)...

Un poco (?!?!) de cleaning/wrangling

## Downloading 1 record(s)...Downloading 1 record(s)...

Finalmente

## Observations: 1,311
## Variables: 9
## $ id         <int> 12312938, 77138632, 9910972, 79685942, 79674872, 8039…
## $ name       <chr> "George G Vega Yon", "Alejandro Zahler", "Joshua", "L…
## $ bio        <chr> "Doing #rstats at USC's Department of Preventive Medi…
## $ fecha_inc  <date> 2013-01-22, 2013-02-06, 2013-02-07, 2013-02-07, 2013…
## $ city       <chr> "Pasadena", "Santiago", "Santiago", "Santiago", "Sant…
## $ photo_link <chr> "https://secure.meetupstatic.com/photos/member/1/4/7/…
## $ nacum      <dbl> 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16…
## $ vino_hoy   <lgl> FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, FALSE, TRUE,…
## $ marker     <list> [FALSE, FALSE, [TRUE, "url(https://static.xx.fbcdn.n…

Entonces

h|1i|0g|3h|2c|1h|2a|1r|3t|2e|1r
en 30 minutos o menos
…o másJoshua Kunst, @jbkunst, Meetup UseRchile Junio 2019