## ---------------- ggplot2 Examples ------------------------- library(ggplot2) dataMatrix<-read.csv("Ships.csv") attach(dataMatrix) # Example1: qplot(wt, mpg, data=mtcars, colour=factor(cyl)) # Example 2: model <- lm(mpg ~ wt + factor(cyl), data=mtcars) grid <- with(mtcars, expand.grid( wt = seq(min(wt), max(wt), length = 20), cyl = levels(factor(cyl)) )) grid$mpg <- stats::predict(model, newdata=grid) qplot(wt, mpg, data=mtcars, colour=factor(cyl)) + geom_line(data=grid) # Example 3: err <- stats::predict(model, newdata=grid, se = TRUE) grid$ucl <- err$fit + 1.96 * err$se.fit grid$lcl <- err$fit - 1.96 * err$se.fit qplot(wt, mpg, data=mtcars, colour=factor(cyl)) + geom_smooth(aes(ymin = lcl, ymax = ucl), data=grid, stat="identity")