Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 882
Jijoy Avatar asked Apr 06 '20 20:04

Jijoy


Video Answer


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')
like image 79
user438383 Avatar answered Sep 17 '22 00:09

user438383