---
title: "Stat. 651: Welcome"
author: "Prof. Eric A. Suess"
format:
  html:
    self-contained: true
---

# 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 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://plot.ly/r/) is an excellent place to start to learn about use of animation [plot.ly chapter 14](https://plotly-r.com/animating-views).

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

