R 기초 분야 자주 묻는 질문 [ 맵 지도 그리기, 그래프 그리기, 히스토그램 등..]

아래 그림과 같이 기초가 튼튼해야 성공 할 수 있다.   




아래에는 네이버 지식인에서 자주 나오는 질문이다. 

1. Maps 질문 


library(maps)
library(mapdata)
library(ggplot2)
library(dplyr)
# Map그리기 

# 캐나다 맵 그리기
map("worldHires","Canada",  col="gray90", fill=TRUE)
title("Canada map in mapdata packages")

# 미국 맵 그리기 (하와이를 그리면 너무 작게 보여, 제외 )
map("worldHires", "usa", xlim=c(-170,-10),ylim=c(20,83),col="gray95",resolution=0,fill=TRUE)
title("usa map in mapdata packages ") 

# 맥시코 맵 그리기 
map("worldHires","mexico",  col="gray90", fill=TRUE)
title("Mexico map in mapdata packages")


2. 막대 및 히스토그램 질문


barplot(iris$Sepal.Width, ylab = "빈도", main = '빈도그래프')

hist(iris$Sepal.Width)



3.막대그래프 질문


사고년도 = c("15년도","16년도","17년도","18년도","19년도") 사고건수 = c(29,24,29,19,14) data <- data.frame(사고년도, 사고건수) barplot(t(data$사고건수),ylab = "사고건수", main = '년도별 사고건수', names = data$사고년도 )



 4.MT CARS 실린더별 산점도 질문



# 실린더별 다른 색상 사용 
mtcars %>% 
  mutate(cyl = as.factor(cyl)) %>% 
  group_by(cyl) %>% 
  ggplot() + 
  geom_point(mapping = aes(wt, mpg, color = cyl))


5.특정 데이터만을 포함하는 행 추출하는 법

# iris Petal.Length 에서 1.4하고, 1.5 가져오기

library(dplyr) iris %>% filter(Petal.Length %in% c(1.4 , 1.5))


6. Trees 데이터 셋 이용 R 코드 작성 하는 방법

① trees 데이터셋의 앞쪽 일부분(1~6행)만 출력하시오.

# 1번 답
head(trees)
##   Girth Height Volume
## 1   8.3     70   10.3
## 2   8.6     65   10.3
## 3   8.8     63   10.2
## 4  10.5     72   16.4
## 5  10.7     81   18.8
## 6  10.8     83   19.7

② 전체 나무들의 둘레치수(Girth)에 대해 사분위수를 나타내시오.

# 2번 답
quantile(trees$Girth)
##    0%   25%   50%   75%  100% 
##  8.30 11.05 12.90 15.25 20.60

③ 전체 나무들의 높이(Height)에 대해 히스토그램을 그리시오.

# 3번답
hist(trees$Height)

trees histogram



④ 전체 나무들의 부피(volume)에 대해 상자그림을 그리시오.

#4 번답
boxplot(trees$Volume)




trees boxplot




댓글 1개:

  1. A detailed Canada map helps travelers plan routes between popular destinations efficiently.
    flat earth map

    답글삭제

[주식 클로드 자동매매 프로젝트] 제2편. 데이터 인프라 구축 — 모델보다 데이터가 먼저다

 머신러닝 모델을 이야기하기 전에, 그 모델이 먹는 데이터가 어디서 어떻게 왔는지부터 정직하게 밝혀야 한다. 이 프로젝트에서 가장 많은 시간이 들어간 부분은 화려한 모델 튜닝이 아니라, "내가 정말 그 데이터를 갖고 있는가"를 확인하...