Chapter 4 Methods

We describe our methods in this chapter.

4.1 1번 문제

library(ggplot2)

ggplot(data=mpg,aes(x=hwy,fill=drv))+geom_histogram(alpha=0.5)+labs(title="Histogram",subtitle="Histogram of Highway Mile Per Gallon",color="drv",caption="Source: mpg",x="hwy",y="count")+theme_minimal()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

4.2 2번 문제

ggplot(data=mpg,aes(x=hwy,fill=drv))+geom_histogram(alpha=0.5)+labs(title="Histogram using facet_grid()",subtitle="Histogram of Highway Mile Per Gallon",color="drv",caption="Source: mpg",x="hwy",y="count")+theme_minimal()+facet_grid(rows=vars(drv))
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

4.3 3번 문제

ggplot(data=midwest,aes(x=area,y=poptotal),options(scipen = 999))+geom_point(alpha=0.4,aes(color=state,size=popdensity))+geom_smooth(color="blue",alpha=0.4,se=F)+labs(title="Scatterplot",subtitle="Area Vs Population",x="Area",y="Population",color="state",size="popdensity",caption="Source: midwest")+xlim(c(0,0.1))+ylim(c(0,500000))+theme_classic()
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
## Warning: Removed 15 rows containing non-finite values (stat_smooth).
## Warning: Removed 15 rows containing missing values (geom_point).

4.4 4번 문제

ggplot(data=iris,aes(x=Sepal.Length,y=Sepal.Width,shape=Species,color=Species))+geom_point(size=6,alpha=0.5)+xlim(c(4,8))+scale_x_continuous(breaks=c(5,6,7,8))+ylim(c(2.0,4.5))+labs(title="Scatterplot",subtitle="Sepal.Length Vs Sepal.Width",color="Species",caption="Source: iris")+theme_minimal()
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.

4.5 5번 문제

library(gcookbook)
ggplot(data=heightweight,aes(x=heightIn,y=weightLb,color=sex))+geom_smooth(alpha=0.5,method=lm,se=F)+geom_point(alpha=0.5,size=3)+theme_classic()+xlim(c(50,75))+ylim(c(48,176))+scale_x_continuous(breaks=c(50,55,60,65,70))+scale_y_continuous(breaks=c(50,75,100,125,150,175))+labs(title="Scatterplot",subtitle = "Weight Vs Height", caption="Source:heightweight")
## Scale for 'x' is already present. Adding another scale for 'x', which will
## replace the existing scale.
## Scale for 'y' is already present. Adding another scale for 'y', which will
## replace the existing scale.
## `geom_smooth()` using formula 'y ~ x'

4.6 6번 문제

library(RColorBrewer)
ggplot(data=mpg,aes(x=manufacturer,fill=class))+geom_bar(width=0.5)+theme(panel.background=element_rect(fill = "white"),panel.grid=element_line(colour="grey95",linetype = "solid"),axis.text.x=element_text(angle=65))+scale_fill_brewer(palette="Spectral")+labs(title="Barplot",subtitle = "Manufacturer across Vehicle Classes")