Friday, April 5, 2013

RG #3: multiple scatter plot with smoothed line (trellis plots)




# data 
set.seed (12345)
y1 <- rnorm(1000, 12,9)
x1 <- 0.35 *y1 + rnorm(1000, 0,3)
x2 <-  c(rep("A",500), rep("B",500))
x3 <-  c(rep(1,100), rep(2,100), rep(3,100), rep(4,100), rep(5, 100), rep(1,100), rep(2,100), rep(3,100), rep(4,100), rep(5, 100))
data2 <- data.frame(x1, y1, x2, x3)


require(ggplot2) 
# scatter plots with out lines 
qplot(y1, x1, data =data2) + facet_grid(x2 ~ x3)+theme_bw()

# with smoothed lines  
qplot(y1, x1, data =data2, geom = c("point", "smooth"), method = "lm") + facet_grid(x2 ~ x3)+ theme_bw()


No comments:

Post a Comment

Note: Only a member of this blog may post a comment.