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 |
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 |
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) |
ggplot(iris, aes(x = Sepal.Length, y = Sepal.Width)) + # Draw ggplot2 facet plot geom_point() + facet_grid(. ~ Species)
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")) |
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) |
ggplot(iris_italic, # Italic label aes(x = Sepal.Length, y = Sepal.Width)) + geom_point() + facet_grid(. ~ Species, labeller = label_parsed)
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")) |
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) |
ggplot(iris_bold, # Bold label aes(x = Sepal.Length, y = Sepal.Width)) + geom_point() + facet_grid(. ~ Species, labeller = label_parsed)
Further Resources & Related Articles
Here, you may find some additional resources on topics such as ggplot2, graphics in R, text elements, and plot legends:
- Add Space Between Panels of ggplot2 Facet Plot
- Change Transparency of ggplot2 Plot Legend Items
- Modify ggplot2 Facet Label Background & Text Colors
- How to Annotate Bold & Italic Text to ggplot2 Graph
- How to Modify Facet Plot Labels of ggplot2 Graph
- Switch ggplot2 Facet Plot Labels from Top to Bottom