Draw ggplot2 Polygon Plot without Filling Color in R (Example Code)

In this tutorial, I’ll demonstrate how to create a ggplot2 polygon plot without a filling color in R programming.

Setting up the Example

df <- data.frame(x = c(1, 5, 8, 3, 7, 2),    # Constructing example data
                 y = c(4, 3, 8, 2, 7, 9))
df
#   x y
# 1 1 4
# 2 5 3
# 3 8 8
# 4 3 2
# 5 7 7
# 6 2 9
install.packages("ggplot2")                  # Install & load ggplot2 package
library("ggplot2")
ggplot(df, aes(x, y)) +                      # Drawing ggplot2 polygon plot with filling
  geom_polygon()

r graph figure 1 draw ggplot2 polygon without filling color r

Example: Drawing a ggplot2 Polygon Plot without Filling Colors

ggplot(df, aes(x, y)) +                      # Drawing ggplot2 polygon plot without filling
  geom_polygon(color = "red",
               fill = NA)

r graph figure 2 draw ggplot2 polygon without filling color r

Related Tutorials

Have a look at the following R programming tutorials. They illustrate similar topics as this article:

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