글

라벨이 시각화인 게시물 표시

[R_bigdata] R을 활용한 시각화 (ggplot)

#day04_05_visual.R #ggplot install.packages('ggplot2') library(ggplot2) library(dplyr) library(tidyverse) #내장 데이터 사용 diamonds #ggplot은 데이터와 미학적 요소로 나뉘어 그려진다. #ggplot() 은 데이터를 정의 #aes(esthetics): 화면에 그려지는 방식 ggplot(diamonds,aes(x=color)) + geom_bar() ggplot(diamonds,aes(x=clarity, y=price)) + geom_bar(stat='identity') #보이도록 하기 위해서 (visible) #그룹화 해서 평균 가격을 만들어서 시각화 diamonds %>% group_by(clarity) %>% summarise(mean_price=mean(price)) %>% ggplot(aes(x=clarity,y=mean_price)) + geom_bar(stat='identity') #group_by는 매개변수에 전달된  컬럼명으로 요약하는 역할을 한다. summarise()는 매개변수에 전달된 계산방법에 따라 group_by()의 컬럼그룹을 요약한다. 여기서는 clarity로 카테고리화하고 카테고리별 price를 mean()을 통해 구해내고 있다. #산점도를 이용, 다이아몬드 크기에 따른 가격을 그려보기 diamonds %>% ggplot(aes(x=carat, y =price, color=clarity))+geom_point()+geom_smooth() #geom_point : 산점도 #ggplot 의 상속 #ggplot에서 정의한 내용은 전체에 상속된다. #추가되는 레이어에서 정의 내용은 상속되지 않는다. diamonds %>% ggplot(aes(x=carat, y =price))+geom_point(aes(color=clarity)...

[R_bigdata] R을 활용한 시각화(도식)

#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...