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?
$
inside ofaes()
. Also histograms are univariate plots so you don't specify a y variable for those. Is your data already summarized? Maybe you want a bar chart? Tryggplot(df, aes(sp, cov) + geom_col()
. If you the same message then it's possible you've overwritten the defaultaes()
function. Take a look atconflicts()
to see if you are shadowing theggplot2::aes
function. - MrFlick