내가 가지고있는 데이터 구조의 유형과 수행하려는 분석을 에뮬레이트하는 다음 스크립트가 있습니다.
library(ggplot2)
library(reshape2)
n <- 10
df <- data.frame(t=seq(n)*0.1, a =sort(rnorm(n)), b =sort(rnorm(n)),
a.1=sort(rnorm(n)), b.1=sort(rnorm(n)),
a.2=sort(rnorm(n)), b.2=sort(rnorm(n)))
head(df)
mdf <- melt(df, id=c('t'))
## head(mdf)
levels(mdf$variable) <- rep(c('a','b'),3)
g <- ggplot(mdf,aes(t,value,group=variable,colour=variable))
g +
stat_smooth(method='lm', formula = y ~ ns(x,3)) +
geom_point() +
facet_wrap(~variable) +
opts()
여기에 덧붙여 제가하고 싶은 것은 t
과 인자 c ( 'a', 'b')
에 대한 평활 함수의 1 차 도함수를 플로팅하는 것입니다. 이 문제를 해결하는 방법을 제안 해 주시면 대단히 감사하겠습니다.