0

I have created a boxplot using the following code -

ggplot(xray50g, aes(x = Company, y = DefScore, label = Batch, 
                     label2 = PercentPopAff, label3 = AvVertAff, 
                     label4 = EggsPerLitreReceiving)) +
geom_boxplot() +
geom_point(aes(colour = Ploidy), size = 0.5) +
geom_jitter() +
# USE ENVSTATS PACKAGE TO INCLUDE SAMPLE SIZE
stat_n_text(size = 3) +
# INCLUDE MEAN VALUES
stat_summary(fun = mean, geom = "point", shape = 4, size = 2, color = "black") +
stat_summary(fun = mean, colour = "black", geom = "text", size = 3, show.legend = FALSE,
           hjust = -0.35, vjust = -0.5, aes( label = round(..y.., digits = 2)))

I wanted to spread the data points out a little; however, when I use geom_jitter it seems to blur all the data points together and ruin the chart (see image).

Any help with this would be greatly appreciated.

enter image description here

enter image description here

1
  • decrease the size of the points, try ggbeeswarm package. And for more help provide some test data. Commented Mar 4, 2021 at 12:13

1 Answer 1

0

You can use the width argument of geom_jitter to control how much the points are spread along the x-axis. I'd also recommend making the jittered points transparent (alpha argument) and to stop geom_boxplot from plotting the outliers with the outlier.shape argument (as those points also will be plotted by the jitter layer). Try the following:

ggplot(xray50g, aes(x = Company, y = DefScore, label = Batch, 
                     label2 = PercentPopAff, label3 = AvVertAff, 
                     label4 = EggsPerLitreReceiving)) +
geom_boxplot(outlier.shape = NA) +
geom_jitter(alpha = 0.25, width = 0.1)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.