Wednesday, 29 January 2014

How to get the scale right in a chart


Exercise 2 We can use help to find how to adjust the plot to meet our requirements. For example, you can add a title to the x-axis using the additional argument xlab="year" Try this, and also add an appropriate y-axis label and plot title. Provide your plot for the solution to this exercise (you can use the ‘Export’ button in the graphics window). [4 Marks]
Exercise 3 Is there an apparent trend in the number of girls baptized over the years? [2 Marks]


#exercise 2
plot(x = arbuthnot$year, y = arbuthnot$girls, main="Baptism records for girls born in London 1629 to 1710",
     xlab="year", ylab = "number of newborn girls",type="l")





Make the axis start at zero is good practice







plot(x = arbuthnot$year, y = arbuthnot$girls, main="Baptism records for girls born in London 1629 to 1710",
     xlab="year", ylab = "number of newborn girls",type="l",ylim=c(0,10000))





Exercise 4 Now, make a plot of the proportion of boys over time. What do you see? Tip: As well as by using the and keys you can access your command history using the history tab in the upper right panel. This might save you a lot of typing. [3 Marks]
#exercise 4
boygirlrat<-arbuthnot$boys/(arbuthnot$boys + arbuthnot$girls)


plot(arbuthnot$year, boygirlrat,type="l")
This chart looks exciting - the ratio of boys to girls is all over the place

 But maybe not - it is just about 0.5 with bits of wiggling


plot(arbuthnot$year, boygirlrat,type="l",ylim=c(0,1))

Sunday, 26 January 2014

Starting off

Examples of how to use R with comments and help

One good thing about R Studio is that you can create a list of commands which you can keep.  This means when you've worked out how to do something you can save the command.

To do this go to File on the top line of RStudio > Select New File > RScript

Your screen will look like this now and you can see the two commands in a box on the top LHS .  This is the r script





 Once you have the Rscript, you can run the commands by selecting a few lines and then going to Code > Run line(s)