Skip to menu

ggplot 문의드립니다.

네잎클로바 2020.03.24 12:53 Views : 291

두변수를 설정할때 boxplot로  작성하면 잘되었습니다. ggplot으로 하니까 그림이 다릅니다.

그래서 ggpolt에서  두변수간에  숫자변수를 설정하고, 전과 후를 알고자하는데 그림이 이것이 맞는지 잘 모르겠습니다.

boxplot처럼 같이 나오려면 방법이 있을까요? 지금 제가 한 ggplot은 명령어 설정이 맞는지요?


library(boot)

cd4

str(cd4)
data.frame': 20 obs. of  2 variables:
 $ baseline: num  2.12 4.35 3.39 2.51 4.04 5.1 3.77 3.35 4.1 3.35 ...
 $ oneyear : num  2.47 4.61 5.26 3.02 6.36 5.93 3.93 4.09 4.88 3.81 ...

boxplot(cd4$baseline, cd4$oneyear)
a = data.frame(cd4)
before = c(2,4,3,3,4,5,4,3,4,3,4,4,3,2, 3,3,2,3,3,3)
after = c(2,5,5,3,6,6,4,4,5,4,5,3,6,3,4,3,3,4,4,2)
b=cd4$baseline
c=cd4$oneyear

# before(전)
library(ggplot2)
(ggplot(a,aes(b,c,group=before))
  + geom_boxplot()
  + stat_sum(colour="darkgray",alpha=0.5)
  + scale_size(breaks=1:2, range=c(3,6))
)
# after(후)
(ggplot(a,aes(b,c,group=after))
  + geom_boxplot()
  + stat_sum(colour="darkgray",alpha=0.5)
  + scale_size(breaks=1:2, range=c(3,6))
)

답변을 부탁드립니다. 감사합니다.