1

I am using

expand = c(0, 0)

to remove the space between the zero and the border of the graph. However, the tick mark is then half on and half off the border when I save it as a png.

detail of graph

Is there any way of making the tick mark be in line with the border, which would look way more elegant? I tried making the border thicker, but that doesn't solve it.

df<-data.frame(x=c("T1", "T2", "T3"), y=c(48, 24, 26))
ggplot(data=df, aes(x, y))+
  geom_col()+ 
  theme_bw()+
  scale_y_continuous(expand = c(0, 0), limits = c(0, 60), breaks=c(0, 12, 24, 36, 48, 60))
tjebo
  • 21,977
  • 7
  • 58
  • 94
Meerkat
  • 123
  • 9
  • Appears to be a duplicate of https://stackoverflow.com/questions/36474643/graphical-parameters-in-ggplot2-how-to-change-axis-tick-thickness The answer in the link has a number of useful tips. – L Tyrone Mar 18 '23 at 04:18
  • @LeroyTyrone this is not a dupe. But the linked question is still interesting, thanks for sharing. – tjebo Mar 18 '23 at 09:29
  • 1
    @LeroyTyrone Yes, you are correct. It is a duplicate. The word 'align' was what was missing from my search. Thanks! – Meerkat Mar 27 '23 at 01:53

1 Answers1

1

An easy fix would be to use coord_cartesian(clip="off") to prevent the axis line from being clipped off when hitting the panel border:

df <- data.frame(x = c("T1", "T2", "T3"), y = c(48, 24, 26))

library(ggplot2)

ggplot(data = df, aes(x, y)) +
  geom_col() +
  theme_bw() +
  scale_y_continuous(
    expand = c(0, 0),
    limits = c(0, 60),
    breaks = c(0, 12, 24, 36, 48, 60)
  ) +
  coord_cartesian(clip = "off")

enter image description here

stefan
  • 90,330
  • 6
  • 25
  • 51