본문 바로가기
4. 그래프 꾸미기(저수준 함수)/box() - 그래프 테두리선

R에서 그래프 테두리선 그리기, box 함수

by makhimh 2019. 12. 18.
반응형

R에서 그래프 테두리선 그리기, box 함수



그래프 테두리선에는 3가지 종류가 있습니다. 


- 그래프 축 테두리선   box(col="원하는 색")

- inner margin 테두리선   box("figure", col="원하는 색")

- outer margin 테두리선    box("outer", col="원하는 색")



#1. 그래프 축 테두리선


box("plot", col="원하는 색")

또는

box(col="원하는 색")


디폴트가 "plot"이기 때문에 생략이 가능합니다. 


> plot(1,1)

> box(col="red")



lty 옵션을 이용해서 선 스타일을 설정할 수도 있습니다. 


lty=0 → "blank" (투명선)

lty=1 → "solid" (실선) 

lty=2 → "dashed" (대쉬선)

lty=3 → "dotted" (점선)

lty=4 → "dotdash" (점선 + 대쉬선)

lty=5 → "longdash" ( 긴 대쉬선)

lty=6 → "twodash" (두개의 대쉬선)




> plot(1,1)

> box("plot",col="red",lty=2)


문제가 있습니다. 원래 그래프에도 검정 테두리가 있기 때문에 겹쳐보입니다. bty옵션을 이용하여 기존에 있던 테두리를 없애면 해결됩니다. 


> plot(1,1,bty="n")

> box("plot",col="red",lty=2)  




#2. inner margin 테두리선


box("figure", col="원하는 색")


plot(1,1)

> box("figure", col="gray")  




#3. outer margin 테두리선


box("outer", col="원하는 색")


> plot(1,1)

> box("outer", col="blue")  



inner margin과 차이가 없어 보입니다. 이유는 outer margin의 디폴트값이 0이기 때문입니다. outer margin 값을 2로 바꾸고 inner margin과 비교해봅시다. 


> par(oma=c(2,2,2,2))

> plot(1,1)

> box("figure", col="gray") 

> box("outer", col="blue")  


반응형

댓글