---
title: "Data Visualization R"
author: "Prof. Eric A. Suess"
output:
  word_document: default
  html_notebook: default
  pdf_document: default
---

Some of the code from Chapter 3, Section 1.

In this chapter ggplot2 is introduced.  We will discuss ggplot2 more in Stat. 651.

The main idea of making graphs with ggplot2 is the idea of mappings that are applied as asthetics in a plot.

The ggplot2 package is part of the tidyverse.  We will install and load the tidyverse.

```{r message=FALSE}
library(mdsr)
library(tidyverse)
```



```{r}
CIACountries
```

# Aesthetics

```{r}
g <- ggplot(data = CIACountries, aes(y = gdp, x = educ))
g + geom_point(size = 3)

g + geom_point(aes(color = net_users), size = 3)
```


```{r}
g <- ggplot(data = CIACountries, aes(y = gdp, x = educ, label = country, color = net_users))
g + geom_text(size = 3)
```

## Scale

```{r}
g <- ggplot(data = CIACountries, aes(y = gdp, x = educ))
g + geom_point(size = 3)

g + geom_point(aes(color = net_users, size = roadways)) 

g + geom_point(aes(color = net_users, size = roadways)) +
   coord_trans(y = "log10")
```

## Facets

```{r}
g + geom_point(alpha = 0.9, aes(size = roadways)) +
   coord_trans(y = "log10") +
  facet_wrap( ~ net_users, nrow = 1) +
  theme(legend.position = "top")
```
