R

GGPLOT2 - 그림 양 옆 공백 없애기

쿠키아버님 2022. 9. 20. 15:25
library(ggplot2)

df<-data.frame(x=seq(0, 4),
               y=runif(5))

 

 

원하는 것은 GGPLOT에서 그림의 왼쪽과 오른쪽의 공백을 없애는 것이다.

ggplot(data=df)+
  geom_line(aes(x=x, y=y))

 

빨강색 영역을 없애고 싶다

 

 

scale_x_continuous를 사용하면 된다.

ggplot(data=df)+
  geom_line(aes(x=x, y=y))+
  scale_x_continuous(expand=c(0, 0))

그림의 양 옆 공백이 사라진 것을 확인할 수 있다.