Plotting polynomials is really easy using {ggplot2}. I am still a novice with {ggplot2}, but the advantage of the package is that it lets you add on code as you go to specify different aspects about the graph, such as the title, whether to display lines or points, or how any linear model should be assessed. Lets use the dataset and code that I used as an example in Day 32. We were able to easily make a graph using the plot() function. However, to modify the graph using the basic {graphics} package requires some knowledge of all of the options in {par}, which are many (“we are legion”), and *importantly* need to be stated in the correct way. {ggplot2} lets you tag on extra portions of a graph just by adding a “+” sign. This can even end up as a burden if you re-use code a lot, as you can end up with tons of useless code that just clutters up the lines. But if you’re careful, it should not be too much of a problem. Once you get used to the new syntax, {ggplot2} is way easier and more flexible, and lets you make some really nice graphs.

##Lets try to plot out the curve for the graph library(ggplot2) ##so lets just look at just the scatterplot qplot(x=spore.date, y=spore$spore.number, geom=c("point"))

##Now lets look at the graph with some smoothed averages qplot(x=spore.date, y=spore$spore.number, geom=c("point","smooth"))

## now lets look at the graph and treat it as a quadratic qplot(x=spore.date, y=spore$spore.number, geom=c("point","smooth"), method="lm", formula = y ~ poly(x, 2))

##And as a X^3 function qplot(x=spore.date, y=spore$spore.number, geom=c("point","smooth"), method="lm", formula = y ~ poly(x, 3))

#And just to be rediculous, lets look at a x^10 function qplot(x=spore.date, y=spore$spore.number, geom=c("point","smooth"), method="lm", formula = y ~ poly(x, 10)) ###......really ugly....