26/6/2020

Introduccion

Data

I used the gapminder data from the dataset package that have the following structure:

library(dslabs);library(dplyr)
library(ggplot2);library(plotly)
str(gapminder)
'data.frame':   10545 obs. of  9 variables:
 $ country         : Factor w/ 185 levels "Albania","Algeria",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ year            : int  1960 1960 1960 1960 1960 1960 1960 1960 1960 1960 ...
 $ infant_mortality: num  115.4 148.2 208 NA 59.9 ...
 $ life_expectancy : num  62.9 47.5 36 63 65.4 ...
 $ fertility       : num  6.19 7.65 7.32 4.43 3.11 4.55 4.82 3.45 2.7 5.57 ...
 $ population      : num  1636054 11124892 5270844 54681 20619075 ...
 $ gdp             : num  NA 1.38e+10 NA NA 1.08e+11 ...
 $ continent       : Factor w/ 5 levels "Africa","Americas",..: 4 1 1 2 2 3 2 5 4 3 ...
 $ region          : Factor w/ 22 levels "Australia and New Zealand",..: 19 11 10 2 15 21 2 1 22 21 ...

Structure of Tools

This app only contain two version of tools:

  • The slider bar, to modify the bin of a histogram
  • The selected choice, that are necessary to choice a depend variable and an independ variable
  • Also exist a second selection otion for factor that filter the plots.

Structure of Shiny App part 1

At first the app starts with a histogram graph that show us the way that a variable has.

hist(gapminder$infant_mortality)

Structure of Shiny App part 2

In the second plot I show you the same histogram but in logs because the scale of some variables are so different to other and can not see them well.

hist(log(gapminder$gdp))

Structure of Shiny App part 3

For part 3 I designed a ggplot usin plotly package that show us the relationship between imputs but filtered but some factor.

gg <- gapminder %>% ggplot(aes(infant_mortality,life_expectancy, color = region)) +
  geom_point(color = "black") +geom_smooth(method ="loess") + facet_wrap(.~ region)
ggplotly(gg)

Structure of Shiny App part 4

Finally I designed a time seris that show us how in mean the variable selected was changing trough time.

ggg <- gapminder %>% ggplot(aes(year,life_expectancy, color = region)) +
  geom_line(color = "black") +geom_smooth(method ="loess") + facet_wrap(.~ region)
ggplotly(ggg)