This post has used information provided here.
R lets you graph univariate data using the line() function. This is useful at times. However, the trend line can be misleading since the variable is independent. The trend line produced here uses the means of the datapoints and there is no relationship between the axis.
To simply graph the data points, I will use the following method - assuming the data has been imported to 'mydata', and the temperatures are stored with the variable name 'mmax.temp' (NB: R doesn't like 'spaces' or '-' in file names and will default to '.'):
> plot(mydata$mmax.temp, type="o", col="blue")
where type = the of type of symbols and lines to usecol = the colour of the symbols and lines
This will produce a graph like this:
To add a trend line using just the temperatures, use lines(lowess()), lowess is the method for calculating the averages - I'm certain other methods exist but I know only this one for now:
> lines(lowess(mydata$mmax.temp, f=0.2))
where mydata$mmax.temp = your data$variablef = the smoothness of the line - the greater the value, the smoother the line
and this will superimpose a trend line to the graph we just created.
You can play around with the f value to your liking, but for what I've been working with, there is minimal difference. If you wish to read more about the lowess() function go here.
Now go make some trending lines ;D!
Ciao!
No comments:
Post a Comment