06.09.2021 Views

Learning Statistics with R - A tutorial for psychology students and other beginners, 2018a

Learning Statistics with R - A tutorial for psychology students and other beginners, 2018a

Learning Statistics with R - A tutorial for psychology students and other beginners, 2018a

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

0 20 40 60 80 100 120<br />

Winning Margin<br />

0 20 40 60 80 100 120<br />

AFL games, 2010<br />

(a)<br />

(b)<br />

Figure 6.12: By default, R will only extent the whiskers a distance of 1.5 times the interquartile range,<br />

<strong>and</strong> will plot any points that fall outside that range separately (panel a). As we’ve seen in earlier graphics,<br />

the boxplot() function lets you customise the plot fairly extensively. This is illustrated in panel b, which<br />

shows a much more minimalist boxplot, <strong>and</strong> attaches in<strong>for</strong>mative labels to the graphic.<br />

.......................................................................................................<br />

> boxplot( x = afl.margins, # the data<br />

+ xlab = "AFL games, 2010", # x-axis label<br />

+ ylab = "Winning Margin", # y-axis label<br />

+ border = "grey50", # dim the border of the box<br />

+ frame.plot = FALSE, # don’t draw a frame<br />

+ staplewex = 0, # don’t draw staples<br />

+ whisklty = 1 # solid line <strong>for</strong> whisker<br />

+ )<br />

Overall, I think the resulting boxplot is a huge improvement in visual design over the default version. In<br />

my opinion at least, there’s a fairly minimalist aesthetic that governs good statistical graphics. Ideally,<br />

every visual element that you add to a plot should convey part of the message. If your plot includes things<br />

that don’t actually help the reader learn anything new, you should consider removing them. Personally,<br />

I can’t see the point of the cross-bars on a st<strong>and</strong>ard boxplot, so I’ve deleted them.<br />

Okay, what comm<strong>and</strong>s can we use to customise the boxplot? If you type ?boxplot <strong>and</strong> flick through<br />

the help documentation, you’ll notice that it does mention staplewex as an argument, but there’s no<br />

mention of whisklty. The reason <strong>for</strong> this is that the function that h<strong>and</strong>les the drawing is called bxp(), so<br />

if you type ?bxp all the gory details appear. Here’s the short summary. In order to underst<strong>and</strong> why these<br />

arguments have such stupid names, you need to recognise that they’re put together from two components.<br />

- 177 -

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!