# Surface plots!

Daryn will be going over how to make surface plots. Its just kind of a fun way to show off pretty things you can do in R. Here (rsm-plots ) is a document that covers surface plots, and here is her code!

``` #use swiss data```

``` #plot of single variable ?plot par(mfrow=c(1,2)) plot(swiss\$Education, swiss\$Fertility, main= "Graph 1", xlab= "Years of Education", ylab= "Fertility") plot(swiss\$Agriculture, swiss\$Fertility) ```

```#add a line of best fit NOT WORKING #ed.fert<-lm(swiss\$Education~swiss\$Fertility) #plot(swiss\$Education, swiss\$Fertility, main= "Graph 1", xlab= "Years of Education", ylab= "Fertility") #lines(swiss\$Education,ed.fert\$fitted) #model for Fertility as a polynomial function of Agriculture and Education swiss2.lm <- lm(Fertility ~ poly(Agriculture, Education, degree=2), data=swiss) require(rsm) #model for Fertility as a polynomial function of Agriculture and Education swiss2.lm <- lm(Fertility ~ poly(Agriculture, Education, degree=2), data=swiss) #show 3 types of graphs par(mfrow=c(1,3)) image(swiss2.lm, Education ~ Agriculture) contour(swiss2.lm, Education ~ Agriculture) persp(swiss2.lm, Education ~ Agriculture, zlab = "Fertility") #enhanced perspective plot persp(swiss2.lm, Education ~ Agriculture, col = "blue", bounds = list(Agriculture=c(20,70), Education=c(0,30)), zlab = "Predicted Fertility", contours = list(z="top", col="orange"), theta = -145, phi = 35, shade = 1) #playing with color persp(swiss2.lm, Education ~ Agriculture, col = rainbow(50), bounds = list(Agriculture=c(20,70), Education=c(0,30)), zlab = "Predicted Fertility", contours = list(z="top", col="orange"), theta = -145, phi = 35, shade = 1) jet.colors <- colorRampPalette(c("#00007F", "blue", "#007FFF", "cyan", "#7FFF7F", "yellow", "#FF7F00", "red", "#7F0000")) colorzjet <- jet.colors(100) persp(swiss2.lm, Education ~ Agriculture, col = colorzjet, bounds = list(Agriculture=c(20,70), Education=c(0,30)), zlab = "Predicted Fertility", contours = list(z="top", col="orange"), theta = -145, phi = 35, shade = 1) #saving plots - add to a plot then run whole script dev.copy(pdf,'myplot.pdf') dev.off() ```