06 novembro, 2019
library(gapminder) # lifeExp: Esperanza de vida al nacer (años) # pop: Población # gdpPercap: PIB per cápita (US$, ajustado a la inflación) head(gapminder)
## # A tibble: 6 x 6 ## country continent year lifeExp pop gdpPercap ## <fct> <fct> <int> <dbl> <int> <dbl> ## 1 Afghanistan Asia 1952 28.8 8425333 779. ## 2 Afghanistan Asia 1957 30.3 9240934 821. ## 3 Afghanistan Asia 1962 32.0 10267083 853. ## 4 Afghanistan Asia 1967 34.0 11537966 836. ## 5 Afghanistan Asia 1972 36.1 13079460 740. ## 6 Afghanistan Asia 1977 38.4 14880372 786.
Paquete plotly
Paquete d3heatmap
Paquete heatmaply
Paquete streamgraph
Paquete leaflet
Paquete rgl
Paquete chorddiag
Paquete circlePacker
Paquete collapsibletree
Paquete networkD3
Paquete dygraph
Paquete highcharts
Paquete visNetwork
Paquete SunburstR
Paquete animation
Paquete gganimate
Paquete animations
Paquete googleVis
install.packages("plotly") library(plotly) plot_ly(data = data.frame(), ..., type = NULL, name, color, colors = NULL, alpha = NULL, stroke, strokes = NULL, alpha_stroke = 1, size, sizes = c(10, 100), span, spans = c(1, 20), symbol, symbols = NULL, linetype, linetypes = NULL, split, frame, width = NULL, height = NULL, source = "A")
library(gapminder) library(plotly) gapminder2007 <- subset(gapminder, year==2007) plot_ly(data = gapminder2007, x = ~ gdpPercap, y = ~ lifeExp)
library(gapminder) library(plotly) gapminder2007 <- subset(gapminder, year==2007) plot_ly(data = gapminder2007, x = ~ gdpPercap, y = ~ lifeExp, color = ~ continent)
library(gapminder) library(plotly) gapminder2007 <- subset(gapminder, year==2007) plot_ly(data = gapminder2007, x = ~ gdpPercap, y = ~ lifeExp, color = ~ continent, colors ="Set1")
library(gapminder) library(plotly) gapminder2007 <- subset(gapminder, year==2007) pal <- c("red", "blue", "green", "yellow", "black") plot_ly(data = gapminder2007, x = ~ gdpPercap, y = ~ lifeExp, color = ~ continent, colors = pal)
library(gapminder) library(plotly) gapminder2007 <- subset(gapminder, year==2007) pal <- c("red", "blue", "green", "yellow", "black") pal <- setNames(pal, c("Africa", "Americas", "Asia", "Europe", "Oceania")) plot_ly(data = gapminder2007, x = ~ gdpPercap, y = ~ lifeExp, color = ~ continent, colors = pal)
library(gapminder) library(plotly) gapminder2007 <- subset(gapminder, year==2007) plot_ly(data = gapminder2007, x = ~ gdpPercap, y = ~ lifeExp, type = "scatter", mode="markers", symbol = ~ continent, symbols = c("circle", "x", "o", "+", "*"), color = I('black'), marker = list(size = 5))
Da click sobre este enlace para ver la solución, sólo si es necesario.
library(gapminder) library(plotly) gapminder2007 <- subset(gapminder, year==2007) p <- ggplot(gapminder2007, aes(lifeExp, fill = continent)) + geom_density(alpha = 0.2) p <- ggplotly(p) p
Realiza un diagrama de densidades con la variable pop para el año 1952 discriminado por continent.
Da click sobre este enlace para ver la solución, sólo si es necesario.
library(gapminder) library(plotly) gapminder2007 <- subset(gapminder, year==2007) plot_ly(data = gapminder2007, x = ~ lifeExp, color = ~ continent, type="box")
Realiza un boxplot con la variable pop para el año 1952 discriminado por continent.
Da click sobre este enlace para ver la solución, sólo si es necesario.
library(ggplot2) library(gganimate) library(gapminder) p <- ggplot(gapminder, aes(x = gdpPercap, y=lifeExp, size = pop, colour = country)) + geom_point(show.legend = FALSE, alpha = 0.7) + scale_color_viridis_d() + scale_size(range = c(2, 12)) + scale_x_log10() + labs(x = "GDP per capita", y = "Life expectancy") p + transition_time(year) + labs(title = "Year: {frame_time}")
Realiza un boxplot comparativo animado con la variables lifeExp y continent.
Da click sobre este enlace para ver la solución, sólo si es necesario.
Cook, D., Swayne, D. F., & Buja, A. (2007). Interactive and dynamic graphics for data analysis: with R and GGobi. Springer Science & Business Media.
Sosulski, K. (2018). Data Visualization Made Simple: Insights Into Becoming Visual. Routledge.
Young, F. W., Valero-Mora, P. M., & Friendly, M. (2011). Visual statistics: seeing data with dynamic interactive graphics (Vol. 914). John Wiley & Sons.
Wilke, C. O. (2019). Fundamentals of Data Visualization: A Primer on Making Informative and Compelling Figures. O'Reilly Media.
Wilkinson, L. (2012). The grammar of graphics. In Handbook of Computational Statistics (pp. 375-414). Springer, Berlin, Heidelberg.
Muchas gracias!
Olga Cecilia Usuga Manco
olga.usuga@udea.edu.co