Formatting plots

Plots in R can be formatted in many ways. We have already seen some of them in this chapter. In this section, we briefly explore some of these options. Let's go back to the data frame containing the 1,000 roulette spins and examine the relationship between the position on the roulette and the number by color. On line 1, we call the plot function. On line 2, we specify the attributes to be plotted, and add a little jitter to the data, using the jitter() function, otherwise, many points will be stacked over each other. The factor argument of this function controls the amount of jittering. We also reduce the size of the dots, using the cex attribute (line 3). We then title our graph and axes (lines 4 to 6).

Finally, we want to color the dots according to whether the number drawn is red or not (line 7). For this purpose, we use the col attribute:

1    plot( 
2      jitter(Data$position, factor=4),jitter(Data$number, factor=4),
3      cex = 0.5,
4      main = "Relationship between number and position on the 5      wheel", xlab = "Position", 
6      ylab="Number",
7      col=as.factor(Data$isRed))
Formatting plots

Relationship between number drawn and position on the wheel

As we can see from the graph, there is a relationship between the position on the wheel and the number, when considering color. Yet, red is associated with numbers higher than 18 in the first half of the wheel, counting from 0, and with small numbers on the second half of the wheel (and reversely for Black).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.220.16