theme_linedraw ggplot2 Theme in R (6 Examples)

 

In this article, I’ll show how to switch the ggplot2 theme to the theme_linedraw in R.

The tutorial contains the following content:

Let’s get started!

 

Example Data & Add-On Packages

The following data is used as basement for this R programming tutorial:

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

 

table 1 data frame theme_linedraw ggplot2 theme

 

As you can see based on Table 1, our exemplifying data is a data frame containing three columns. The variables x and y are numerical, and the variable group has the character class.

In this tutorial, I’ll also have to install and load the ggplot2 package.

install.packages("ggplot2")                # Install ggplot2 package
library("ggplot2")                         # Load ggplot2

 

Example 1: Draw ggplot2 Scatterplot Using theme_linedraw()

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

 

r graph figure 1 theme_linedraw ggplot2 theme

 

Example 2: Draw ggplot2 Density Plot Using theme_linedraw()

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

 

r graph figure 2 theme_linedraw ggplot2 theme

 

Example 3: Draw ggplot2 Histogram Using theme_linedraw()

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

 

r graph figure 3 theme_linedraw ggplot2 theme

 

Example 4: Draw ggplot2 Barchart Using theme_linedraw()

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

 

r graph figure 4 theme_linedraw ggplot2 theme

 

Example 5: Draw ggplot2 Boxplot Using theme_linedraw()

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

 

r graph figure 5 theme_linedraw ggplot2 theme

 

Example 6: Draw ggplot2 Line Plot Using theme_linedraw()

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

 

r graph figure 6 theme_linedraw ggplot2 theme

 

Video & Further Resources

I have recently published a video on my YouTube channel, which explains the R code of this article. You can find the video below.

 

The YouTube video will be added soon.

 

On this website, you can also find articles on how to create different kinds of graphics such as scatterplots, density plots, barcharts, boxplots, histograms, and line plots using the other ggplot2 themes:

Furthermore, you may have a look at the introductions to other add-on packages that provide extra themes for ggplot2 plots:

Besides the video and the tutorials above, you might have a look at the other tutorials which I have published on my website.

 

In this R tutorial you have learned how to apply the theme_linedraw function to modify the design and layout of a ggplot2 plot. Let me know in the comments, if you have further questions.

 

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.

Fill out this field
Fill out this field
Please enter a valid email address.

Menu
Top