How to Use R Plot pch Symbols to customize graph points

Sometimes when graphing data, you need to include different datasets on the same graph. When this is the case, it is helpful to have diverse symbols for different types of data. Plot pch symbols are an excellent way to do this. Having different graph point symbols for each dataset is a convenient way of supplying more information in your graph. It not only allows you to distinguish different datasets, but these symbols are also handy for showing how those datasets relate to each other. This opens the door to making your graphs more informative and useful. It will also make your graphs look more impressive to those who see them.

Description

These plotting symbols come with the ggpubr package which is in extension of the ggplot2 package. This package provides a collection of twenty-six points symbols that alow you to customize your graphs. There is no function for producing these symbols because you simply equate the argument “pch” to a number zero to twenty-five. Here is a list of these point shapes along with their numbers.

  • 0 = square.
  • 1 = circle.
  • 2 = triangle point up.
  • 3 = plus.
  • 4 = cross.
  • 5 = diamond.
  • 6 = triangle point down.
  • 7 = square cross.
  • 8 = star.
  • 9 = diamond plus.
  • 10 = circle plus.
  • 11 = triangles up and down.
  • 12 = square plus.
  • 13 = circle cros.
  • 14 = square and triangle down.
  • 15 = filled square.
  • 16 = filled circle.
  • 17 = filled triangle point-up.
  • 18 = filled diamond.
  • 19 = solid circle.
  • 20 = bullet – smaller circle.
  • 21 = filled circle blue.
  • 22 = filled square blue.
  • 23 = filled diamond blue.
  • 24 = filled triangle point-up blue.
  • 25 = filled triangle point down blue.

With the help of this list, you will be able to set the pch number to the one matching the plot symbol that you want to use.

Explanation

The process of adding these symbols simply involves adding the “pch” argument to the plotting function and equating it to the right number. A simple version when used with the plotting function looks like plot(x, y, pch = 8). When this is done you get a graph to have your data set with the selected symbol. This is possible because the various plotting functions have a lot of built-in flexibility to them that allows such additions to the original base R function. These symbols are part of the ggpubr package which is an extension to the ggplot2 package. Despite its association with the ggplot2 package, it works with the base R plotting functions as well. In each case, the process is the same in that you add the “pch” argument to the function equating it to the number of the plot symbol that you want to use. By combining the plot function, with the points function along with this argument, you can have multiple datasets on the same graph in a manner where they are easily distinguishable from each other.

Examples

Here are several coding examples that show the addition of these symbols, as well as help you to see what they are and how they work.

> library(“ggpubr”)
> show_point_shapes()

This example has code that produces a list of the symbols for you.

> t = as.numeric(Sys.time())
> set.seed(t)
> x = rnorm(100)
> x = sort(x)
> y = dnorm(x)
> plot(x,y)

This is simply an example of the default use of the plotting function for comparison purposes.

> library(“ggpubr”)
> t = as.numeric(Sys.time())
> set.seed(t)
> x = rnorm(100)
> x = sort(x)
> y = dnorm(x)
> plot(x,y, pch = 8)

Here we have an example of the plotting function with the “pch” argument added to select a star symbol.

> library(“ggpubr”)
> t = as.numeric(Sys.time())
> set.seed(t)
> x = rnorm(100)
> x = sort(x)
> y = dnorm(x)
> plot(x,y, pch = 8, col = “red”)

Here we have an example of the plotting function with the “pch” and color arguments added to select a red star symbol.

> library(“ggpubr”)
> t = as.numeric(Sys.time())
> set.seed(t)
> x = rnorm(26*4)
> x = sort(x)
> n = 0:(26*4)
> y = dnorm(x)
> z = 5
> plot(x,y, col = “white”)
> for (i in n) {
+ z = i%%26
+ points(x[i], y[i], pch = z)
+ }

This example includes the points function containing the “pch” argument so as to produce a graph containing all of the symbols.

> t = as.numeric(Sys.time())
> set.seed(t)
> x1 = rnorm(100)
> x2 = rnorm(100)
> x3 = rnorm(100)
> y = rnorm(100)
> plot(x1,y, pch = 0, col = “red”)
> points(x2, y, pch = 1, col = “blue”)
> points(x3, y, pch = 2, col = “green”)

In this last example, we are plotting three different datasets onto a single graph using these plotting symbols. We included the extra touch of having them in different colors.

Application

The main application of these plotting symbols is being able to include different datasets in the same graph in a manner in which they can be easily distinguished from one another. This is particularly helpful when the datasets are related in some way but being able to tell them apart provides useful information. It can be handy in determining whether or not two different datasets are talking about the same thing. It can also help by being able to include different datasets in the same graph that are unrelated but having them together provide useful information about what is happening to the data. You can use these symbols to see whether or not two or more datasets come together in a manner that suggests a relationship between them. Sometimes having different datasets plotted together, that otherwise may not seem related in any way, can show evidence suggesting that they are in fact related.

These symbols are a handy tool for making a graph come alive and revealing information you may not see otherwise. They make it easy to put different datasets on the same graph while still being able to tell them apart. It is also a tool that can make your graphs look more attractive to the viewer.

Scroll to top
Privacy Policy