1. R의 내장 데이터셋인 airquality를 이용하여, 적합한 3가지 이상의
그래프 유형을 ggplot2을 사용해서 그려보자.
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
head(airquality)
## Ozone Solar.R Wind Temp Month Day
## 1 41 190 7.4 67 5 1
## 2 36 118 8.0 72 5 2
## 3 12 149 12.6 74 5 3
## 4 18 313 11.5 62 5 4
## 5 NA NA 14.3 56 5 5
## 6 28 NA 14.9 66 5 6
summary(airquality)
## Ozone Solar.R Wind Temp
## Min. : 1.00 Min. : 7.0 Min. : 1.700 Min. :56.00
## 1st Qu.: 18.00 1st Qu.:115.8 1st Qu.: 7.400 1st Qu.:72.00
## Median : 31.50 Median :205.0 Median : 9.700 Median :79.00
## Mean : 42.13 Mean :185.9 Mean : 9.958 Mean :77.88
## 3rd Qu.: 63.25 3rd Qu.:258.8 3rd Qu.:11.500 3rd Qu.:85.00
## Max. :168.00 Max. :334.0 Max. :20.700 Max. :97.00
## NA's :37 NA's :7
## Month Day
## Min. :5.000 Min. : 1.0
## 1st Qu.:6.000 1st Qu.: 8.0
## Median :7.000 Median :16.0
## Mean :6.993 Mean :15.8
## 3rd Qu.:8.000 3rd Qu.:23.0
## Max. :9.000 Max. :31.0
##
ggplot(airquality, aes(x = Wind, y = Ozone)) +
geom_point(color = "steelblue", alpha = 0.7) +
labs(title = "풍속 vs 오존 농도 산점도",
x = "풍속 (mph)",
y = "오존 (ppb)") +
theme_minimal()
## Warning: Removed 37 rows containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(airquality, aes(x = factor(Month), y = Temp)) +
geom_boxplot(fill = "tomato", alpha = 0.6) +
labs(title = "월별 기온 분포",
x = "월",
y = "기온 (°F)") +
theme_light()

ggplot(airquality, aes(x = Temp)) +
geom_histogram(binwidth = 5, fill = "skyblue", color = "black") +
labs(title = "기온 분포 히스토그램",
x = "기온 (°F)",
y = "빈도") +
theme_classic()

#scatterplot :wind 와 ozone농도
#boxplot:월별 온도 분포
#histogram: temp 분포