Chapter 4 Methods

We describe our methods in this chapter.

HW1

4.1 Problem 1

library(ggplot2)
ggplot(data=mpg, aes(x=hwy, fill=drv))+geom_histogram(alpha=0.5)+theme_minimal()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

##

4.2 Problem 2

ggplot(data=mpg, aes(x=hwy, fill=drv))+facet_grid(drv~.)+geom_histogram(alpha=0.5)+ theme_minimal()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

##

4.3 Problem 3

ggplot(data=midwest, aes(x=area, y=poptotal))+geom_point(aes(color=state, size=popdensity),alpha=0.4)+geom_smooth(se=FALSE)+scale_x_continuous(limits=c(0,0.1))+scale_y_continuous(limits=c(0, 500000))+theme_classic()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'

##

4.4 Problem 4

library(datasets)
ggplot(data=iris, aes(x=Sepal.Length, y=Sepal.Width))+geom_point(aes(color=Species, shape=Species), size=6,alpha=0.5)+theme_minimal()

##

4.5 Problem 5

library(gcookbook)
ggplot(data=heightweight, aes(x=heightIn, y=weightLb, color=sex))+geom_point(size=3, alpha=0.5)+stat_smooth(se=FALSE, method="lm")+theme_classic()
## `geom_smooth()` using formula 'y ~ x'

##

4.6 problem 6

library(ggplot2)
ggplot(data=mpg, aes(x=manufacturer, fill=class))+geom_bar(width=0.5)+scale_fill_brewer(palette="Spectral")+theme_minimal()+theme(axis.text.x=element_text(angle=65))