---
title: "Stat. 651 Welcome"
author: "Prof. Eric A. Suess"
date: "10/12/2020"
output:
  html_notebook: default
  pdf_document: default
  word_document: default
---

# Gapminder

```{r}
library(pacman)
p_load(tidyverse, gapminder)

gapminder
```


```{r}
gapminder %>% 
  ggplot(aes(x = gdpPercap, y = lifeExp )) + 
  geom_point()

```


```{r}
gapminder %>% 
  ggplot(aes(x = log(gdpPercap), y = log(lifeExp))) + 
  geom_point()


```

```{r}
gapminder %>% 
  ggplot(aes(x = log(gdpPercap), y = log(lifeExp), color = continent, size = pop)) + 
  geom_point() +
  geom_text(aes(label=ifelse(country=="United States",as.character(country),'')),hjust=-0.2,vjust=0)
```

# Faceting

```{r}
gapminder

gapminder %>%  
  ggplot(aes(x = log(gdpPercap), y = log(lifeExp), color = continent, size = pop)) + 
  geom_point() +
  facet_wrap(~year) 
```

# Plot.ly

```{r}
library(plotly)

p <- gapminder %>%  
  ggplot(aes(x = log(gdpPercap), y = log(lifeExp), color = continent, size = pop)) + 
  geom_point() +
  facet_wrap(~year)

ggplotly(p)
```

# Plot.ly faceting

```{r}
library(plotly)

p <- gapminder %>%  
  ggplot(aes(x = log(gdpPercap), y = log(lifeExp), color = continent, size = pop)) + 
  geom_point() +
  facet_wrap(~year)

ggplotly(p)
```

# Plot.ly annimation with ggplot.

To learn about [Plot.ly R](https://plot.ly/r/) and [Plot.ly ggplot](https://plot.ly/ggplot2/).

The [plot.ly book](https://plotly-book.cpsievert.me/) is an excellent place to start to learn about use of annimation [plot.ly chapter 5](https://plotly-book.cpsievert.me/key-frame-animations.html).

```{r}
gg <- gapminder %>% ggplot(aes(log(gdpPercap), log(lifeExp), color = continent)) +
  geom_point(aes(size = pop, frame = year, ids = country)) 
ggplotly(gg)
```

