En estas slides presentaremos ejemplos de algunos de los gráficos más utilizados en el análisis de datos. Puedes ver listados más completos en:
[Extensiones ggplot2]: Impresionante!!
[R-graph gallery - ggplot2 package]: otra vez, impresionante!!
Evidentemente, el tipo de grafico se ha de elegir en función de la información que se quiere mostrar. [Aquí] puedes encontrar ayuda para elegir el tipo de grafico. Por ejemplo:
[From Data to Viz], [The Data Visualisation Catalogue], [The chart chooser], [The Chart Chooser Dissected], [The Chart Chooser: Interactive Version], etc ...
ggplot(iris, aes(Sepal.Length))
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)")
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)") +geom_histogram(bins = 40) + labs(title = "40 intervalos")
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)") +geom_histogram(bins = 40) + labs(title = "40 intervalos") +geom_histogram(binwidth = 0.5) + labs(title = "En lugar de elegir el nº de intervalos, \n se puede elegir la anchura del intervalo: \n binwidth = 0.5")
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)") +geom_histogram(bins = 40) + labs(title = "40 intervalos") +geom_histogram(binwidth = 0.5) + labs(title = "En lugar de elegir el nº de intervalos, \n se puede elegir la anchura del intervalo: \n binwidth = 0.5") +geom_histogram(binwidth = 0.5, color = "black", fill = "tomato") + labs(title = "binwidth = 0.5, color = black, fill = tomato")
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)") +geom_histogram(bins = 40) + labs(title = "40 intervalos") +geom_histogram(binwidth = 0.5) + labs(title = "En lugar de elegir el nº de intervalos, \n se puede elegir la anchura del intervalo: \n binwidth = 0.5") +geom_histogram(binwidth = 0.5, color = "black", fill = "tomato") + labs(title = "binwidth = 0.5, color = black, fill = tomato") +geom_histogram(binwidth = 0.5, aes(fill = Species), color = "black") + labs(title = "binwidth = 0.5, color = black, aes(fill = Species)")
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)") +geom_histogram(bins = 40) + labs(title = "40 intervalos") +geom_histogram(binwidth = 0.5) + labs(title = "En lugar de elegir el nº de intervalos, \n se puede elegir la anchura del intervalo: \n binwidth = 0.5") +geom_histogram(binwidth = 0.5, color = "black", fill = "tomato") + labs(title = "binwidth = 0.5, color = black, fill = tomato") +geom_histogram(binwidth = 0.5, aes(fill = Species), color = "black") + labs(title = "binwidth = 0.5, color = black, aes(fill = Species)") +facet_grid(cols = vars(Species))
ggplot(iris, aes(Sepal.Length, fill = Species)) + geom_density(alpha = 0.5) ggplot(iris, aes(x = Sepal.Length, y = Species)) + ggridges::geom_density_ridges(aes(fill = Species), alpha = 0.5)
ggplot(iris, aes(x = Species, y = Sepal.Length))
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot()
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot() +geom_boxplot(aes(fill = Species), outlier.colour = "purple")
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot() +geom_boxplot(aes(fill = Species), outlier.colour = "purple") +geom_jitter(width = 0.15, alpha = 1/4, color = "tomato")
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot() +geom_boxplot(aes(fill = Species), outlier.colour = "purple") +geom_jitter(width = 0.15, alpha = 1/4, color = "tomato") +stat_summary(fun = "mean", geom = "point", color = "purple", size = 2.5)
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot() +geom_boxplot(aes(fill = Species), outlier.colour = "purple") +geom_jitter(width = 0.15, alpha = 1/4, color = "tomato") +stat_summary(fun = "mean", geom = "point", color = "purple", size = 2.5) +geom_violin(aes(fill = Species), alpha = 0.6)
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot() +geom_boxplot(aes(fill = Species), outlier.colour = "purple") +geom_jitter(width = 0.15, alpha = 1/4, color = "tomato") +stat_summary(fun = "mean", geom = "point", color = "purple", size = 2.5) +geom_violin(aes(fill = Species), alpha = 0.6) +coord_flip()
ggplot(mpg, aes(class))
ggplot(mpg, aes(class)) +geom_bar()
ggplot(mpg, aes(class)) +geom_bar() +geom_bar(fill = "steelblue")
ggplot(mpg, aes(class)) +geom_bar() +geom_bar(fill = "steelblue") +coord_flip()
ggplot(mpg, aes(class)) +geom_bar() +geom_bar(fill = "steelblue") +coord_flip() +geom_bar(aes(forcats::fct_rev(forcats::fct_infreq(class))), fill = "steelblue")
Para esta subsección utilizaremos el data.frame mtcars
p <- ggplot(mtcars, aes(factor(cyl), fill = factor(vs)))p + geom_bar() p + geom_bar(position = "fill")p + geom_bar(position = "dodge")p + geom_bar(position = position_dodge2(preserve = "single"))
Permiten al usuario interactuar con el gráfico, abriéndose posibilidades como: zooming, highlight, o mostrar información adicional al pinchar en algún elemento del gráfico, etc …
Los gráficos interactivos permiten al usuario interactuar con el gráfico.
En general, JavaScript (JS) es el lenguaje utilizado para hacer gráficos interactivos con librerías como D3, Chart, Plotly, Vis Highcharts, …
Recientemente, el paquete de R htmlwidgets ha facilitado el uso de las librerías de JS en R.
Actualmente, paquetes de R, como leaflet, DT, dygraphs, networkD3 y muchos otros, utilizan el framework propuesto por htmlwidgets para hacer disponibles los gráficos interactivos de JS en R. [Aquí] puede ver los pkgs que usar htmlwidgets
[Aquí] puedes ver una galería con ejemplos.
library(plotly)p <- ggplot(iris, aes(Sepal.Length, Petal.Length, color = Species)) + geom_point() + geom_smooth()ggplotly(p)
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
o | Tile View: Overview of Slides |
s | Toggle scribble toolbox |
Alt + f | Fit Slides to Screen |
Esc | Back to slideshow |
En estas slides presentaremos ejemplos de algunos de los gráficos más utilizados en el análisis de datos. Puedes ver listados más completos en:
[Extensiones ggplot2]: Impresionante!!
[R-graph gallery - ggplot2 package]: otra vez, impresionante!!
Evidentemente, el tipo de grafico se ha de elegir en función de la información que se quiere mostrar. [Aquí] puedes encontrar ayuda para elegir el tipo de grafico. Por ejemplo:
[From Data to Viz], [The Data Visualisation Catalogue], [The chart chooser], [The Chart Chooser Dissected], [The Chart Chooser: Interactive Version], etc ...
ggplot(iris, aes(Sepal.Length))
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)")
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)") +geom_histogram(bins = 40) + labs(title = "40 intervalos")
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)") +geom_histogram(bins = 40) + labs(title = "40 intervalos") +geom_histogram(binwidth = 0.5) + labs(title = "En lugar de elegir el nº de intervalos, \n se puede elegir la anchura del intervalo: \n binwidth = 0.5")
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)") +geom_histogram(bins = 40) + labs(title = "40 intervalos") +geom_histogram(binwidth = 0.5) + labs(title = "En lugar de elegir el nº de intervalos, \n se puede elegir la anchura del intervalo: \n binwidth = 0.5") +geom_histogram(binwidth = 0.5, color = "black", fill = "tomato") + labs(title = "binwidth = 0.5, color = black, fill = tomato")
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)") +geom_histogram(bins = 40) + labs(title = "40 intervalos") +geom_histogram(binwidth = 0.5) + labs(title = "En lugar de elegir el nº de intervalos, \n se puede elegir la anchura del intervalo: \n binwidth = 0.5") +geom_histogram(binwidth = 0.5, color = "black", fill = "tomato") + labs(title = "binwidth = 0.5, color = black, fill = tomato") +geom_histogram(binwidth = 0.5, aes(fill = Species), color = "black") + labs(title = "binwidth = 0.5, color = black, aes(fill = Species)")
ggplot(iris, aes(Sepal.Length)) +geom_histogram(bins = 60) + labs(title = "60 intervalos (o bins)") +geom_histogram(bins = 40) + labs(title = "40 intervalos") +geom_histogram(binwidth = 0.5) + labs(title = "En lugar de elegir el nº de intervalos, \n se puede elegir la anchura del intervalo: \n binwidth = 0.5") +geom_histogram(binwidth = 0.5, color = "black", fill = "tomato") + labs(title = "binwidth = 0.5, color = black, fill = tomato") +geom_histogram(binwidth = 0.5, aes(fill = Species), color = "black") + labs(title = "binwidth = 0.5, color = black, aes(fill = Species)") +facet_grid(cols = vars(Species))
ggplot(iris, aes(Sepal.Length, fill = Species)) + geom_density(alpha = 0.5) ggplot(iris, aes(x = Sepal.Length, y = Species)) + ggridges::geom_density_ridges(aes(fill = Species), alpha = 0.5)
ggplot(iris, aes(x = Species, y = Sepal.Length))
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot()
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot() +geom_boxplot(aes(fill = Species), outlier.colour = "purple")
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot() +geom_boxplot(aes(fill = Species), outlier.colour = "purple") +geom_jitter(width = 0.15, alpha = 1/4, color = "tomato")
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot() +geom_boxplot(aes(fill = Species), outlier.colour = "purple") +geom_jitter(width = 0.15, alpha = 1/4, color = "tomato") +stat_summary(fun = "mean", geom = "point", color = "purple", size = 2.5)
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot() +geom_boxplot(aes(fill = Species), outlier.colour = "purple") +geom_jitter(width = 0.15, alpha = 1/4, color = "tomato") +stat_summary(fun = "mean", geom = "point", color = "purple", size = 2.5) +geom_violin(aes(fill = Species), alpha = 0.6)
ggplot(iris, aes(x = Species, y = Sepal.Length)) +geom_boxplot() +geom_boxplot(aes(fill = Species), outlier.colour = "purple") +geom_jitter(width = 0.15, alpha = 1/4, color = "tomato") +stat_summary(fun = "mean", geom = "point", color = "purple", size = 2.5) +geom_violin(aes(fill = Species), alpha = 0.6) +coord_flip()
ggplot(mpg, aes(class))
ggplot(mpg, aes(class)) +geom_bar()
ggplot(mpg, aes(class)) +geom_bar() +geom_bar(fill = "steelblue")
ggplot(mpg, aes(class)) +geom_bar() +geom_bar(fill = "steelblue") +coord_flip()
ggplot(mpg, aes(class)) +geom_bar() +geom_bar(fill = "steelblue") +coord_flip() +geom_bar(aes(forcats::fct_rev(forcats::fct_infreq(class))), fill = "steelblue")
Para esta subsección utilizaremos el data.frame mtcars
p <- ggplot(mtcars, aes(factor(cyl), fill = factor(vs)))p + geom_bar() p + geom_bar(position = "fill")p + geom_bar(position = "dodge")p + geom_bar(position = position_dodge2(preserve = "single"))
Permiten al usuario interactuar con el gráfico, abriéndose posibilidades como: zooming, highlight, o mostrar información adicional al pinchar en algún elemento del gráfico, etc …
Los gráficos interactivos permiten al usuario interactuar con el gráfico.
En general, JavaScript (JS) es el lenguaje utilizado para hacer gráficos interactivos con librerías como D3, Chart, Plotly, Vis Highcharts, …
Recientemente, el paquete de R htmlwidgets ha facilitado el uso de las librerías de JS en R.
Actualmente, paquetes de R, como leaflet, DT, dygraphs, networkD3 y muchos otros, utilizan el framework propuesto por htmlwidgets para hacer disponibles los gráficos interactivos de JS en R. [Aquí] puede ver los pkgs que usar htmlwidgets
[Aquí] puedes ver una galería con ejemplos.
library(plotly)p <- ggplot(iris, aes(Sepal.Length, Petal.Length, color = Species)) + geom_point() + geom_smooth()ggplotly(p)
p1 <- p + facet_grid(cols = vars(Species)) ggplotly(p1)