Change Point Size in ggplot2 Scatterplot in R (2 Examples)

 

In this article, I’ll demonstrate how to increase or decrease the size of points in a ggplot2 scatterplot in R.

Table of contents:

Sound good? Let’s take a look at some R codes in action…

 

Example Data, Packages & Basic Graphic

Consider the following example data.

data <- data.frame(x = 1:5,        # Example data
                   y = 1:5)
data                               # Print example data

 

table 1 data frame change point size ggplot2 scatterplot r

 

Table 1 shows that our example data is made of five rows and two integer columns called “x” and “y”.

We also need to install and load the ggplot2 package, if we want to use the corresponding functions:

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

Next, we can draw our data:

ggplot(data, aes(x, y)) +          # Create basic ggplot2 plot
  geom_point()

 

r graph figure 1 change point size ggplot2 scatterplot r

 

After running the previous R programming syntax the ggplot2 scatterplot shown in Figure 1 has been plotted.

 

Example 1: Increase Point Size in ggplot2 Plot

The following code shows how to make the points in our ggplot2 scatterplot larger.

For this, we have to specify a large value to the size argument within the geom_point function.

Have a look at the following example code:

ggplot(data, aes(x, y)) +          # Increase point size
  geom_point(size = 10)

 

r graph figure 2 change point size ggplot2 scatterplot r

 

In Figure 2 it is shown that we have created a ggplot2 xy-plot with larger dots with the previous code.

 

Example 2: Decrease Point Size in ggplot2 Plot

This example demonstrates how to create a ggplot2 scatterplot with tiny points.

For this, we have to specify a very small value to the size argument:

ggplot(data, aes(x, y)) +          # Decrease point size
  geom_point(size = 0.1)

 

r graph figure 3 change point size ggplot2 scatterplot r

 

Figure 3 shows the output of the previous code: A ggplot2 graphic with small points.

 

Video & Further Resources

Have a look at the following video which I have published on my YouTube channel. I’m explaining the R programming code of this tutorial in the video.

 

The YouTube video will be added soon.

 

In addition, you could have a look at the other articles of this homepage. You can find a selection of articles on topics such as graphics in R, ggplot2, and labels below.

 

At this point you should know how to modify the point size of a ggplot2 graphic in R. If you have any additional questions, let me know in the comments.

 

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.

Menu
Top