How to build a trendline on a graph in R

LoomyBear picture LoomyBear · Mar 1, 2016 · Viewed 18.6k times · Source

I've checked everywhere, and people refer to examples that I can't understand (yes I'm kinda slow). Could anyone please explain me how to build a logarithmic trendline in R?

Here's the working example:

myds <- c(23.0415,13.1965,10.4110,12.2560,9.5910,10.7160,9.9665,8.5845,8.9855,8.8920,10.3425,9.3820,9.0860,9.6870,8.5635,9.0755,8.5960,7.9485,8.3235,8.1910)
plot(myds)

I can't find a simple way to apply regression trendlines. I'm interested in particular in the logarithmic and the linear trendlines. Is it possible to do without connecting any new packages?

Good sirs, please be kind to clarify!

Answer

Daniel picture Daniel · Mar 2, 2016

Since you have not provided reproducible examples, I'll post some links, which I think might help you:

An example for a simple, linear trend line is here: http://www.r-tutor.com/elementary-statistics/quantitative-data/scatter-plot

Furthermore, there has been a thread on this over at SO: How do I add different trend lines in R?

Using ggplot would make it a bit easier, as you can use the smooth functions.