# Uppyn's Blog

The world through Dutch eyes in Sydney

## Learning R – a second step

April 2, 2010

Posted by on In the last post I have done something very simple: I called the built-in data set ‘sunspots’ and drew a basic plot. With very basic means I can do some more to this plot. E.g. I can add a title and titles for the axes:

plot(sunspots,xlab=”years”,ylab = “sunspot count”,main = “Sunspot numbers”)

Now I have titles with just a simple command.

In the next step I would like to change the plot form a line plot to a dot plot. I do that by adding the type = “p” instruction to the plot command:

plot(sunspots,type=”p”,xlab=”years”,ylab = “sunspot count”,main = “Sunspot numbers”)

Easy enough. But now I would like to add a line the points that represents the average of the data. Now I need two commands:

k <- 40

lines( filter(sunspots, rep(1/k,k)), col = ‘blue’, lwd = 3 )

The extra command ”lwd=3′ gives me a little bit thicker line.

This remains pretty simple and it shows already how versatile R can be even at the very basic level!

Advertisements