Chapter 4 Methods

We describe our methods in this chapter.

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

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

options(scipen = 999)
ggplot(data = midwest, aes(x = area, y = poptotal)) + geom_point(aes(color = state,  size = popdensity),alpha=0.4) + scale_x_continuous(limits=c(0,0.1))+scale_y_continuous(limits = c(0,500000)) + geom_smooth(se = FALSE)+ labs(title = "Scatterplot",subtitle="Area Vs Population",caption="Source:midwest",y="population") + 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).

library(datasets)
ggplot(data = iris) + geom_point(aes(x = Sepal.Length, y = Sepal.Width, shape = Species, color = Species), alpha = 0.5, size=6) + labs(title="Scatterplot", subtitle="Sepal.Length Vs Sepal.Width", caption="Source : iris") + theme_minimal()

library(gcookbook)
ggplot(heightweight, aes(x = heightIn, y = weightLb, colour = sex)) + geom_point(size = 3, alpha = 0.5) + geom_smooth(method="lm", se = FALSE) + labs(title="scatterplot", subtitle="Manufacturer acros Vehicle Classes", caption="Source : heightweight") + theme_classic()
## `geom_smooth()` using formula 'y ~ x'

library(ggplot2)
ggplot(data=mpg)+ geom_bar(aes(x=manufacturer, fill=class), width=0.5)+
  labs(title="Barplot", subtitle="Manufacturer acros Vehicle Classes")+
  scale_fill_brewer(palette="Spectral")+
  theme_minimal()+
  theme(axis.text.x=element_text(angle=65))