Add Panel Border to ggplot2 Plot in R Last Updated : 28 Apr, 2021 Comments Improve Suggest changes Like Article Like Report In this article, we will use theme() function to add panel border to the plot in R Programming Language. Here we will create a scatter plot, but you can apply it to any plot and add a Panel Border to that one. Approach:Specify the data object, and it has to be a dataframe. Here it has two variable named year and point.Call ggplot() function. Put first parameter 'data' and then set the aesthetic function 'aes()'.Inside aes() function, set the year variable for the X Axis, use the point variable for the Y Axis.Call ggtitle() to set the title of the plot.Call geom_point() function. Here inside geom_point() function, we use aes() with size parameter for setting the size of points and also use col parameter to set the color of points.Add Panel Border to plot using theme() function and panel.border as its parameter. To add Panel Border to R plot we simply add theme() function to ggplot() function. Inside theme() function, we have to specify panel.border parameter to add panel border around plot and use element_rect() function as value of panel.border parameter. Syntax: theme(panel.border) Parameter: theme() has many parameters to specify the theme of plot. we can use them as per our requirements but for add panel border to plot, we will use only panel.border parameter and specify element_rect() function as it's value. Return: Theme of the plot. element_rect() is used for specifying borders and backgrounds. Syntax: element_rect(color = "color_name", fill = NULL, size = NULL, linetype = NULL) Parameter: fill : Specifies the color by which we fill whole rectangle.color : For specifying border color.size : For specifying border size.linetype : For specifying border line type Return: Border around plot. Dataset in use: yearpoint12011102201220320133042014405201550 Let just first create a regular scatter plot to understand the difference better. Example: R # load ggplot2 package library(ggplot2) # Create a dataframe for Plot data data <- data.frame(year = c(2011, 2012, 2013, 2014, 2015), point = c(10, 20, 30, 40, 50)) # Plot the scatter plot ggplot(data, aes(year, point)) + geom_point()+ ggtitle("Scatter Plot") Output: Simple Scatter plot using ggplot2 Now let's add a border to it and display the result. Example: R # load ggplot2 package library(ggplot2) # Create a dataframe for Plot data data <- data.frame(year = c(2011, 2012, 2013, 2014, 2015), point = c(10, 20, 30, 40, 50)) # Plot the scatter plot with panel border # of size 10 and green color ggplot(data, aes(year, point)) + geom_point()+ ggtitle("Scatter Plot with Panel Border")+ theme(panel.border = element_rect(color = "green", fill = NA, size = 10)) Output: Scatter Plot with Panel Border Comment More infoAdvertise with us Next Article Add Panel Border to ggplot2 Plot in R E erkrutikpatel Follow Improve Article Tags : R Language R-ggplot Similar Reads Add Confidence Band to ggplot2 Plot in R In this article, we will discuss how to add Add Confidence Band to ggplot2 Plot in the R programming Language. A confidence band is the lines on a scatter plot or fitted line plot that depict the upper and lower confidence bounds for all points on the range of data. This helps us visualize the error 3 min read Add Text to ggplot2 Plot in R In this article, we are going to see how to add Text to the ggplot2 plot in R Programming Language. To do this annotate() is used. It is useful for adding small annotations (such as text labels) or if you have your data in vectors, and for some reason don't want to put them in a data frame. Syntax: 2 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 Set Area Margins of ggplot2 Plot in R In this article, we will discuss how to set area margins of the ggplot2 plot in the R programming language. To do this call the theme() function and use the plot.margin argument of this function with the required data to this argument as per the requirement of the user. theme() function is a powerf 1 min read Increase border line thickness of ggplot2 plot in R In this article, we are going to see how to change the borderline thickness using the ggplot2 bar plot in R Programming Language. First, you need to install the ggplot2 package if it is not previously installed in R Studio. To install and load write the below command in R Console : install.packages( 2 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 Draw ggplot2 Legend without Plot in R A legend in the graph describes each part of the plot individually and is used to show statistical data in graphical form. In this article, we will see how to draw only the legend without a plot in ggplot2. First, let us see how to draw a graph with a legend so that the difference is apparent. For 3 min read How To Make Dumbbell Plot in R with ggplot2? The Dumbbell Plot shows the change between two points in our dataset. It is named so because of its Dumbbell shape. It helps us to understand the span of data categorically. To make Dumbbell Plot in R using ggplot2,  we use the geom_dumbbell() function. Syntax: geom_dumbbell(data, aes(y, x, xend), s 2 min read Add Common Legend to Combined ggplot2 Plots in R In this article, we will discuss how to create a combined plot with a shared legend in R Language using the ggplot2 package. To join multiple ggplot2 plots, we use the grid.arrange() function of the gridExtra package in the R Language. The grid.arrange() function converts the frame into a grid of th 3 min read Like