• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

How to Add Dollar Symbol for Axis Labels with ggplot2?

datavizpyr · February 13, 2020 ·

In this tutorial, we will learn how to format x or y-axis so that we have dollar symbol in a plot made with ggplot2 in R.

Let us create a dataframe with salary education information for developers using the StackOverflow survey results. We first create two lists; one for education and the second for salary.

education <- c("Bachelor's", "Less than Bachelor's",
               "Master's","PhD","Professional")
salary <- c(110000,105000,126000,144200,95967)

We create a tibble using the two lists with tibble() function.

df <- tibble(Education=education,
             Salary=salary)
df
## # A tibble: 5 x 2
##   Education            Salary
##   <chr>                 <dbl>
## 1 Bachelor's           110000
## 2 Less than Bachelor's 105000
## 3 Master's             126000
## 4 PhD                  144200
## 5 Professional          95967

Let us make a simple bar plot with geom_col() in ggplot2.

df %>%
  ggplot(aes(x=Education, y=Salary)) +
  geom_col()

In the barplot, height of bars represent salary for each education category.

Note that on y-axis we have the salary as numbers. Instead, sometimes you would like to have the y-axis with dollars. We can use the R Package scales to format with dollar symbol.

We can do that by specifying scale_y_continuous() with labels=scales::dollar_format()

df %>%
  ggplot(aes(x=Education, y=Salary)) +
  geom_col()+
  scale_y_continuous(labels=scales::dollar_format())

Now, we get a bar plot with y-axis formatted with dollars.

Related posts:

Customizing Labels on Bars in Side by side Stacked BarplotHow To Add Labels to Grouped Barplot with Bars Side-By-Side in R? Add Mean Line to RIdgeline Plot with ggridges in RHow To Add Mean Line to Ridgeline Plot in R with ggridges? Visualizing Missing Data with Barplot in R ggplot2Visualizing Missing Data with Barplot in R Annotate Clusters with Ellipse with Labels ggforceHow To Annotate Clusters with Circle/Ellipse by a Variable in R

Filed Under: add dollar sign to label, ggplot2, R Tagged With: dollar in R, ggplot2, R, scales dollar_format()

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version