Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data Visualization
  • Statistics in R
  • Machine Learning in R
  • Data Science in R
  • Packages in R
  • Data Types
  • String
  • Array
  • Vector
  • Lists
  • Matrices
  • Oops in R
Open In App
Next Article:
Modify axis, legend, and plot labels using ggplot2 in R
Next article icon

Change Theme Color in ggplot2 Plot in R

Last Updated : 30 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

A theme in ggplot2 is a collection of settings that control the non-data elements of the plot. These settings include things like background colors, grid lines, axis labels, and text sizes. we can use various theme-related functions to customize the appearance of your plots, including changing theme colors.

Using ggplot() Change Theme Color in ggplot2 Plot in R

The ggplot() method can be used to create a plot of the data points. The points can be specified in the aesthetic mappings of the ggplot() method, wherein the x and y coordinates represent the column vectors of the data frame to be plotted. 

Syntax:

ggplot(df, aes = )

Arguments : 

  • df : The data frame to be plotted.
  • aes : The aesthetic mappings.

1. Installing the ggplot2 package

The ggplot2 package in R can be downloaded and installed into the working space using the following command : 

R
install.packages("ggplot2") library("ggplot2") 

2. Plotting graph using ggplot()

To plot a graph firstly we have to create a data frame using data.frame() method and then that data we are plotting the graph and a component of geom_point() is added to represent the data values as points in the graph as seen in the output.

R
library(ggplot2)  data_frame1 = data.frame(x= c(2,4,3,1),                          y = c(3,1,6,8))                           ggplot(data_frame1,aes(x = x , y =y)) +    geom_point() 

Output:

Change Theme Color in ggplot2 Plot in R
Change Theme Color in ggplot2 Plot in R

3. Changing theme color based on the background panel 

The background color of the plot can be changed by using the theme function. It overrides the default theme parameters. The background theme can be changed using the following syntax : 

Syntax: theme( panel.background = element_rect(fill = , color = ))

Parameters:

  • fill : The fill color for the rectangle
  • color : border color
  • size : border size

We are going to change the background color to green and the x-axis and y-axis color to blue using the panel.background in theme() method.

R
library(ggplot2)  data_frame1 = data.frame(x= c(2,4,3,1),                          y = c(3,1,6,8))                           ggplot(data_frame1,aes(x = x , y =y)) +    geom_point()+   theme(panel.background = element_rect(fill = 'green', color = 'blue')) 

Output:

Change Theme Color in ggplot2 Plot in R
Change Theme Color in ggplot2 Plot in R

4. Changing theme color based on in-built themes

There are a large number of in-built themes in the ggplot which can be added as components to the existing plot. Let's try some of them: 

1. theme_linedraw()

This method is used to create black lines inside the plot.

R
library(ggplot2)  data_frame1 = data.frame(x= c(2,4,3,1),                          y = c(3,1,6,8))  ggplot(data_frame1,aes(x = x , y =y)) +    geom_point()+   theme_linedraw() 

Output:

Change Theme Color in ggplot2 Plot in R

2. theme_minimal()

This theme is used to remove background annotations.

R
library(ggplot2)  data_frame1 = data.frame(x= c(2,4,3,1),                          y = c(3,1,6,8))                           ggplot(data_frame1,aes(x = x , y =y)) +    geom_point()+   theme_minimal() 

Output:

Change Theme Color in ggplot2 Plot in R
Change Theme Color in ggplot2 Plot in R

3. theme_dark()

It is used to create a dark background theme, as a result of which the elements of the graph are better popped out.

R
library(ggplot2)  data_frame1 = data.frame(x= c(2,4,3,1),                          y = c(3,1,6,8))  ggplot(data_frame1,aes(x = x , y =y)) +    geom_point()+   theme_dark() 

Output:

Change Theme Color in ggplot2 Plot in R
Change Theme Color in ggplot2 Plot in R

4. theme_void()

It is used to remove the background theme.

R
library(ggplot2)  data_frame1 = data.frame(x= c(2,4,3,1),                          y = c(3,1,6,8))  ggplot(data_frame1,aes(x = x , y =y)) +    geom_point()+   theme_void() 

Output:

Change Theme Color in ggplot2 Plot in R
Change Theme Color in ggplot2 Plot in R

5. theme_light()

It is used to plot the data in the form of light gray lines and an axis.

R
library(ggplot2)  data_frame1 = data.frame(x= c(2,4,3,1),                          y = c(3,1,6,8))  ggplot(data_frame1,aes(x = x , y =y)) +    geom_point()+   theme_light() 

