[R] ggplot2에서 텍스트 추가를 위한 "ggfittext" 패키지 소개

 정보

  • 업무명     : ggplot2에서 텍스트 추가를 위한 "ggfittext" 패키지 소개

  • 작성자     : 이상호

  • 작성일     : 2020-01-06

  • 설   명      :

  • 수정이력 :

 

 내용

[특징]

  • ggplot2 텍스트 추가를 위해서 ggfittext 패키지가 요구되며 이 프로그램은 이러한 목적을 달성하기 위한 소프트웨어

 

aluminous-749358_1280.jpg

 

[기능]

  • ggfittext 라이브러리 소개

 

[활용 자료]

  • 없음

 

[자료 처리 방안 및 활용 분석 기법]

  • 없음

 

[사용법]

  • 소스 코드 예시 참조

 

[사용 OS]

  • Windows10

 

[사용 언어]

  • R v3.6.2

  • R Studio v1.2.5033

 

 소스 코드

[명세]

  • 전역 설정

    • 최대 10 자리 설정

    • 메모리 해제

# Set Option
options(digits = 10)
memory.limit(size = 9999999999999)

 

  • 라이브러리 읽기

# Library Load
library(ggfittext)
library(tidyverse)

 

  • Data Frame 설정

    • x : x축

    • y : y축

    • value : 범례값

    • text : 범례 제목

# Set Data Frame
dfData = tibble(
    text = c("월", "화", "수", "목", "금", "토")
    , value = sample(1:10, 6)
    , x = rep(1:3, 2)
    , y = rep(2:1, each = 3)
    )

 

etc-image-1

 

  • ggplot2를 이용한 가시화 예시 (1)

# Example Using ggplot2 (1)
dfData %>%
    ggplot(aes(x = x, y = y, fill = value, label = text)) +
    geom_tile() +
    scale_fill_gradient(
        low = "black"
        , high = "yellow") +
    geom_fit_text(
        reflow = TRUE
        , grow = TRUE
        , contrast = TRUE
        )

 

etc-image-2

 

  • ggplot2를 이용한 가시화 예시 (2)

# Example Using ggplot2 (2)
dfData %>%
    ggplot(aes(x = x, y = value, fill = value, label = text)) +
    geom_col(position = "dodge") +
    geom_bar_text(
        reflow = FALSE
        , grow = FALSE
        , contrast = TRUE
        , place = "topright"
        )

 

etc-image-3

 

[전체]

# Set Option
options(digits = 10)
memory.limit(size = 9999999999999)

# Library Load
library(ggfittext)
library(tidyverse)

# Set Data Frame
dfData = tibble(
    text = c("월", "화", "수", "목", "금", "토")
    , value = sample(1:10, 6)
    , x = rep(1:3, 2)
    , y = rep(2:1, each = 3)
    )

dplyr::glimpse(dfData)

# Example Using ggplot2 (1)
dfData %>%
    ggplot(aes(x = x, y = y, fill = value, label = text)) +
    geom_tile() +
    scale_fill_gradient(
        low = "black"
        , high = "yellow") +
    geom_fit_text(
        reflow = TRUE
        , grow = TRUE
        , contrast = TRUE
        )

# Example Using ggplot2 (2)
dfData %>%
    ggplot(aes(x = x, y = value, fill = value, label = text)) +
    geom_col(position = "dodge") +
    geom_bar_text(
        reflow = FALSE
        , grow = FALSE
        , contrast = TRUE
        , place = "topright"
        )

 

 참고 문헌

[논문]

  • 없음

[보고서]

  • 없음

[URL]

  • 없음

 

 문의사항

[기상학/프로그래밍 언어]

  • sangho.lee.1990@gmail.com

[해양학/천문학/빅데이터]

  • saimang0804@gmail.com