0
votes

The dataset is available here but I am only using the ones from Year 2010 - 2016 as a subset: https://www.kaggle.com/heesoo37/120-years-of-olympic-history-athletes-and-results/

I am trying to plot the height of different gender with a boxplot and it returns this plot:

enter image description here
I felt that it is not correct since there are way too many outliers...(mean=175, min=133, max=221). I was wondering if I need to adjust the Y-axis to include more data points in this boxplot? If so, how can I do that?

Here is my code:

ggplot(data = olympics, aes(x = Sex, y = Height) +
 geom_boxplot() +
 labs(title= "Height Distribution of Olympics Athletes by Gender")

Also, I was wondering if it is possible to plot such a graph with base R language as well? Thank you!

1
The link to the data is not working. Please provide it using e.g. dput. - kath
"I felt that it is not correct since there are way too many outliers...(mean=175, min=133, max=221)." Why do you "feel" that way? How do the numbers in brackets relate to your "feelings"? - Roland
Just execute dput(olympics) in R and paste the output into your question. - Roland
The graph is most likely correct, you just have that many outliers with the ggplots's default for the length of the whiskers enforced. If you want to extend the whiskers beyond an interquartile range of 1.5, you can do so by using coef in your call to boxplot. An example would be to type ggplot(data = olympics, aes(x = Sex, y = Height) + geom_boxplot(coef = 10) + labs(title= "Height Distribution of Olympics Athletes by Gender"). Note: This will of course only change how your data is displayed - tifu
I would second the points made by @kath and @Roland. It would be much easier if you provided the data using dput(). Many users, me included, are not inclined to register for a website and manually download a data set so if you want help, make it a bit easier for us :) - tifu

1 Answers

0
votes

Welcome to stackoverflow @VanLindert. The best way to get help is to give us code to run that replicates the problem. The datapasta and reprex packages make this easy to do. https://reprex.tidyverse.org/articles/articles/datapasta-reprex.html

What I suspect is going on is that you are readjusting the y-axis limits and the boxplot keeps changing. When you use plot + scale_y_continuous(limits = c(130, 225)) or the shorthand plot + ylim(130, 225) ggplot filters out values above/below those 130 and 225 and the quartiles are recalculated. If you want to just zoom in on the plot to a specific range, you can use

plot + coord_cartesian(ylim = c(130, 225))