HAHS.
도구로 돌아가기

ggplot2

high-level-code
open-source windowsmaclinux R

개요 / Overview

ggplot2는 21세기 가장 영향력 있는 시각화 라이브러리입니다. 2005년 해들리 위컴(Hadley Wickham)이 만들었으며 릴런드 윌킨슨(Leland Wilkinson)의 "그래픽 문법(Grammar of Graphics)"에 기반을 두고 있어, 사람들이 시각화를 구성하는 방식에 대한 사고방식을 근본적으로 바꾸어 놓았습니다. 차트 유형을 선택하고 거기에 데이터를 맞추는 대신, ggplot2는 데이터, 미학적 매핑, 기하 객체, 통계적 변환, 스케일, 좌표계, 패싯, 테마라는 조합 가능한 구성 요소로부터 시각화를 만들 수 있게 합니다.

ggplot2 is the most influential visualization library of the 21st century. Created by Hadley Wickham in 2005 and based on Leland Wilkinson's "Grammar of Graphics," it fundamentally changed how people think about constructing visualizations. Rather than choosing a chart type and fitting data into it, ggplot2 lets you build visualizations from composable components: data, aesthetic mappings, geometric objects, statistical transformations, scales, coordinate systems, facets, and themes.

tidyverse 생태계의 일부로서, ggplot2는 데이터 조작을 위한 dplyr, 재구조화를 위한 tidyr, 가독성 있는 데이터 워크플로를 위한 파이프 연산자와 매끄럽게 통합됩니다. 이 덕분에 R에서 원본 데이터부터 다듬어진 차트에 이르는 여정이 매우 매끄럽습니다. 이 라이브러리는 통계학, 생물정보학, 사회과학, 경제학 연구에서 기본 시각화 도구가 되었습니다.

As part of the tidyverse ecosystem, ggplot2 integrates seamlessly with dplyr for data manipulation, tidyr for reshaping, and the pipe operator for readable data workflows. This makes the journey from raw data to polished chart remarkably smooth in R. The library has become the default visualization tool in statistics, bioinformatics, social sciences, and economics research.

ggplot2의 확장 생태계는 방대합니다: ggridges(릿지라인 플롯), ggrepel(스마트 레이블 배치), patchwork(다중 플롯 레이아웃), gganimate(애니메이션), ggforce(추가 기하 객체) 등 수백 가지가 있습니다. ggplot2의 원칙에 기반한 설계와 확장 생태계가 결합되면, 만들 수 없는 통계 차트가 거의 없습니다.

ggplot2's extension ecosystem is vast: ggridges (ridgeline plots), ggrepel (smart label placement), patchwork (multi-plot layouts), gganimate (animations), ggforce (additional geometries), and hundreds more. The combination of ggplot2's principled design and its extension ecosystem means there is almost no statistical chart you cannot create.

강점 / Strengths

  • 그래픽 문법 접근 방식이 깔끔하고 조합 가능하며 읽기 쉬운 코드를 만듭니다
  • Grammar-of-graphics approach produces clean, composable, readable code
  • 통계 그래픽에서는 타의 추종을 불허합니다: 내장된 평활화, 회귀, 밀도 추정
  • Unmatched for statistical graphics: built-in smoothing, regression, density estimation
  • 패싯팅(스몰 멀티플)이 우아하고 수월합니다
  • Faceting (small multiples) is elegant and effortless
  • 방대한 확장 생태계(CRAN에 200개 이상의 패키지)
  • Massive extension ecosystem (200+ packages on CRAN)
  • 어떤 해상도에서도 PDF, SVG, PNG로 출판 품질의 출력을 제공합니다
  • Publication-quality output in PDF, SVG, PNG at any resolution
  • 테마 시스템 덕분에 프로젝트나 출판물 전체에 걸쳐 일관된 스타일링이 가능합니다
  • Themes system allows consistent styling across an entire project or publication
  • tidyverse 데이터 조작 파이프라인과 매끄럽게 통합됩니다
  • Seamless integration with the tidyverse data manipulation pipeline
  • 학술 출판의 사실상 표준입니다 — 심사자와 독자들이 ggplot2 수준의 품질을 기대합니다
  • De facto standard in academic publishing — reviewers and readers expect ggplot2 quality
  • gganimate 확장은 최소한의 추가 코드로 애니메이션을 더해줍니다
  • gganimate extension adds animation with minimal additional code
  • plotly::ggplotly()는 ggplot2 차트를 인터랙티브 웹 시각화로 변환합니다
  • plotly::ggplotly() converts ggplot2 charts to interactive web visualizations

