“Error: Mapping should be created with `aes()` or `aes_()`.”

I’m trying to build a simple histogram with ggplot2 package in R. I’m loading my data from a csv file and putting 2 of the columns together in a data frame, like this:

df = data.frame(sp = data$species, cov = data$totalcover)

sp is recognised as a factor of 23 levels (my number of lines) and cov as 23 numbers. Then, to build the histogram, I’m executing this:

ggplot(df, aes(df$sp, df$cov) + geom_histogram())

However, R returns the error: “Error: Mapping should be created with aes() or aes_().”

How is this possible if I’m already using aes? Is it maybe related with the type of the values?

Leave a Comment

tech