0

How to remove the extra portion of Y-axis (marked with red in the attached image) from the ggplot2 box-plot area? Tried many times but failed to do so. I used the following command lines and got the attached box-whiskar plot: (N.B. My graph was large in size, that is why the numbers indicating the sizes of texts and lines were huge)

p <- ggplot(d, aes(x=combinations, y=number)) + 
  ylim(NA, 2) + 
  stat_boxplot(geom = "errorbar", size = 3.2, color= "grey30", width= 0.5) + 
  geom_boxplot(outlier.color= "blue", outlier.size = 32, outlier.stroke = 5, outlier.shape = 4, width= 0.5, size= 3.2, color= "grey30", fill= "lightyellow", fatten= 3) + 
  stat_summary(fun= mean, geom = "crossbar", width= 0.5, size= 2.5, color= "red") + 
  xlab(label = "Non-crop flower combinations") + 
  ylab(label = "Number of bees / square meter") + 
  geom_point(size= 22, shape= 16, color= "black", alpha= 0.4)
p + 
  theme_classic() + 
  theme(axis.line = element_line(colour = 'black', size = 3.5), 
        axis.ticks = element_line(colour = 'black', size = 3.5), 
        axis.text = element_text(colour = "black", size = 95, margin = margin(t = 50, r = 0, b = 0, l = 0)), 
        axis.title = element_text(color= "black", size = 150, margin = margin(t = 0, r = 50, b = 0, l = 0)), 
        axis.ticks.length = unit(2.5, "cm"), plot.margin = unit(c(2,3,1,1), "cm"), 
        panel.background = element_rect(fill= "grey94"), 
        panel.grid.major = element_line(color="white", size = 3.2), 
        panel.grid.minor = element_line(color = "white", size = 1.5))

enter image description here

tjebo
  • 21,977
  • 7
  • 58
  • 94
  • 6
    Try with `scale_y_continuous(expand = expansion(mult = c(0.05, 0)))`. ggplot2 by default expands a continuous scale by 5 percent on each side. – stefan Jan 08 '21 at 21:59
  • Thank you @stefan for your kind help! I shall surely try this method. – Supratim Laha Jan 09 '21 at 23:00

0 Answers0