Boxplot Axes Labels - Remove Ticks X Axis

Hi all,

I tried setting up a boxplot with quite some long label names. I had to create some line breaks to make them fit.
It looks a bit odd now, as I am unable to remove the ticks on the x-axis. Any idea how I can remove these (tried several things, but nothing seemed to work properly) or alternatively move the labels down a bit.

I tried it a sneaky way by adding an additional line break before the actual text, but there doesn't seem to be enough space below the x-axis and thus that didn't help either.

Any idea anyone?

#> Please don't mind the German naming
boxplot(HO01_GD~SD12, data=WW, names=c("ohne beruflichen\n Bildungsabschluss", "Lehre/ Ausbildung\n im dualen System", "Fachschulabschluss", "Hochschulabschluss", "Promotion"))

You might want to check ?par which gives you all control on the base R plotting parameters.

For example, to remove the tickmarks:


WW <- data.frame(SD12 = rep(letters[1:5], each = 10),
                 HO01_GD = rnorm(50))

opar <- par(tck = 0)

boxplot(HO01_GD~SD12, data=WW, names=c("ohne beruflichen\n Bildungsabschluss", "Lehre/ Ausbildung\n im dualen System", "Fachschulabschluss", "Hochschulabschluss", "Promotion"))

par(opar)

Created on 2020-12-08 by the reprex package (v0.3.0)

Thanks a lot!

Do you happen to know if there is a way to have x-axis and y-axis set up independently?
E.g. one with and one without ticks? I didn't find anything in ?par for this. I know how to format the intervals for one axis, but was unable to fully remove them for the x-axis.

Yes, you can plot the main graph without axes, then add them separately with their own parameters:

boxplot(HO01_GD~SD12, data=WW, axes = FALSE) # plot without axes
axis(2) # default computations for y axis

# customized x axis
axis(1, at = 1:5,
     labels =  c("\n\nohne beruflichen\n Bildungsabschluss", "Lehre/ Ausbildung\n im dualen System", "Fachschulabschluss", "Hochschulabschluss", "Promotion"),
     tcl = 0)

Oh and not saying you have to, but you can also consider using ggplot2 which tends to do a better job for nice-looking graphics. But that does require learning a whole new plotting system with its own set of options.

library(ggplot2)

ggplot(WW) +
  geom_boxplot(aes(x=SD12, y=HO01_GD)) +
  scale_x_discrete(labels = c("ohne beruflichen\n Bildungsabschluss", "Lehre/ Ausbildung\n im dualen System", "Fachschulabschluss", "Hochschulabschluss", "Promotion")) +
  theme_classic()

Thank you ever so much!
I tried to stay away from ggplot2, as I guess I would mess everything up...
But the solution with taking away the axes and then re-plotting them works perfectly!
Thank you!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.