Home > OS >  ggplot2: theme(axis.text=element_text(size=3) does not change font size on the y-axis
ggplot2: theme(axis.text=element_text(size=3) does not change font size on the y-axis

Time:09-17

Using this code

FigureS8 <- plot(nonParametricBoot, "edge", plot = "difference", onlyNonZero = TRUE, order = "sample")

returns a figure where text labels on x- and y-axis are too big.

I therefore added theme():

FigureS8 <- plot(nonParametricBoot, "edge", plot = "difference", onlyNonZero = TRUE, order = "sample")
FigureS8   theme(axis.text=element_text(size=3))

Now font size on labels on the x-axis becomes smaller (as I want), but there are no changes to the fontsize on the y-axis. How can I change the font size on both?

CodePudding user response:

It might be an instance of this problem: ggplot2 theme: axis.text not inheriting from text?

Your theme needs to be 'complete' in order for axis.text.y to inherit from axis.text correctly. So either define a complete theme or just define both axis.text.x and axis.text.y

CodePudding user response:

Because you haven't specified which axis you want to change in you code, the axis.text is interpreted as applying only to the x axis, as that is always the first axis to be dealt with.

Therefore code should be:

  theme(axis.text.x = element_text(size = 3),
        axis.text.y = element_text(size = 3))
  • Related