0

I've got the plot below: enter image description here

And I want to remove that small vertical tick that I guess is axis.line.y prolongation that goes below y=0.

 ggplot() + 
  geom_col(data=a, aes(x = X, y = M, fill = X), width = 0.75, position = position_dodge(0.1), colour = "black", size = 1) +
  labs(title = "XYZ") + xlab("ABCDEF") + ylab("Value") +
  coord_cartesian(ylim = c(0, NA)) +
  geom_errorbar(data=a, aes(x = X, y = M, ymin = M, ymax = max), width=0.4, size=0.5) + 
  geom_point(data = df2, aes(x = X, y = Y), shape = 21, size = 2, stroke = 1, colour = "black", fill = "white", position = position_jitter(height = .2, width = .2)) +
  scale_fill_manual(values = colors) +
  theme(
    aspect.ratio = 5/4,
    axis.line.y.left = element_line(color="black", size = 1),
    #axis.line.x = element_line(color="black", size = 1),
    axis.text.x = element_text(size = 20, family = "Helvetica", color = "black", angle=45, hjust=1),
    axis.text.y = element_text(size = 20, family = "Helvetica", color = "black", angle=0, hjust=1),
    axis.title.x.bottom = element_text(size = 20, family = "Helvetica", angle=0, margin = margin(t=30), hjust=NULL),
    axis.title.y = element_text(size = 25, family = "Helvetica", color = "black", angle=0, margin = margin(r = 30), vjust = 0.5),
    plot.title = element_text(size = 30, family = "Helvetica", color = "black", margin = margin(b = 30), hjust = 0.5 ),
    axis.ticks.y = element_line(size = 1.5),
    axis.ticks.length.y = unit(10,"pt") 
    ) + 
    geom_hline(yintercept=0, linetype="solid", colour = "black", size=1) 
   #geom_vline(xintercept=0, linetype="solid", colour = "black", size=1)

That's my code. As you can see by the # I tried using geom_vline instead of axis.line.y but then I didn't get any line (no error). I'd apreciate any help with getting rid of that unnecessary prolongation.

Gregor Thomas
  • 136,190
  • 20
  • 167
  • 294
Mieszko
  • 49
  • 4
  • `scale_y_continuous(expand=list(c(0,0.1), c(0,0)))` should do it – Gregor Thomas Mar 21 '20 at 14:37
  • It does but it also crops the plot so that the top dots are cut in half... – Mieszko Mar 21 '20 at 14:52
  • You can fix that by adjusting the second value of the list items. If you do `scale_y_continuous(expand = expansion(mult = c(0, .1)))` that should give you 10% on top of he bars... increase the 0.1 if you need more. See `?expansion` for details. – Gregor Thomas Mar 21 '20 at 19:10
  • As a general comment, you can make your theme modifications much briefer. If you add `theme_gray(family = "Helvetica")` that will set your font family for all text. The `theme_gray` function takes a `base_size` argument too that you can use to scale all the text sizes. And any theme arguments that have dots can be set and inherited, e.g., you could set `axis.text = element_text(size = 20, color = "black", hjust = 0)`, which will be used for both `axis.text.x` and `axis.text.y`. And you can do that and still modify portions at a lower level, e.g., `axis.text.x = element_text(angle = 45)`. – Gregor Thomas Mar 21 '20 at 19:14

0 Answers0