Error: stat_count() can only have an x or y aesthetic

Viewed 100578

I am getting Error: stat_count() can only have an x or y aesthetic. when trying to plot using data from an excel sheet

library(readxl)
library(dplyr)
library(ggplot2)
dataset= read_excel("D:/Downloads/Covid19.xlsx")
dataset2= read_excel("D:/Downloads/Covid19.xlsx", sheet = "Sheet2")
dataset3= dataset[,c(4,5)]
ggplot(dataset2, aes(x=Region, y= male))+geom_bar()

My Data from excel file looks like this Dataset

Excel

1 Answers

You need to include stat='identity', which is basically telling ggplot2 you will provide the y-values for the barplot, rather than counting the aggregate number of rows for each x value, which is the default stat=count

ggplot(dataset2, aes(x=Region, y= male)) +
     geom_bar(stat='identity')
Related