SlideShare ist ein Scribd-Unternehmen logo
1 von 61
Downloaden Sie, um offline zu lesen
R에서 그래프 그리는 방법
■ 그래프의 종류
cafe.daum.net/oracleoracle
1. 막대 그래프
2. 원형 그래프
4. 지도 그래프
3. 라인 (Plot) 그래프
5. 소리를 시각화
6. 구글에서 제공하는 그래프
7. 워드 클라우드
8. 사분위수 그래프
막대 그래프
cafe.daum.net/oracleoracle
문제106
cafe.daum.net/oracleoracle
emp 테이블의 월급으로 기본적인 막대 그래프를 그리시오
문제106 답
cafe.daum.net/oracleoracle
emp <- read.csv("emp.sal", header=T)
barplot(emp$sal)
문제107
cafe.daum.net/oracleoracle
문제106번 그래프에 제목을 Salary Bar Chart 라고
이름을 붙이시오
문제107 답
cafe.daum.net/oracleoracle
barplot(emp$sal , main="Salary Bar Chart" )
문제108
cafe.daum.net/oracleoracle
문제107번 막대 그래프 x 축에 사원이름을 출력하시오
문제108 답
cafe.daum.net/oracleoracle
barplot(emp$sal , main="Salary Bar Chart",
names.arg = emp$ename, ylab="Salary",
cex.names=0.7 )
문제109
cafe.daum.net/oracleoracle
문제108번 그래프에 색깔을 입히시오
문제109 답
cafe.daum.net/oracleoracle
barplot(emp$sal , main="Salary Bar Chart",
names.arg = emp$ename, ylab="Salary",
cex.names=0.7 , col =('blue') )
문제110
cafe.daum.net/oracleoracle
문제109번의 색깔을 사원별로 unique 하게 하시오
문제110 답
cafe.daum.net/oracleoracle
barplot(emp$sal , main="Salary Bar Chart",
names.arg = emp$ename, ylab="Salary",
cex.names=0.7 , col = rainbow(14) )
문제111
cafe.daum.net/oracleoracle
치킨집 년도별 창업건수를 막대 그래프로 시각화 하시오
문제111 답
cafe.daum.net/oracleoracle
create_cnt <- read.csv("창업건수.csv", header=T)
drop_cnt <- read.csv("폐업건수.csv", header=T)
barplot(create_cnt$치킨,main="년도별 치킨집 창업건수",
names.arg=create_cnt$X, col=("blue"),
ylim=c(0,1300) )
문제112
cafe.daum.net/oracleoracle
치킨집 년도별 폐업건수를 막대 그래프로 시각화 하시오
문제112 답
cafe.daum.net/oracleoracle
create_cnt <- read.csv("창업건수.csv", header=T)
drop_cnt <- read.csv("폐업건수.csv", header=T)
barplot(drop_cnt$치킨집,main="년도별 치킨집 폐업건수",
names.arg=create_cnt$X, col=("red"),
ylim=c(0,4000) )
문제113
cafe.daum.net/oracleoracle
치킨집 년도별 창업건수, 폐업건수를 막대 그래프로 그리는
데 같이 출력되게 하시오
문제113 답
cafe.daum.net/oracleoracle
barplot( x ,main="년도별 치킨집 창업,폐업건수",
names.arg=create_cnt$X, col=c("blue","red"),
ylim=c(0,4000) , beside=T )
x <- rbind(create_cnt$치킨집, drop_cnt$치킨집)
문제114
cafe.daum.net/oracleoracle
문제113번에 legend 를 달아서 파란색이 창업이고 빨간색
이 폐업이다라고 하시오
문제114 답
cafe.daum.net/oracleoracle
barplot( x ,main="년도별 치킨집 창업,폐업건수",
names.arg=create_cnt$X, col=c("blue","red"),
ylim=c(0,4000) , beside=T ,
legend =c("창업", "폐업") )
x <- rbind(create_cnt$치킨집, drop_cnt$치킨집)
문제115
cafe.daum.net/oracleoracle
카페(커피음료) 가 얼마나 창업을 하고 얼마나 폐업을 하는지
막대 그래프로 시각화 하시오
문제115 답
cafe.daum.net/oracleoracle
barplot( x ,main="년도별 카페 창업,폐업건수",
names.arg=create_cnt$X, col=c("blue","red"),
ylim=c(0,4000) , beside=T ,
legend =c("창업", "폐업") )
x <- rbind(create_cnt$커피음료, drop_cnt$커피음료)
원형(pie) 그래프
cafe.daum.net/oracleoracle
문제116
cafe.daum.net/oracleoracle
사원 테이블의 월급으로 원형 그래프를 그리시오
pie(emp$sal)
문제117
cafe.daum.net/oracleoracle
문제116번을 다시 수행하는데 색깔을 좀더 화려하게 시각화
하시오
문제117 답
cafe.daum.net/oracleoracle
pie(emp$sal , col=rainbow(14) )
문제118
cafe.daum.net/oracleoracle
문제117번을 다시 수행하는데 제목을 Salary Pie
Chart 라고 붙이시오
문제118 답
cafe.daum.net/oracleoracle
pie(emp$sal , col=rainbow(14),
main="Salary Pie Chart")
문제119
cafe.daum.net/oracleoracle
문제118번을 다시 수행하는데 누구의 월급인지 이름이
출력되게 하시오
문제119 답
cafe.daum.net/oracleoracle
pie(emp$sal , col=rainbow(14),
main="Salary Pie Chart", labels=emp$ename)
문제120
cafe.daum.net/oracleoracle
문제119번 그래프에 월급에 비율을 붙여서 출력하시오
문제120 답
cafe.daum.net/oracleoracle
sal_label <- round(emp$sal/sum(emp$sal) * 100,1)
sal_label2 <- paste(emp$ename, sal_label, "%")
pie(emp$sal , col=rainbow(14),
main="Salary Pie Chart", labels = sal_label2)
문제121
cafe.daum.net/oracleoracle
2014년도 업종별 창업 비율을 아래와 같이 원형 그래프로
그리시오
문제121 답
cafe.daum.net/oracleoracle
x2 <- create_cnt[ create_cnt$X =='2014', (2:8) ]
pie(t(x2), col=rainbow(7))
cnt_label <- round(x2/sum(x2) * 100,1)
cnt_label2 <- paste(colnames(cnt_label),t(cnt_label), '%')
pie(t(x2), col=rainbow(7), labels= cnt_label2)
문제122
cafe.daum.net/oracleoracle
2013년도 업종별 창업 비율을 아래와 같이 원형 그래프로
그리는데 제목을 2013년도 창업 현황이라고 출력되게하시오
문제122 답
cafe.daum.net/oracleoracle
x2 <- create_cnt[ create_cnt$X =='2013', (2:8) ]
pie(t(x2), col=rainbow(7))
cnt_label <- round(x2/sum(x2) * 100,1)
cnt_label2 <- paste(colnames(cnt_label),t(cnt_label), '%')
pie(t(x2), col=rainbow(7), labels= cnt_label2,
main="2013년도 창업 현황" )
문제123
cafe.daum.net/oracleoracle
문제122번 코드를 가지고 함수를 생성하는데 아래와 같이
함수를 실행해서 년도 입력하면 해당 년도의 원형 그래프가
그려지게 하시오
년도를 입력하세요 ? 2013
> show_pie()
문제123 답
cafe.daum.net/oracleoracle
show_pie <- function() {
graphics.off()
response <- readline(prompt ='년도를 입력하세요 ~' )
x2 <- create_cnt[ create_cnt$X == response , (2:8) ]
pie(t(x2), col=rainbow(7))
cnt_label <- round(x2/sum(x2) * 100,1)
cnt_label2 <- paste(colnames(cnt_label),t(cnt_label), '%')
pie(t(x2), col=rainbow(7), labels= cnt_label2,
main="2013년도 창업 현황" )
}
문제124
cafe.daum.net/oracleoracle
문제123번을 다시 수행하는데 제목도 년도에 맞겠금 변경되게
하시오
년도를 입력하세요 ? 2013
> show_pie()
문제124 답
cafe.daum.net/oracleoracle
show_pie <- function() {
graphics.off()
response <- readline(prompt ='년도를 입력하세요 ~' )
x2 <- create_cnt[ create_cnt$X == response , (2:8) ]
pie(t(x2), col=rainbow(7))
cnt_label <- round(x2/sum(x2) * 100,1)
cnt_label2 <- paste(colnames(cnt_label),t(cnt_label), '%')
pie(t(x2), col=rainbow(7), labels= cnt_label2,
main=paste(response, "년도 창업 현황" ) )
}
문제125
cafe.daum.net/oracleoracle
아래와 같이 업종을 물어보게하고 업종을 입력하면 해당 업종의
창업,폐업 현황이 막대그래프로 그려지는 함수를 생성하시오
업종을 입력하세요 ? 치킨
> show_bar()
문제125 답
cafe.daum.net/oracleoracle
show_bar <- function() {
graphics.off()
response <- readline(prompt ='업종을 입력하세요 ~' )
x <- rbind(create_cnt[,response] , drop_cnt[,response] )
barplot( x ,main="년도별 치킨집 창업,폐업건수",
names.arg=create_cnt$X, col=c("blue","red"),
ylim=c(0,4000) , beside=T ,
legend =c("창업", "폐업") )
}
문제126
cafe.daum.net/oracleoracle
문제125번을 다시 수행하는데 제목이 그 업종과 관련된 제목
으로 출력되게 하시오
업종을 입력하세요 ? 치킨
> show_bar()
문제126 답
cafe.daum.net/oracleoracle
show_bar <- function() {
graphics.off()
response <- readline(prompt ='업종을 입력하세요 ~ ' )
x <- rbind(create_cnt[,response] , drop_cnt[,response] )
barplot( x ,
main= paste("년도별", response," 창업,폐업건수"),
names.arg=create_cnt$X, col=c("blue","red"),
ylim=c(0,4000) , beside=T ,
legend =c("창업", "폐업") )
}
문제127
cafe.daum.net/oracleoracle
아래의 스크립트를 수행하고 입력했을때의 값이 response
라는 변수에 입력되게 하시오
menu(c("Yes", "No"), title="Do you want this?")
문제127 답
cafe.daum.net/oracleoracle
response <- menu(c("Yes", "No"), title="Do you want this?")
문제128
cafe.daum.net/oracleoracle
R의 menu 함수를 이용해서 아래와 같이 업종을 번호로 선택
해서 막대그래프가 출력되게하시오
> show_bar()
1. x
2. 미용실
3. 양식집
4. 일식집
5. 치킨집
6. 커피음료
7. 한식음식점
8. 호프간이주점
Do you want this ? 2
문제128 답
cafe.daum.net/oracleoracle
show_bar <- function() {
graphics.off()
response <- menu(c("x","미용실","양식집","일식집","치킨집"
,"커피음료","한식음식점","호프간이주점"),
title="Do you want this?")
x <- rbind(create_cnt[,response] , drop_cnt[,response] )
barplot( x ,
main= paste("년도별", response," 창업,폐업건수"),
names.arg=create_cnt$X, col=c("blue","red"),
ylim=c(0,4000) , beside=T ,
legend =c("창업", "폐업") )
}
문제129
cafe.daum.net/oracleoracle
문제128번 다시 수행하는데 그래프의 제목도 업종명으로
출력되게 하시오
문제129 힌트
cafe.daum.net/oracleoracle
특정 컬럼명만 가져오는 방법
문제129 답
cafe.daum.net/oracleoracle
show_bar<-function(){
response<-menu(c("X","미용실","양식집","일식집",
"치킨집","커피음료","한식음식점","호프간이주점")
,title="Do you want this?")
graphics.off()
response<-colnames(create_cnt)[response]
x<-rbind(create_cnt[, response], drop_cnt[,response])
barplot(x, main=paste(response,"업종의 년도별 창업, 폐업건수")
,names.arg=create_cnt$X,col=c("blue","red"),
ylim=c(0,4000),beside=T,legend=c("창업","폐업"))
}
문제130
cafe.daum.net/oracleoracle
직업, 입사한 년도(4자리), 직업별 입사한 년도별 토탈월급을
출력하시오
문제130 답
cafe.daum.net/oracleoracle
emp <- read.csv("emp.csv",header=T)
x2 <- tapply(emp$sal,
list(emp$job,format(as.Date(emp$hiredate), '%Y')), sum)
x2[is.na(x2)] <- 0
x2
문제131
cafe.daum.net/oracleoracle
아래의 결과에서 colum name 과 row name 을 각각 출력
하시오
문제131 답
cafe.daum.net/oracleoracle
colnames(x2)
rownames(x2)
문제132
cafe.daum.net/oracleoracle
아래의 데이터의 결과를 막대 그래프로 시각화 하시오
문제132 답
cafe.daum.net/oracleoracle
emp <- read.csv("emp.csv",header=T)
x2 <- tapply(emp$sal,
list(emp$job,format(as.Date(emp$hiredate), '%Y')), sum)
x2[is.na(x2)] <- 0
x11()
barplot( x2, col = rainbow(5), beside =T )
legend('topright',legend=rownames(x2),fill=rainbow(5) )
문제133
cafe.daum.net/oracleoracle
아래와 같이 막대 그래프를 그릴 컬럼을 물어보게하고
컬럼을 각각 입력하면 토탈월급에 대한 막대 그래프가
그려지게 하시오
> show_emp_bar()
가로가 될 컬럼명을 입력하세요 ~ deptno
세로가 될 컬럼명을 입력하세요 ~ job
■ 그래프의 종류
cafe.daum.net/oracleoracle
1. 막대 그래프
2. 원형 그래프
4. 지도 그래프
3. 라인 (Plot) 그래프
5. 소리를 시각화
6. 구글에서 제공하는 그래프
7. 워드 클라우드
8. 사분위수 그래프
여기까지 보았습니다
라인 그래프는
다음 슬라이드에서
보겠습니다
사랑하는 자여 네 영혼이 잘됨같이 네가 범사에 잘되고
강건하기를 내가 간구하노라
- 성경 요한삼서 1장 2절

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

R에서 막대그래프와 원형 그래프 그리는 방법