Notice
Recent Posts
Recent Comments
Link
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

자료 매번 검색하기 귀찮아서 만든 블로그

GGPLOT2 - geom_boxplot 사용하기 (상자 그림) 본문

R

GGPLOT2 - geom_boxplot 사용하기 (상자 그림)

쿠키아버님 2022. 1. 6. 23:29
library(ggplot2)

len = 20;

df<-data.frame(value=runif(len), category=c(rep("Category_1", len/4),
                                           rep("Category_2", len/4),
                                           rep("Category_3", len/4),
                                           rep("Category_4", len/4)))

 

 

기본적인 박스 플랏 그리기

ggplot(df, aes(category, value, color=category))+
  geom_boxplot()

 

 

물론 박스 내부 색상, 테두리 색상, 이상치 모양 등

 

여러가지 커스터마이징도 가능하다

 

ggplot(df, aes(category, value, color=category))+
  geom_boxplot(color="blue", #박스 테두리 색상
               fill="red", #박스 내부 색상
               width=0.25, #박스 너비
              outlier.size = 5, #이상치 크기
              outlier.shape = 1 #이상치의 모양 형태
              )

 

요렇게