혼자서 해보기 1

Q1

library(ggplot2)
mpg <- as.data.frame(ggplot2::mpg)
ggplot(data = mpg, aes(x= cty, y= hwy)) + geom_point()

Q2

midwest <- as.data.frame(ggplot2::midwest)
ggplot(data = midwest, aes(x= poptotal, y = popasian)) + 
  geom_point() + 
  xlim(0, 500000) + 
  ylim(0, 10000)
## Warning: Removed 15 rows containing missing values (`geom_point()`).

혼자서 해보기 2

Q1

library(dplyr)
## 
## 다음의 패키지를 부착합니다: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
df <- mpg %>%
  filter(class == "suv") %>%
  group_by(manufacturer) %>%
  summarise(mean_cty = mean(cty)) %>%
  arrange(desc(mean_cty)) %>%
  head(5)

Q2

ggplot(data = df, aes(x = reorder(manufacturer, -mean_cty), y = mean_cty)) + geom_col()

혼자서 해보기 3

economics <- as.data.frame(ggplot2::economics)
ggplot(data = economics, aes(x = date, y = psavert)) + geom_line()

혼자서 해보기 4

class_mpg <- mpg %>%
filter(class %in% c("compact", "subcompact", "suv"))
ggplot(data = class_mpg, aes(x = class, y = cty)) + geom_boxplot()

한국어 데이터

getwd()
## [1] "C:/Users/user/OneDrive/바탕 화면"
setwd("C:\\Users\\user\\OneDrive\\바탕 화면\\R")
read.table("korean_data.txt", fileEncoding="utf-8", head=T) -> korean
korean$gender <- substr(korean$stimulus, 1,1)
ggplot(data = korean, aes(x = gender, y = response)) + geom_boxplot()

극단치 기준 찾기

boxplot(korean$response)$stats

##      [,1]
## [1,]    1
## [2,]    1
## [3,]    4
## [4,]    7
## [5,]    7

25%의 값은 1이고, median의 값은 4이고, 75%의 값은 7이다.