Output:

Change Theme Color in ggplot2 Plot in R
Change Theme Color in ggplot2 Plot in R

4. Changing the color of plotted points in the plot

The geom_point() method takes as arguments the aesthetic mappings which can be used to modify the color of the points by specifying the color.

R
library(ggplot2)  data_frame1 = data.frame(x= c(2,4,3,1),                          y = c(3,1,6,8))  ggplot(data_frame1,aes(x = x , y =y)) +    geom_point(aes(colour="red")) 

Output:

Change Theme Color in ggplot2 Plot in R
Change Theme Color in ggplot2 Plot in R

In this article, we learned how to change theme color in the ggplot2 plot in R programming language.


Next Article
Modify axis, legend, and plot labels using ggplot2 in R

Y

yippeee25
Improve
Article Tags :
  • R Language

Similar Reads

  • Data visualization with R and ggplot2
    The ggplot2 ( Grammar of Graphics ) is a free, open-source visualization package widely used in R Programming Language. It includes several layers on which it is governed. The layers are as follows: Layers with the grammar of graphicsData: The element is the data set itself.Aesthetics: The data is t
    7 min read
  • Introduction to ggplot2

    • Master Data Visualization With ggplot2
      In this article, we are going to see the master data visualization with ggplot2 in R Programming Language. Generally, data visualization is the pictorial representation of a dataset in a visual format like charts, plots, etc.  These are the important graphs in data visualization with ggplot2, Bar Ch
      8 min read

    • Efficient way to install and load R packages
      The most common method of installing and loading packages is using the install.packages() and library() function respectively. Let us see a brief about these functions - Install.packages() is used to install a required package in the R programming language. Syntax: install.packages("package_name") l
      2 min read

    Working with External Data

    • Plot from DataFrame in ggplot2 using R
      ggplot2 is a popular data visualization library in the R programming language. It is widely used for creating beautiful, customizable, and informative visualizations.  One of the most useful features of ggplot2 is the ability to plot data stored in a data frame. In this article, we will learn how to
      4 min read

    • How to personalize easily ggplot2 graphs in R
      In this article, we are going to learn how to personalize easily ggplot2 graphs in the R programming language. Data visualization is an essential tool for understanding and communicating complex data sets. One of the most popular and powerful visualization libraries in R is ggplot2, which offers a w
      11 min read

    Basic Plotting with ggplot2

    • Plot Only One Variable in ggplot2 Plot in R
      In this article, we will be looking at the two different methods to plot only one variable in the ggplot2 plot in the R programming language. Draw ggplot2 Plot Based On Only One Variable Using ggplot & nrow Functions In this approach to drawing a ggplot2 plot based on the only one variable, firs
      5 min read

    • How to create a plot using ggplot2 with Multiple Lines in R ?
      In this article, we will discuss how to create a plot using ggplot2 with multiple lines in the R programming language. Method 1: Using geom_line() function In this approach to create a ggplot with multiple lines, the user need to first install and import the ggplot2 package in the R console and then
      3 min read

    • Plot Lines from a List of DataFrames using ggplot2 in R
      For data visualization, the ggplot2 package is frequently used because it allows us to create a wide range of plots. To effectively display trends or patterns, we can combine multiple data frames to create a combined plot. Syntax: ggplot(data = NULL, mapping = aes(), colour()) Parameters: data - Def
      3 min read

    • How to plot a subset of a dataframe using ggplot2 in R ?
      In this article, we will discuss plotting a subset of a data frame using ggplot2 in the R programming language. Dataframe in use:  AgeScoreEnrollNo117700521880103177915419752051885256199630717903581971409188345 To get a complete picture, let us first draw a complete data frame. Example: [GFGTABS] R
      8 min read

    • Change Theme Color in ggplot2 Plot in R
      A theme in ggplot2 is a collection of settings that control the non-data elements of the plot. These settings include things like background colors, grid lines, axis labels, and text sizes. we can use various theme-related functions to customize the appearance of your plots, including changing theme
      4 min read

    • Modify axis, legend, and plot labels using ggplot2 in R
      In this article, we are going to see how to modify the axis labels, legend, and plot labels using ggplot2 bar plot in R programming language. For creating a simple bar plot we will use the function geom_bar( ). Syntax: geom_bar(stat, fill, color, width) Parameters :  stat : Set the stat parameter to
      5 min read

    Common Geometric Objects (Geoms)

    • Comprehensive Guide to Scatter Plot using ggplot2 in R
      Scatter plot uses dots to represent values for two different numeric variables and is used to observe relationships between those variables. To plot the Scatter plot we will use we will be using the geom_point() function. This function is available in ggplot2 package which is a free and open-source
      7 min read

    • Line Plot using ggplot2 in R
      In a line graph, we have the horizontal axis value through which the line will be ordered and connected using the vertical axis values. We are going to use the R package ggplot2 which has several layers in it.  First, you need to install the ggplot2 package if it is not previously installed in R Stu
      6 min read

    • R - Bar Charts
      Bar charts provide an easy method of representing categorical data in the form of bars. The length or height of each bar represents the value of the category it represents. In R, bar charts are created using the function barplot(), and it can be applied both for vertical and horizontal charts. Synta
      4 min read

    • Histogram in R using ggplot2
      A histogram is an approximate representation of the distribution of numerical data. In a histogram, each bar groups numbers into ranges. Taller bars show that more data falls in that range. It is used to display the shape and spread of continuous sample data. Plotting Histogram using ggplot2 in RWe
      5 min read

    • Box plot in R using ggplot2
      A box plot is a graphical display of a data set which indicates its distribution and highlights potential outliers It displays the range of the data, the median, and the quartiles, making it easy to observe the spread and skewness of the data. In ggplot2, the geom_boxplot() function is used to creat
      5 min read

    • geom_area plot with areas and outlines in ggplot2 in R
      An Area Plot helps us to visualize the variation in quantitative quantity with respect to some other quantity. It is simply a line chart where the area under the plot is colored/shaded. It is best used to study the trends of variation over a period of time, where we want to analyze the value of one
      3 min read

    Advanced Data Visualization Techniques

    • Combine two ggplot2 plots from different DataFrame in R
      In this article, we are going to learn how to Combine two ggplot2 plots from different DataFrame in R Programming Language. Here in this article we are using a scatter plot, but it can be applied to any other plot. Let us first individually draw two ggplot2 Scatter Plots by different DataFrames then
      2 min read

    • Annotating text on individual facet in ggplot2 in R
      In this article, we will discuss how to annotate a text on the Individual facet in ggplot2 in R Programming Language. To plot facet in R programming language, we use the facet_grid() function from the ggplot2 library. The facet_grid() is used to form a matrix of panels defined by row and column face
      5 min read

    • How to annotate a plot in ggplot2 in R ?
      In this article, we will discuss how to annotate functions in R Programming Language in ggplot2 and also read the use cases of annotate.  What is annotate?An annotate function in R can help the readability of a plot. It allows adding text to a plot or highlighting a specific portion of the curve. Th
      4 min read

    • Annotate Text Outside of ggplot2 Plot in R
      Ggplot2 is based on the grammar of graphics, the idea that you can build every graph from the same few components: a data set, a set of geoms—visual marks that represent data points, and a coordinate system. There are many scenarios where we need to annotate outside the plot area or specific area as
      2 min read

    • How to put text on different lines to ggplot2 plot in R?
      ggplot2 is a plotting package in R programming language that is used to create complex plots from data specified in a data frame. It provides a more programmatic interface for specifying which variables to plot onto the graphical device, how they are displayed, and general visual properties.  In thi
      3 min read

    • How to Connect Paired Points with Lines in Scatterplot in ggplot2 in R?
      In this article, we will discuss how to connect paired points in scatter plot in ggplot2 in R Programming Language. Scatter plots help us to visualize the change in two more categorical clusters of data. Sometimes, we need to work with paired quantitative variables and try to visualize their relatio
      2 min read

    • How to highlight text inside a plot created by ggplot2 using a box in R?
      In this article, we will discuss how to highlight text inside a plot created by ggplot2 using a box in R programming language.  There are many ways to do this, but we will be focusing on one of the ways. We will be using the geom_label function present in the ggplot2 package in R. This function allo
      3 min read

    Adding labels, titles, and legends in r

    • Working with Legends in R using ggplot2
      A legend in a plot helps us to understand which groups belong to each bar, line, or box based on its type, color, etc. We can add a legend box in R using the legend() function. These work as guides. The keys can be determined by scale breaks. In this article, we will be working with legends and asso
      7 min read

    • How to Add Labels Directly in ggplot2 in R
      Labels are textual entities that have information about the data point they are attached to which helps in determining the context of those data points. In this article, we will discuss how to directly add labels to ggplot2 in R programming language. To put labels directly in the ggplot2 plot we add
      5 min read

    • How to change legend title in ggplot2 in R?
      In this article, we will see how to change the legend title using ggplot2 in R Programming.  We will use ScatterPlot. For the Data of Scatter Plot, we will pick some 20 random values for the X and Y axis both using rnorm() function which can generate random normal values, and here we have one more p
      3 min read

    • How to change legend title in R using ggplot ?
      A legend helps understand what the different plots on the same graph indicate. They basically provide labels or names for useful data depicted by graphs. In this article, we will discuss how legend names can be changed in R Programming Language. Let us first see what legend title appears by default.
      2 min read

    Customizing Visual Appearance

    • Introduction to Color Palettes in R with RColorBrewer
      RColorBrewer is an R Programming Language package library that offers a variety of color palettes to use while making different types of plots. Colors impact the way we visualize data. If we have to make a data standout or we want a color-blind person to visualize the data as well as a normal person
      3 min read

    • Using Colors to Create Engaging Visualisations in R
      Colors are an effective medium for communicating information. The color display of data plays a critical role in visualization and exploratory data analysis. The exact use of color for data display allows for known interrelationships and patterns within data. The careless use of color will create un
      7 min read

    • Themes and background colors in ggplot2 in R
      In this article, we will discuss how to change the look of a plot theme (background color, panel background color, and gridlines) using the R Programming Language and ggplot2 package.  Themes in ggplot2 package The ggplot2 package in R Language has 8 built-in themes. To use these themes we just need
      3 min read

    • How to change background color in R using ggplot2?
      In this article, we will discuss how to change the background color of a ggplot2 plot in R Programming Language. To do so first we will create a basic ggplot2 plot. Step 1: Create sample data for the plot. sample_data <- data.frame(x = 1:10, y = 1:10) Step 2: Load the package ggplot2. library("gg
      2 min read

    Handling Data Subsets: Faceting

    • How to create a faceted line-graph using ggplot2 in R ?
      A potent visualization tool that enables us to investigate the relationship between two variables at various levels of a third-category variable is the faceted line graph. The ggplot2 tool in R offers a simple and versatile method for making faceted line graphs. This visual depiction improves our co
      6 min read

    • How to Combine Multiple ggplot2 Plots in R?
      In this article, we will discuss how to combine multiple ggplot2 plots in the R programming language.  Combining multiple ggplot2 plots using '+' sign to the final plot In this method to combine multiple plots, here the user can add different types of plots or plots with different data to a single p
      2 min read

    • Change Labels of GGPLOT2 Facet Plot in R
      In this article, we will see How To Change Labels of ggplot2 Facet Plot in R Programming language.  To create a ggplot2 plot, we have to load ggplot2 package. library() function is used for that. Then either create or load dataframe. Create a regular plot with facets. The labels are added by default
      3 min read

    • Change Font Size of ggplot2 Facet Grid Labels in R
      In this article, we will see how to change font size of ggplot2 Facet Grid Labels in R Programming Language.  Let us first draw a regular plot without any changes so that the difference is apparent. Example: [GFGTABS] R library("ggplot2") DF <- data.frame(X = rnorm(20), Y = rnorm(20), g
      2 min read

    • Remove Labels from ggplot2 Facet Plot in R
      In this article, we will discuss how to remove the labels from the facet plot in ggplot2 in the R Programming language. Facet plots, where one subsets the data based on a categorical variable and makes a series of similar plots with the same scale. We can easily plot a facetted plot using the facet_
      2 min read

    Grouping Data: Dodge and Position Adjustments

    • How to Make Grouped Boxplots with ggplot2 in R?
      In this article, we will discuss how to make a grouped boxplot in the R Programming Language using the ggplot2 package. Boxplot helps us to visualize the distribution of quantitative data comparing different continuous or categorical variables. Boxplots consist of a five-number summary which helps i
      3 min read

    • Combine and Modify ggplot2 Legends with Ribbons and Lines
      The ggplot2 library is often used for data visualization. One feature of ggplot2 is the ability to create and modify legends for plots. In this tutorial, we will cover how to combine and modify ggplot2 legends with ribbons and lines. To begin, make sure you have the ggplot2 library installed and loa
      4 min read

    • How to Avoid Overlapping Labels in ggplot2 in R?
      In this article, we are going to see how to avoid overlapping labels in ggplot2 in R Programming Language. To avoid overlapping labels in ggplot2, we use guide_axis() within scale_x_discrete(). Syntax: plot+scale_x_discrete(guide = guide_axis(<type>)) In the place of we can use the following p
      2 min read

geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences