Uppyn's Blog

The world through Dutch eyes in Sydney

Learning R – a second step

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!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: