Modify Only One Label of ggplot2 Facet Plot to Italic & Bold in R (2 Examples)

In this article you’ll learn how to change only one label of a ggplot2 facet plot to bold or italic in the R programming language.

Setting up the Examples

data(iris)                        # Loading example data frame
head(iris)
#   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
# 1          5.1         3.5          1.4         0.2  setosa
# 2          4.9         3.0          1.4         0.2  setosa
# 3          4.7         3.2          1.3         0.2  setosa
# 4          4.6         3.1          1.5         0.2  setosa
# 5          5.0         3.6          1.4         0.2  setosa
# 6          5.4         3.9          1.7         0.4  setosa
install.packages("ggplot2")       # Install ggplot2 package
library("ggplot2")                # Load ggplot2
ggplot(iris,
       aes(x = Sepal.Length,
           y = Sepal.Width)) +    # Draw ggplot2 facet plot
  geom_point() +
  facet_grid(. ~ Species)

r graph figure 1 modify only one label ggplot2 facet italic bold r

Example 1: Displaying One Specific ggplot2 Facet Plot Label in Italic

iris_italic <- iris               # Change labels in data frame
iris_italic$Species <- factor(iris_italic$Species,
                              labels = c("italic(setosa)",
                                         "versicolor",
                                         "virginica"))
ggplot(iris_italic,               # Italic label
       aes(x = Sepal.Length,
           y = Sepal.Width)) +
  geom_point() +
  facet_grid(. ~ Species, labeller = label_parsed)

r graph figure 2 modify only one label ggplot2 facet italic bold r

Example 2: Displaying One Specific ggplot2 Facet Plot Label in Bold

iris_bold <- iris                 # Change labels in data frame
iris_bold$Species <- factor(iris_bold$Species,
                            labels = c("bold(setosa)",
                                       "versicolor",
                                       "virginica"))
ggplot(iris_bold,                 # Bold label
       aes(x = Sepal.Length,
           y = Sepal.Width)) +
  geom_point() +
  facet_grid(. ~ Species, labeller = label_parsed)

r graph figure 3 modify only one label ggplot2 facet italic bold r

Further Resources & Related Articles

Here, you may find some additional resources on topics such as ggplot2, graphics in R, text elements, and plot legends:

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top