- RSTUIDO에서 boxplot, density, point를 한번에 그리는 법(ggdist)2023년 05월 29일 07시 35분 45초에 업로드 된 글입니다.작성자: r-code-for-data-analysis
데이터 시각화 중 대표적인 것이 boxplot 이다. 그런데 개별점을 표시하는 point와 같이 쓸 경우 겹쳐 보여서 시인성이 안 좋다. 더구나 데이터 분포를 보는 density 까지 보여주려면 그래프가 지저분해진다.
이걸 해결해 주는 패키지가 "ggdist" 이다.
https://mjskay.github.io/ggdist/
Visualizations of Distributions and Uncertainty
Provides primitives for visualizing distributions using ggplot2 that are particularly tuned for visualizing uncertainty in either a frequentist or Bayesian mode. Both analytical distributions (such as frequentist confidence distributions or Bayesian priors
mjskay.github.io
1. 패키지 설치 및 불러오기
install.packages("ggdist") library(ggdist)
2. 간단한 예제
library(tidyverse) library(tidyquant) mpg %>% filter(cyl %in% c(4,6,8)) %>% ggplot(aes(x=factor(cyl), y=hwy, fill=factor(cyl))) + ggdist::stat_halfeye( adjust = 0.5, justification = -.2, .width = 0, point_colour = NA ) + geom_boxplot( width = .12, outlier.color=NA, alpha=0.5 )+ ggdist::stat_dots( side="left", justification = 1.1, binwidth=.25 ) + scale_fill_tq() + theme_tq()+ labs( title = "Raincloud Plot", subtitle = "Showing the Bi-Modal Distribution of 6 Cylinder Vehicles", x="Engine Size (No.of Cylinder)", y="Highway Fuel Economy (MPG)", fill = "Cylinders" ) + coord_flip()
3. 결과 : 이때는 그래프를 가로로 뉘여서 보여주는게 유리하다. 3개의 그래프가 겹쳐 있으므로.
728x90반응형'데이터 시각화' 카테고리의 다른 글
xyz 3열의 데이터를 2d, 3d로 시각화 해보기(plot_ly) (0) 2023.05.29 Sank Diagram 으로 QC 데이터 시각화 하기(ggalluvial) (0) 2023.05.29 RSTUDIO 에서 COLOR 선택하기(ggsci,tidyquant) (0) 2023.05.29 GPT를 RSTUDIO에서 사용하고 워드클라우드까지 해 보기(chatgpt) (0) 2023.05.28 GPT를 이용한 Shiny app 만들기 (0) 2023.05.28 댓글