Chapter 4 Methods

교수님, 안녕하세요. 데이터 마이닝을 수강하는 192EDG14 박노원 입니다. 과제1을 제출합니다.

*Problem 1

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

  • Problem 2
p + facet_grid(drv ~ .) + labs(title = "Histogram using facet_grid()", subtitle = "Histogram of Highway Mile Per Gallon", caption = "Sorce: mpg") + theme_minimal()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

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

  • Problem 4
library(datasets)

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

  • Problem 5
library(gcookbook)

ggplot(data = heightweight, aes(x = heightIn, y = weightLb, color = sex, group = sex)) + geom_point(alpha = 0.5, size = 3) + geom_smooth(method = lm, se = FALSE) + labs(title = "Scatterplot", subtitle = "Weight Vs Height", caption = "Source: heightweight") + theme_classic()
## `geom_smooth()` using formula 'y ~ x'

  • Problem 6
library(RColorBrewer)

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