한계 / Limitations

  • R 전용입니다 — JavaScript, Python 등 다른 언어에서 네이티브로 사용할 수 없습니다
  • R-only — cannot be used natively in JavaScript, Python, or other languages
  • 인터랙티브 출력은 내장되어 있지 않고 변환(plotly, ggiraph)이 필요합니다
  • Interactive output requires conversion (plotly, ggiraph) rather than being built in
  • 초보자에게는 문법이 헷갈릴 수 있습니다(aes(), geom_ 레이어, + 연산자 체이닝)
  • Syntax can be confusing for beginners (aes(), geom_ layers, + operator chaining)
  • 대용량 데이터셋(100만 개 이상의 점)은 집계나 래스터화 없이는 느려질 수 있습니다
  • Large datasets (>1M points) can be slow without aggregation or rasterization
  • 기본 테마는 알아보기 쉽지만(그리고 호불호가 갈립니다) — 커스터마이징하려면 테마에 대한 지식이 필요합니다
  • Default theme is recognizable (and divisive) — customization requires theme knowledge
  • 지도/지리 시각화에는 추가 패키지(sf, rnaturalearth)가 필요합니다
  • Map/geographic visualizations require additional packages (sf, rnaturalearth)
  • 웹 배포에는 Shiny나 다른 형식으로의 변환이 필요합니다
  • Web deployment requires Shiny or conversion to another format
  • 3D 시각화 지원이 미미합니다
  • 3D visualization support is minimal

이런 용도에 최적 / Best For

ggplot2는 출판 품질의 정적 그래픽이 필요한, R로 작업하는 통계학자, 연구자, 데이터 과학자에게 결정적인 선택지입니다. 재현성, 통계적 오버레이(신뢰 구간, 회귀선, 밀도 곡선), 스몰 멀티플이 필수적인 학술적 맥락에서 특히 탁월합니다. 워크플로가 R을 사용하고 결과물이 논문, 학위논문, 연구 보고서라면 ggplot2는 의심의 여지 없는 표준입니다.

ggplot2 is the definitive choice for statisticians, researchers, and data scientists working in R who need publication-quality static graphics. It excels in academic contexts where reproducibility, statistical overlays (confidence intervals, regression lines, density curves), and small multiples are essential. If your workflow involves R and your output is a paper, thesis, or research report, ggplot2 is the unquestioned standard.

시작하기 / Getting Started

설치하고 첫 번째 플롯을 만들어봅니다:

Install and create your first plot:

install.packages("ggplot2")
library(ggplot2)

# Basic scatterplot
ggplot(mpg, aes(x = displ, y = hwy, color = class)) +
  geom_point(size = 2, alpha = 0.7) +
  labs(
    title = "Engine Displacement vs Highway MPG",
    x = "Engine Displacement (L)",
    y = "Highway MPG",
    color = "Vehicle Class"
  ) +
  theme_minimal()

통계적 오버레이가 있는 패싯 시각화:

A faceted visualization with statistical overlay:

ggplot(diamonds, aes(x = carat, y = price)) +
  geom_hex(bins = 30) +
  geom_smooth(method = "lm", color = "red") +
  scale_fill_viridis_c() +
  facet_wrap(~cut, nrow = 1) +
  theme_minimal() +
  labs(title = "Diamond Price by Carat and Cut")

파일로 저장하기:

Save to file:

ggsave("my_chart.pdf", width = 10, height = 6, dpi = 300)

지원 차트 유형 / Supported Chart Types

ggplot2는 막대 차트, 누적 막대 차트, 선 그래프, 영역 그래프(누적형, 비율형), 산점도, 버블 차트, 히스토그램, 밀도 플롯, 박스 플롯, 바이올린 플롯, 히트맵(geom_tile 사용), 지터/비스웜 플롯, 러그 플롯, 리본/오차 막대 차트, 등고선 플롯, 2차원 밀도 플롯, 헥스빈 플롯, 릿지라인 플롯(ggridges 사용), QQ 플롯을 기본으로 지원합니다. 확장 패키지를 사용하면 트리맵(treemapify), 샌키/충적도(ggalluvial), 네트워크 다이어그램(ggraph), 코로플레스 맵(sf + geom_sf), 레이더 차트(ggradar), 워드 클라우드(ggwordcloud), 선버스트 차트(ggsunburst 사용), 평행 좌표(GGally), 와플 차트(waffle)도 다룰 수 있습니다.

ggplot2 natively supports bar charts, stacked bar charts, line graphs, area graphs (stacked, proportional), scatterplots, bubble charts, histograms, density plots, box plots, violin plots, heatmaps (via geom_tile), jitter/beeswarm plots, rug plots, ribbon/error bar charts, contour plots, 2D density plots, hex bin plots, ridgeline plots (via ggridges), and QQ plots. With extensions, it also handles treemaps (treemapify), Sankey/alluvial diagrams (ggalluvial), network diagrams (ggraph), choropleth maps (sf + geom_sf), radar charts (ggradar), word clouds (ggwordcloud), sunburst charts (via ggsunburst), parallel coordinates (GGally), and waffle charts (waffle).