# Change Y-Axis to Percentage Points in ggplot2 Barplot in R (2 Examples)

In this R tutorial you’ll learn how to **set the axis labels of a barchart in percentage points**.

The tutorial contains this:

Let’s dive right into the examples…

## Example Data, Packages & Basic Graphic

We’ll use the data below as basement for this R programming tutorial:

data <- data.frame(x = LETTERS[1:5], # Example data y = c(0.4, 0.7, 0.1, 0.3, 0.6)) data # Print data # x y # 1 A 0.4 # 2 B 0.7 # 3 C 0.1 # 4 D 0.3 # 5 E 0.6 |

data <- data.frame(x = LETTERS[1:5], # Example data y = c(0.4, 0.7, 0.1, 0.3, 0.6)) data # Print data # x y # 1 A 0.4 # 2 B 0.7 # 3 C 0.1 # 4 D 0.3 # 5 E 0.6

The previous output of the RStudio console shows that our example data has five rows and two columns.

If we want to use the functions of the ggplot2 package, we also have to install and load ggplot2:

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

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

Next, we can draw the example data.

ggp <- ggplot(data, aes(x, y)) + # ggplot2 with default y-axis labels geom_bar(stat = "identity") ggp # Draw plot |

ggp <- ggplot(data, aes(x, y)) + # ggplot2 with default y-axis labels geom_bar(stat = "identity") ggp # Draw plot

The output of the previous code is shown in Figure 1 – A ggplot2 barchart with default axis values.

## Example 1: Set Y-Axis to Percent Using scale_y_continuous Function

In Example 1, I’ll show how to customize axis values of a barchart using the scale_y_continuous function. Have a look at the following R syntax and the resulting graphic:

ggp + # Change y-axis to percent scale_y_continuous(labels = scales::percent) |

ggp + # Change y-axis to percent scale_y_continuous(labels = scales::percent)

Figure 2 shows the output of the previously shown R syntax: A ggplot2 barchart with percentage points as y-axis labels.

You can also see that the percentage points are shown with one digit after the decimal point. In the next example, I’ll show how to change that…

## Example 2: Set Y-Axis to Percent with User-Defined Accuracy

The following R programming syntax explains how to adjust the accuracy (i.e. how precise the percentage points are rounded) of the percentages on the y-axis:

ggp + # Specify accuracy of y-axis scale_y_continuous(labels = scales::percent_format(accuracy = 1)) |

ggp + # Specify accuracy of y-axis scale_y_continuous(labels = scales::percent_format(accuracy = 1))

As illustrated in Figure 3, we plotted a barchart with percentage points rounded to zero digits.

## Video & Further Resources

I have recently released a video on my YouTube channel, which illustrates the contents of this article. You can find the video below.

*The YouTube video will be added soon.*

In addition, you may want to have a look at the related tutorials on this homepage:

- Plotting Categorical Variable with Percentage Points
- Change Formatting of Numbers of ggplot2 Plot Axis
- Adjust Space Between ggplot2 Axis Labels and Plot Area
- Rotate ggplot2 Axis Labels
- Set ggplot2 Axis Limit Only on One Side
- R Graphics Gallery
- The R Programming Language

At this point you should know how to **adjust ggplot2 axis labels of a barplot to show relative proportion values** in R.

Please note that a similar R code could also be applied to other types of ggplot2 graphics such as line plots or histograms.

If you have additional questions, don’t hesitate to let me know in the comments section.

### Statistics Globe Newsletter