theme_test ggplot2 Theme in R (6 Examples)


This article demonstrates how to set the ggplot2 theme to the theme_test in R programming.

Table of contents:

You’re here for the answer, so let’s get straight to the examples…


Example Data & Packages

The following data will be used as basement for this tutorial:

set.seed(122665)                           # Set random seed
data <- data.frame(x = rnorm(160),         # Create example data frame
                   y = rnorm(160),
                   group = LETTERS[1:4])
head(data)                                 # Print head of example data frame


table 1 data frame theme_test ggplot2 theme


Table 1 shows that our example data consists of three columns.

In this tutorial, we’ll also need to install and load the ggplot2 package:

install.packages("ggplot2")                # Install & load ggplot2 package


Example 1: Draw ggplot2 Scatterplot Using theme_test()

ggplot(data,                               # theme_test scatterplot
       aes(x = x,
           y = y,
           col = group)) +
  geom_point() +


r graph figure 1 theme_test ggplot2 theme


Example 2: Draw ggplot2 Density Plot Using theme_test()

ggplot(data,                               # theme_test density plot
       aes(x = x,
           fill = group)) +
  geom_density(alpha = 0.5) +


r graph figure 2 theme_test ggplot2 theme


Example 3: Draw ggplot2 Histogram Using theme_test()

ggplot(data,                               # theme_test histogram
       aes(x = x,
           fill = group)) +
  geom_histogram(alpha = 0.5,
                 position = "identity",
                 bins = 50) +


r graph figure 3 theme_test ggplot2 theme


Example 4: Draw ggplot2 Barchart Using theme_test()

ggplot(aggregate(y ~ group, data, sum),    # theme_test barplot
       aes(x = group,
           y = y,
           fill = group)) +
  geom_bar(stat = "identity") +


r graph figure 4 theme_test ggplot2 theme


Example 5: Draw ggplot2 Boxplot Using theme_test()

ggplot(data,                               # theme_test boxplot
       aes(x = x,
           fill = group)) +
  geom_boxplot() +


r graph figure 5 theme_test ggplot2 theme


Example 6: Draw ggplot2 Line Plot Using theme_test()

ggplot(data,                               # theme_test line plot
       aes(x = x,
           y = y,
           col = group)) +
  geom_line() +


r graph figure 6 theme_test ggplot2 theme


Video & Further Resources

Would you like to know more about the ggplot2 package? Then you may have a look at the following video of my YouTube channel. I explain how to use the ggplot2 package in much more detail:


Please accept YouTube cookies to play this video. By accepting you will be accessing content from YouTube, a service provided by an external third party.

YouTube Content Consent Button Thumbnail

YouTube privacy policy

If you accept this notice, your choice will be saved and the page will refresh.


You can also find tutorials on how to plot different types of graphics such as xy-plots, density plots, bargraphs, boxplots, histograms, and line charts using other ggplot2 themes:

Also, you may check out the introductions to other add-on packages that provide extra themes for ggplot2 plots:

In addition, you may want to read some of the related articles on this website. You can find a selection of tutorials below.


To summarize: You have learned on this page how to apply the theme_test function to modify the design and layout of a ggplot2 plot in the R programming language. In case you have additional comments and/or questions, let me know in the comments section.


Subscribe to the Statistics Globe Newsletter

Get regular updates on the latest tutorials, offers & news at Statistics Globe.
I hate spam & you may opt out anytime: Privacy Policy.

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.