본문 바로가기
6. 데이터 시각화 - ggplot2/공통

[R ggplot] 범례 추가하고 이름,크기,색,진하기 조절하기

by makhimh 2022. 6. 8.
반응형

데이터는 내장데이터 iris 를 사용하였습니다. 설명은 주석으로 대신합니다. 

library(ggplot2)

ggplot()+
  geom_point(data=iris, aes(x=Sepal.Length,y=Sepal.Width,color=Species))+
  #범례 추가
  theme(legend.position = 'top')+
  #범례 타이틀 색,크기,진하게 설정
  theme(legend.title = element_text(color = "black", size = 20, face = "bold"))+
  #범레 텍스트 색,크기,진하게 설정
  theme(legend.text = element_text(color = "black", size = 12, face = "bold"))+
  #범례 색 설정
  scale_color_manual(values=c('red','blue','green'))
  #범례 이름 강제 설정(선택)
  labs(color="legend")

 

반응형

댓글