#day04_04_visual.R
##데이터 시각화 예제
cars
#기초통계
min(cars$speed)
max(cars$speed)
mean(cars$speed)
median(cars$speed)
summary(cars)
#사분범위 : 자료를 4등분한 위치에 있는 값
quantile(cars$speed)
#시각화로 데이터 보기
#산포도 : 데이터가 어떻게 분포가 되어있는지 확인할 수 있는 시각화 방법
#plot(x,y)
plot(1,1)
#실습하기. plot을 이용하여 cars데이터에서 speed 에 다른 dist(제동거리)를 도표에 그려라
plot(cars$speed,cars$dist)
#x축과 y축의 이름(label)을 부여하기
plot(cars$speed,cars$dist,xlab='스피드',ylab='거리')
#데이터를 표시하는 방법 변경
plot(cars$speed,cars$dist,type='p') #point
plot(cars$speed,cars$dist,type='l') #line
plot(cars$speed,cars$dist,type='b') #both
#bar plot() : 막대 그래프
#표현 값에 비례하여 높이와 길이를 가지는 그래프
#값의 비교를 위해서 쓰인다.
mtcars
mtcars$gear
table(mtcars$gear)
barplot(mtcars$gear)
barplot(table(mtcars$gear))
#실습
#pipe를 이용한 문법으로 작성해보기
library(dplyr)
mtcars$gear %>% table() %>% barplot() #barplot(table(mtcars$gear))
#실습
#예제(hot-dog-contest-winners.csv)
hotdogs <- read.csv('https://raw.githubusercontent.com/luxdolorosa/data_set/master/hot_dog/hot-dog-contest-winners.csv')
hotdogs
str(hotdogs)
#실습
#핫도그 데이터를 이용하여 막대 그래프 생성
#비교값- 먹은갯 Dogs.eaten
barplot(hotdogs$Dogs.eaten)
#산포도를 이용하여 년도별, 먹은 개수 생성
plot(hotdogs$Year,hotdogs$Dogs.eaten)
#실습
#국가별 우승횟수를 barplot을 이용해서 그리기
table(hotdogs$Country,hotdogs$Winner)
barplot(table(hotdogs$Country),col = rainbow(4)) #hotdogs대회의 우승국을 활용하여 테이블을 생성하여 카운트된 결과로 barplot을 생성한다. rainbow()는 차트에 rainbow 색 효과를 준다. 매개변수에는 색이 들어가는 bar의 개수가 들어있다.
#histogram() 빈도 수 시각화
#히스토그램의 경우 차트의 형태가 정수로 온전히 분리되지 않고 범위를 기준으로 나타난다. 예를 들어 c(1,1,2)벡터는 1이 두 번 등장하고 있다. 이에 대한 히스토그램을 호출하면 1.0-1.5 까지 2번 1.5-2.0까지 1번 이런 형태로 나타난다는 것이다.
c(1,1,2)
hist(c(1,1,2))
c(1,1,2) %>% hist()
c(1,2,3,4,10) %>% hist()
cars$speed %>% hist()
#pie : 원 그래프 . 전체에 대한 각 부분의 비율
#data_set에서 banana 데이터를 불러와라
#(banana.csv)
banana <- read.csv('https://raw.githubusercontent.com/luxdolorosa/data_set/master/banana/banana.csv',header = F)
banana
pie(x=banana$V2,labels = banana$V1)#V2는 수, V1은 국가를 뜻하는데, 이 둘이 뒤바뀔 경우 pie생성이 불가하다. 국가 명은 비율에 들어갈 수 없기 때문이다.
#핫도그 데이터 중 우승국가 데이터로 pie 그리기
hotdogs$Country %>% table() %>% pie()
##데이터 시각화 예제
cars
#기초통계
min(cars$speed)
max(cars$speed)
mean(cars$speed)
median(cars$speed)
summary(cars)
#사분범위 : 자료를 4등분한 위치에 있는 값
quantile(cars$speed)
#시각화로 데이터 보기
#산포도 : 데이터가 어떻게 분포가 되어있는지 확인할 수 있는 시각화 방법
#plot(x,y)
plot(1,1)
#실습하기. plot을 이용하여 cars데이터에서 speed 에 다른 dist(제동거리)를 도표에 그려라
plot(cars$speed,cars$dist)
#x축과 y축의 이름(label)을 부여하기
plot(cars$speed,cars$dist,xlab='스피드',ylab='거리')
#데이터를 표시하는 방법 변경
plot(cars$speed,cars$dist,type='p') #point
plot(cars$speed,cars$dist,type='l') #line
plot(cars$speed,cars$dist,type='b') #both
#bar plot() : 막대 그래프
#표현 값에 비례하여 높이와 길이를 가지는 그래프
#값의 비교를 위해서 쓰인다.
mtcars
mtcars$gear
table(mtcars$gear)
barplot(mtcars$gear)
barplot(table(mtcars$gear))
#실습
#pipe를 이용한 문법으로 작성해보기
library(dplyr)
mtcars$gear %>% table() %>% barplot() #barplot(table(mtcars$gear))
#실습
#예제(hot-dog-contest-winners.csv)
hotdogs <- read.csv('https://raw.githubusercontent.com/luxdolorosa/data_set/master/hot_dog/hot-dog-contest-winners.csv')
hotdogs
str(hotdogs)
#실습
#핫도그 데이터를 이용하여 막대 그래프 생성
#비교값- 먹은갯 Dogs.eaten
barplot(hotdogs$Dogs.eaten)
#산포도를 이용하여 년도별, 먹은 개수 생성
plot(hotdogs$Year,hotdogs$Dogs.eaten)
#실습
#국가별 우승횟수를 barplot을 이용해서 그리기
table(hotdogs$Country,hotdogs$Winner)
barplot(table(hotdogs$Country),col = rainbow(4)) #hotdogs대회의 우승국을 활용하여 테이블을 생성하여 카운트된 결과로 barplot을 생성한다. rainbow()는 차트에 rainbow 색 효과를 준다. 매개변수에는 색이 들어가는 bar의 개수가 들어있다.
#histogram() 빈도 수 시각화
#히스토그램의 경우 차트의 형태가 정수로 온전히 분리되지 않고 범위를 기준으로 나타난다. 예를 들어 c(1,1,2)벡터는 1이 두 번 등장하고 있다. 이에 대한 히스토그램을 호출하면 1.0-1.5 까지 2번 1.5-2.0까지 1번 이런 형태로 나타난다는 것이다.
c(1,1,2)
hist(c(1,1,2))
c(1,1,2) %>% hist()
c(1,2,3,4,10) %>% hist()
cars$speed %>% hist()
#pie : 원 그래프 . 전체에 대한 각 부분의 비율
#data_set에서 banana 데이터를 불러와라
#(banana.csv)
banana <- read.csv('https://raw.githubusercontent.com/luxdolorosa/data_set/master/banana/banana.csv',header = F)
banana
pie(x=banana$V2,labels = banana$V1)#V2는 수, V1은 국가를 뜻하는데, 이 둘이 뒤바뀔 경우 pie생성이 불가하다. 국가 명은 비율에 들어갈 수 없기 때문이다.
#핫도그 데이터 중 우승국가 데이터로 pie 그리기
hotdogs$Country %>% table() %>% pie()
댓글
댓글 쓰기