How can the point size in ggplot2 be changed? 2

How can the point size in ggplot2 be changed?

The point size in ggplot2 can be changed by using the “size” argument in the geom_point() function. This argument allows the user to specify the size of the points in the graph, ranging from 0 (no points) to a larger number (bigger points). Additionally, the user can also use the “scale_size()” function to adjust the overall size of the points in the graph. By specifying a multiplier, the user can increase or decrease the size of the points in the plot. Furthermore, the user can also use the “aes()” function to map a variable in their dataset to the size of the points, allowing for a more dynamic and visually appealing plot. Overall, by utilizing these functions, the user can easily adjust the point size in ggplot2 to best suit their needs and create a more visually appealing graph.

Change Point Size in ggplot2 (3 Examples)


You can use the size argument to change the size of points in a ggplot2 scatterplot:

some_ggplot +
  geom_point(size=1.5)

The default size is 1.5 but you can decrease or increase this value to make the points smaller or larger.

The following examples show how to use each method in practice with the built-in dataset in R.

For reference, here’s what a ggplot2 scatterplot looks like using the default size:

library(ggplot2)

ggplot(data=mtcars, aes(x=mpg, y=wt)) +
  geom_point()

Example 1: Increase Point Size in ggplot2

The following code shows how to create a scatterplot in ggplot2 and increase the point size by using the size argument:

library(ggplot2)

#create scatterplot with increased point size
ggplot(data=mtcars, aes(x=mpg, y=wt)) +
  geom_point(size=5)

ggplot2 increase point size

Notice that the points are much larger than the default size.

Example 2: Decrease Point Size in ggplot2

The following code shows how to create a scatterplot in ggplot2 and decrease the point size by using the size argument:

library(ggplot2)

#create scatterplot with decreased point size
ggplot(data=mtcars, aes(x=mpg, y=wt)) +
  geom_point(size=0.5)

ggplot2 decrease point size

Notice that the points are much smaller than the default size.

Example 3: Adjust Point Size Based on Variable

The following code shows how to create a scatterplot in ggplot2 and adjust each point size based on the value of another variable in the mtcars dataset called qsec:

library(ggplot2)

#create scatterplot with point size based on value of qsec
ggplot(data=mtcars, aes(x=mpg, y=wt)) +
  geom_point(aes(size=qsec))

The size of each point is now dependent on the value of the qsec variable.

Notice that ggplot2 also automatically adds a legend on the right side of the plot to help you understand how the value of the qsec variable is mapped onto the size of each point.

Note: You can find the complete documentation for the geom_point() function .

Additional Resources

The following tutorials explain how to perform other common operations in ggplot2:

Cite this article

stats writer (2024). How can the point size in ggplot2 be changed?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-the-point-size-in-ggplot2-be-changed/

stats writer. "How can the point size in ggplot2 be changed?." PSYCHOLOGICAL SCALES, 29 Jun. 2024, https://scales.arabpsychology.com/stats/how-can-the-point-size-in-ggplot2-be-changed/.

stats writer. "How can the point size in ggplot2 be changed?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/how-can-the-point-size-in-ggplot2-be-changed/.

stats writer (2024) 'How can the point size in ggplot2 be changed?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-the-point-size-in-ggplot2-be-changed/.

[1] stats writer, "How can the point size in ggplot2 be changed?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.

stats writer. How can the point size in ggplot2 be changed?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top