Skip to content

Latest commit

 

History

History
120 lines (106 loc) · 4.91 KB

220509.md

File metadata and controls

120 lines (106 loc) · 4.91 KB

트리맵

  • 사각 타일의 형태로 구성
  • 각 타일의 크기와 색으로 데이터의 크기를 나타냄
  • 각각의 타일은 계층 구조가 있어 데이터에 존재하는 계층 구조도 표현 가능

GNI2014 데이터셋으로 트리맵 작성

GNI2014

  • 2014년도의 전 세계 국가별 인구, 국민총소득(GNI), 소속 대륙의 정보를 담고 있음
head(GNI2014)
treemap(GNI2014,
        index=c("continent","iso3"), # 계층구조 설정(대륙-국가)
        vSize="population",          # 타일의 크기
        vColor="GNI",                # 타일의 컬러
        type="value",                # 타일 컬러링 방법
        bg.labels=240,               
        title="World's GNI")         # 트리맵 제목
head(GNI2014)
  iso3          country     continent population    GNI
3  BMU          Bermuda North America      67837 106140
4  NOR           Norway        Europe    4676305 103630
5  QAT            Qatar          Asia     833285  92200
6  CHE      Switzerland        Europe    7604467  88120
7  MAC Macao SAR, China          Asia     559846  76270
8  LUX       Luxembourg        Europe     491775  75990

Rplot23

state.x77로 트리맵 작성

st <- data.frame(state.x77)
st <- data.frame(st, stname=rownames(st)) # 주 이름 열 stname 추가

treemap(st,
        index=c("stname"),
        vSize="Area",
        vColor="Income",
        type="value",
        title="USA states area and income")

Rplot24

버블차트

  • 산점도 위에 버블의 크기로 정보를 표시
  • 산점도는 2개의 변수에 의한 위치정보라면 버블차트는 3개의 변수 정보를 하나의 그래프에 표시
st <- data.frame(state.x77)

symbols(st$Illiteracy, st$Murder,    # 원의 x,y 좌표의 열
        circles=st$Population,       # 원의 반지름의 열
        inches=0.3,                  # 원의 크기 조절값
        fg="white",                  # 원의 테두리 색
        bg="lightgray",              # 원의 바탕색
        lwd=1.5,                     # 원의 테두리선 두께
        xlab="rate of Illiteracy",
        ylab="crime(murder) rate",
        main="Illiteracy and Crime")
text(st$Illiteracy, st$Murder,       # 텍스트가 출력될 x,y 좌표
     rownames(st),                   # 출력할 텍스트
     cex=0.6,                        # 폰트 크기
     col="brown")                    # 폰트 컬러

Rplot25

모자이크 플롯

  • 다중변수 범주형 데이터에 대해 각 변수의 그룹별 비율을 면적으로 표시하여 정보를 전달
mosaicplot(~gear+vs, data=mtcars, color=T, main="Gear and Vs")

Rplot

설명

  • ~gear+vs에서 ~ 다음의 변수가 x축, + 다음의 변수가 y축 방향으로 표시

ggplot 명령문 기본 구조

  • ggplot은 포통 하나의 ggplot()과 여러개의 geom_xx()들이 +로 연결되어 하나의 그래프를 구성

기본적인 막대그래프 작성

month <- c(1,2,3,4,5,6)
rain <- c(55,50,45,50,60,70)
df <- data.frame(month, rain)
df

ggplot(df, aes(x=month,y=rain)) + # 그래프를 그릴 데이터 지정
  geom_bar(stat="identity",       # 막대의 높이는 y축에 해당하는 열의 값
           width=0.7,             # 막대의 폭 지정
           fill="steelblue")      # 막대의 색 지정

Rplot01

막대그래프 꾸미기

month <- c(1,2,3,4,5,6)
rain <- c(55,50,45,50,60,70)
df <- data.frame(month, rain)
df

ggplot(df, aes(x=month,y=rain)) + # 그래프를 그릴 데이터 지정
  geom_bar(stat="identity",       # 막대의 높이는 y축에 해당하는 열의 값
           width=0.7,             # 막대의 폭 지정
           fill="steelblue") +    # 막대의 색 지정
  ggtitle("월별 강수량") +        # 그래프의 제목 지정
  theme(plot.title=element_text(size=25, face="bold", colour="steelblue")) +
  labs(x="",y="강수량") +       # 그래프의 x,y축 레이블 지정
  coord_flip()                    # 그래프를 가로 방향으로 출력

Rplot02

설명

  • theme()은 지정된 그래프에 대한 제목의 폰트 크기, 색 등을 지정하는 역할

히스토그램 작성

ggplot(iris, aes(x=Petal.Length)) +
  geom_histogram(binwidth=0.5)

Rplot03