티스토리 뷰
1. 데이터 정제하기
2. 데이터 시각화하기
1.데이터 정제하기
1. 데이터 불러오기
2. 데이터 요약
3. 데이터 추출
4. 결측치와 이상치 처리
- 데이터 불러오기
install.packages("ggplot2")
library(ggplot2)
data(iris)
head(iris)
10.3 히스토그램 geom_histogram()
ggplot(iris,aes(x=Petal.Length)) +
geom_histogram()
#종별구분색
ggplot(iris,aes(x=Petal.Length, fill=Species)) +
geom_histogram()
#범례감추기
ggplot(iris,aes(x=Petal.Length, fill=Species)) +
geom_histogram(show.legend = FALSE) #범례감추기
#10.4 밀도도표 geom_density()
ggplot(iris,aes(x=Petal.Length)) +
geom_density()
ggplot(iris,aes(x=Petal.Length, fill=Species)) +
geom_density()
ggplot(iris,aes(x=Petal.Length, fill=Species)) +
geom_density(show.legend = FALSE)
ggplot(iris,aes(x=Sepal.Length, fill=Species)) +
geom_density(alpha=0.5) #중첩부분 투명값처리
10.5 상자도표 geom_boxplot()
ggplot(iris,aes(x=Species, y=Sepal.Length)) + geom_boxplot()
ggplot(iris,aes(x=Petal.Length, fill= Species)) + geom_boxplot()
ggplot(iris,aes(x=Petal.Width, fill= Species)) + geom_boxplot()
ggplot(iris,aes(x=Sepal.Length, fill= Species)) + geom_boxplot()
ggplot(iris,aes(x=Sepal.Width, fill= Species)) + geom_boxplot()
ggplot(iris,aes(x=Petal.Length, y=Petal.Width)) + geom_boxplot()
ggplot(iris,aes(x=Petal.Length, y=Petal.Width, fill=Species)) + geom_boxplot()
ggplot(iris,aes(x=Petal.Length, y=Petal.Width, fill=Species)) + geom_boxplot(show.legend = FALSE)
10.6 산점도geom_point()
ggplot(iris,aes(x=Petal.Length, y=Petal.Width)) + geom_point()
ggplot(iris,aes(x=Petal.Length,y=Petal.Width,color= Species)) +
geom_point()
ggplot(iris,aes(x=Petal.Length,y=Petal.Width,color= Species)) +
geom_point() +
labs(x ="꽃잎 길이", y="꽃잎 너비")
ggplot(iris,aes(x=Petal.Length,y=Petal.Width,color= Species)) +
geom_point(show.legend = FALSE)
10.7 바차트
install.packages("gapminder")
library(gapminder)
data("gapminder")
str(gapminder)
data <- as.data.frame(gapminder)
table(data$country)
table(data$continent)
table(data$year)
ggplot(gapminder,aes(continent)) + geom_bar()
#2007년 기준으로 데이터 추출
gapminder <- as.data.frame(gapminder)
head(gapminder)
gapminder_2007 <- gapminder[gapminder$year==2007,]
head(gapminder_2007)
또는
library(dplyr)
gapminder_2007 <- filter(gapminder, year==2007)
ggplot(gapminder_2007, aes(continent, fill=continent)) + geom_bar(show.legend = F)
dim(kor)
table(kor$year)
kor$year <- as.factor(kor$year)
ggplot(kor, aes(x=year,y=lifeExp))+geom_bar(stat="identity")
ggplot(kor, aes(x=year,y=lifeExp, fill=lifeExp))+geom_bar(stat="identity")
ggplot(kor, aes(x=year,y=gdpPercap, group=1)) + geom_line() + geom_point()
ggplot(kor, aes(x=year,y=gdpPercap, group=1)) +
geom_line(linetype=2, color="blue") +
geom_point(shape=1, size=3)
728x90
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
반응형