Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bold boxplot labels in R

Tags:

r

label

boxplot

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: http://img822.imageshack.us/img822/331/23807704.png

like image 238
Avatar Avatar asked Dec 04 '10 18:12

Avatar


People also ask

How do I make labels bold in R?

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.

How do you label a boxplot in R?

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.

How do I change the font size axis labels in boxplot in R?

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.

How do you bold an axis in R?

We can make the axis text font bold by using face=”bold” argument to element_text() function.


1 Answers

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.

like image 126
Gavin Simpson Avatar answered Sep 21 '22 05:09

Gavin Simpson