The Assignment

Use any of the practice data sets in the R package, datasets, 1 to create five plots using the package, ggplot2, and publish these plots in RPubs. Included with each plot should be: a. An explanation of the appropriateness of the geometry applied to plot the data and a summary that explains the “message” to be derived from the plot (e.g., “Displays the relationship between…” or “Compares…). b. Plot and axis titles and, as appropriate, a legend.

Also, use at least two ggplot2 themes from the ggthemes package among the five plots.

The Dataset: Trees

summary(trees)
##      Girth           Height       Volume     
##  Min.   : 8.30   Min.   :63   Min.   :10.20  
##  1st Qu.:11.05   1st Qu.:72   1st Qu.:19.40  
##  Median :12.90   Median :76   Median :24.20  
##  Mean   :13.25   Mean   :76   Mean   :30.17  
##  3rd Qu.:15.25   3rd Qu.:80   3rd Qu.:37.30  
##  Max.   :20.60   Max.   :87   Max.   :77.00

Plot 1

library(dplyr)
library(datasets)
library(magrittr)
library(ggplot2)
library(ggthemes)
head(trees)
##   Girth Height Volume
## 1   8.3     70   10.3
## 2   8.6     65   10.3
## 3   8.8     63   10.2
## 4  10.5     72   16.4
## 5  10.7     81   18.8
## 6  10.8     83   19.7
tree <- tbl_df(trees)
tree
## # A tibble: 31 x 3
##    Girth Height Volume
##    <dbl>  <dbl>  <dbl>
##  1   8.3     70   10.3
##  2   8.6     65   10.3
##  3   8.8     63   10.2
##  4  10.5     72   16.4
##  5  10.7     81   18.8
##  6  10.8     83   19.7
##  7  11.0     66   15.6
##  8  11.0     75   18.2
##  9  11.1     80   22.6
## 10  11.2     75   19.9
## # ... with 21 more rows
treevol <- tree %>%
  ggplot(aes(Volume)) +
  geom_bar(color="blue") +
  labs(title="Volume of Trees",
       x="Volume", y="Number of Trees")+
  theme_economist()
treevol

Plot 2

treehtxgirth <- tree %>%
  ggplot(aes(x=Height, y=Girth)) +
  geom_count(color="orange")+
  labs(title="Relationship Between Tree Height & Girth",
       x="Height", y="Girth in Inches")+
  theme_calc()
treehtxgirth

Plot 3

sum.tree<-tree %>%
  group_by(Girth) %>%
  summarise(min.girth=min(Girth),
            max.girth=max(Girth),
            mean.girth=mean(Girth))
sum.tree
## # A tibble: 27 x 4
##    Girth min.girth max.girth mean.girth
##    <dbl>     <dbl>     <dbl>      <dbl>
##  1   8.3       8.3       8.3        8.3
##  2   8.6       8.6       8.6        8.6
##  3   8.8       8.8       8.8        8.8
##  4  10.5      10.5      10.5       10.5
##  5  10.7      10.7      10.7       10.7
##  6  10.8      10.8      10.8       10.8
##  7  11.0      11.0      11.0       11.0
##  8  11.1      11.1      11.1       11.1
##  9  11.2      11.2      11.2       11.2
## 10  11.3      11.3      11.3       11.3
## # ... with 17 more rows
treegirthmatrix <- sum.tree %>%
  ggplot(aes(x=Girth, y=mean.girth)) +
  geom_point() +
  labs(title="Average Girth by Girth", y="Average Girth (Inches)",
       x="Tree Diameter (Inches)") +
  theme_gdocs()
treegirthmatrix 

Plot 4

sum.treep <- sum.tree %>%
  ggplot(aes(x=max.girth, y=min.girth)) +
  geom_point(color="magenta") +
  labs(title="Minimum Girth by Maximum Girth", y="Minimum Girth (Inches)",
       x="Maximum Girth (Inches)") +
  theme_calc()
sum.treep   

Plot 5

ggplot(tree, aes(x=Height, y=Volume))+
  geom_point()+
  labs(title="Volume by Height - Black Cherry Trees", x="Height (Feet)",
       y="Volume(cubic feet)") +
  theme_few()