Does anybody know how to embolden the x
and y
axis labels ("Single sample" and "Value axis") in an R boxplot?
This is what my boxplot looks like:
We simply add geom_text() as a layer and this layer has the following options: the option family allows a user to specify font. the option fontface allows a user to specify: plain, bold or italic.
Adding Labels We can add labels using the xlab,ylab parameters in the boxplot() function. By using the main parameter, we can add heading to the plot. Notch parameter is used to make the plot more understandable.
The font size of the main title of boxplot can be changed by defining the font size value using par(cex. main=”size”), here size value can be changed based on our requirement. This needs to be done before creating the boxplot, otherwise, there will be no effect on the size of the main title.
We can make the axis text font bold by using face=”bold” argument to element_text() function.
Using this example data:
dat <- data.frame(values = c(rnorm(100, mean = 1), rnorm(100, mean = 3),
rnorm(100, mean = 4, sd = 3)),
groups = factor(rep(c("aaa","bbb","ccc"), each = 100)))
There are several ways. One is to use ?plotmath
functionality and the plotmath
"function" bold()
in an expression:
boxplot(values ~ groups, data = dat,
ylab = expression(bold(Value~axis)),
xlab = expression(bold(Single~sample)))
or, similarly
boxplot(values ~ groups, data = dat,
ylab = expression(bold("Value axis")),
xlab = expression(bold("Single sample")))
Another way is to leave the titles off the plot and then add them with the title()
function using the bold font:
boxplot(values ~ groups, data = dat)
title(ylab = "Value axis", xlab = "Single sample", font.lab = 2)
We need graphical parameter font.lab
as this is the parameter that controls the axis labels. Read the entries in ?par
for more info.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With