This is a perennial favorite of mine for being uninformatively informative—probably because I've never internalized the idea of aesthetics
as mainly meaning a geometry representing data or some auxiliary embellishment. Without a reprex
(see the FAQ) to make this concrete, all I can do is to help understand the error.
is the offending line. Looking at the function signature
geom_bar(
mapping = NULL,
data = NULL,
stat = "count",
position = "stack",
...,
just = 0.5,
width = NULL,
na.rm = FALSE,
orientation = NA,
show.legend = NA,
inherit.aes = TRUE
)
The thing to keep an eye on is the last line—aesthetics are inherited from the ggplot()
function.
As called, your function includes an optional width
argument and an optional $\dots$
argument to pass color. The position
argument was already the default. Everything else takes the default. So, nothing expressly changed the inherited aesthetic.
The data
argument, Df
controls which variable names in aes
will be recognizable. aes
is given CTQ_SG
, which is what? It is a variable in Df
, good enough, and it's been coerced with as.numeric
. What type of variable? It is a data frame within a data frame, A data frame has a length
equal to the number of its variables (columns). In this case, that is greater than one and, I am predicting, less than 186. I further predict that 186 is the number of rows of Df
.
Provides the arguments that might be to blame and because Df$CTQ_SG
which is provided as the x
argument, that is what I'd check first. What single variable (not whole data frame) is to be displayed?