##혼자서 해보기 8-2 (188p) Q1
library(ggplot2)
ggplot(data = mpg, aes(x = cty, y = hwy)) + geom_point()
Q2
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()`).
##혼자서 해보기 8-3 (193p) 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)
ggplot(data = df, aes(x = reorder(manufacturer, -mean_cty),
y = mean_cty)) + geom_col()
Q2
ggplot(data = mpg, aes(x = class)) + geom_bar()
##혼자서 해보기 8-4 (195p) Q1
ggplot(data = economics, aes(x = date, y = psavert)) + geom_line()
##혼자서 해보기 8-5 (198p) Q1
mpg_class <- mpg %>%
filter(class %in% c("compact", "subcompact", "suv"))
ggplot(data = mpg_class, aes(x = class, y = cty)) + geom_boxplot()
###2. 한국어 데이터 과제 #box plot 그리기(x축을 gender y축을 response로 하는 그림을 그리세요.)
korean_data <- read.table("C:/Users/songe/Downloads/R/korean_data.txt", fileEncoding="utf-8", head=T) ->korean
substr(korean_data$stimulus, 1,1) -> korean_data$gender
korean_data$gender <- substr(korean_data$stimulus, 1,1)
ggplot(data = korean_data, aes(x= gender, y= response)) + geom_boxplot()
#그 후 boxplot에서 나타내는 25% 값, median, 75% 값을 각각 찾아 쓰세요.교과서 176에 명령어 있어요
boxplot(korean_data$response)$stats #답-> 25%: 4, median:7, 75%:7
## [,1]
## [1,] 1
## [2,] 1
## [3,] 4
## [4,] 7
## [5,] 7