• 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
  • Seaborn
  • Matplotlib
  • ggplot2
  • Altair
  • About
    • Privacy Policy
  • Visualizing Activation Functions in Neural Networks
  • Confusion Matrix Calculator
  • Visualizing Dropout Rate in Neural Network
  • Visualizing Loss Functions in Neural Networks
  • Show Search
Hide Search

Error in ggplot(): Mapping should be created with `aes()`

datavizpyr · July 17, 2022 ·

Last updated on August 17, 2022

In this post we will see an example of one of most common errors while making a plot with ggplot2 and how to fix them.

library(tidyverse)
theme_set(theme_bw(16)

Let us we are trying to make a scatter plot using ggplot2 using the following code. Here we use mtcars dataset built-in R to make the scatter plot

mtcars %>%
  ggplot(mpg,disp)+
  geom_point()

If we try to execute the code we will get the following error.

Error in `ggplot()`:
! Mapping should be created with `aes()` or `aes_()`.

How to fix: ggplot2 error: Mapping should be created with `aes() or aes_()`

The error here is definitely is useful in coming up with ways to fix the error. The error message indirectly saying the we are missing aes() while specifying x and y-axis variables for the scatter plot.

By correctly adding aes() as shown below

mtcars %>%
  ggplot(aes(mpg,disp))+
  geom_point()+
  labs(subtitle= "How to fix: ggplot2 error: Mapping should be created with `aes()`")
ggsave("how_to_fix_ggplot2_error_Mapping_should_be_created_with_aes.png")

We will get the intended scatter plot shown below.

How to fix ggplot2 error: Mapping should be created with aes
How to fix ggplot2 error: Mapping should be created with aes

Explore the Complete ggplot2 Guide

35+ tutorials with code: scatterplots, boxplots, themes, annotations, facets, and more—tested and beginner-friendly.

Visit the ggplot2 Hub → No fluff—just code and visuals.

Related posts:

Default Thumbnailggplot2 error: Cannot use `+.gg()` with a single argument. How to fix Error in dataframeggplot2 error: how to fix error in dataframe How to fix Error in ggplot(., aes... could not find function ggplotggplot2 errot: how to fix could not find function “ggplot Customizing Mean mark to boxplot with ggplot2How To Show Mean Value in Boxplots with ggplot2?

Filed Under: ggplot2, R Tagged With: ggplot2 error

Primary Sidebar

Python & R Viz Hubs

  • Seaborn Guide & Cookbook
  • ggplot2 Guide & Cookbook
  • Matplotlib Guide & Cookbook
  • Confusion Matrix Calculator
  • Visualizing Activation Functions
  • Visualizing Dropout
  • Visualizing Loss Functions

Buy Me a Coffee

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

Go to mobile version