boxplot function has a lot of useful parameters allowing us to change the behaviour and appearance of the boxplot graphs. In this exercise we will try to use those parameters in order to replicate the visual style of Matlab’s boxplot. Before trying out this exercise please make sure that you are familiar with the following functions:
We will be using the same iris dataset which is available in R by default in the variable of the same name –
iris. The exercises will require you to make incremental changes to the default boxplot style.
Answers to the exercises are available here.
If you obtained a different (correct) answer than those listed on the solutions page, please feel free to post your answer as a comment on that page.
Make a default boxplot of Sepal.Width stratified by Species.
Change the range of the y-axis so it starts at 2 and ends at 4.5.
Modify the boxplot function so it doesn’t draw ticks nor labels of the x and y axes.
Add notches (triangular dents around the median representing confidence intervals) to the boxes in the plot.
Increase the distance between boxes in the plot.
Change the color of the box borders to blue.
a. Change the color of the median lines to red.
b. Change the line width of the median line to 1.
a. Change the color of the outlier points to red.
b. Change the symbol of the outlier points to “+”.
c. Change the size of the outlier points to 0.8.
a. Add the title to the boxplot (try to replicate the style of matlab’s boxplot).
b. Add the y-axis label to the boxplot (try to replicate the style of matlab’s boxplot).
a. Add x-axis (try to make it resemble the x-axis in the matlab’s boxplot)
b. Add y-axis (try to make it resemble the y-axis in the matlab’s boxplot)
c. Add the y-axis ticks on the other side.
NOTE: You can use
format(as.character(c(2, 4.5)), drop0trailing=TRUE, justify="right") to obtain the text for y-axis labels.