Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding "empty space" to perimeter of ggplot2 plot

I have a figure that looks like this:
Initial Plot

I am trying to increase the size of the asterisks, using this code:

ggplot(data, aes(x = Cohort, y = C1M_HP, fill = Cohort)) + geom_violin(width = 0.5) +
geom_boxplot(outlier.shape = NA, width = 0.2, coef = 0) + 
geom_signif(comparisons = list(c("Control","Dup")), map_signif_level=TRUE, textsize = 6.25) + 
scale_fill_manual(values = c('#AED6F1', '#F1948A')) + theme_minimal() + 
geom_jitter(alpha = 0.8, width = 0.1)

Unfortunately, this results in the asterisks getting cut off, like so:
Increased asterisk size

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I have tried using plot.margin to change the margin sizes, but this is not correct.

How do I add extra ’empty space’ around the edges of my plot to prevent this issue?

>Solution :

One way is to use coord_cartesian(ylim = c(ymin, ymax))

library(ggplot2)
library(ggsignif)

ggplot(mtcars, aes(x = factor(am), y = mpg, fill = factor(am))) + geom_violin(width = 0.5) +
  geom_boxplot(outlier.shape = NA, width = 0.2, coef = 0) + 
  geom_signif(comparisons = list(c("0","1")), map_signif_level=TRUE, textsize = 10.25) + 
  scale_fill_manual(values = c('#AED6F1', '#F1948A')) + theme_minimal() + 
  geom_jitter(alpha = 0.8, width = 0.1)+
  theme_minimal()+
  coord_cartesian(ylim = c(0, max(mtcars$mpg)+5))

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading