G.ven
G.ven

Reputation: 31

R studio histogram Error: stat_bin() must not be used with a y aesthetic

enter image description here

I want to make a histogram with the data above, data shows the income per person in some country. Using this command I keep getting that

Error: stat_bin() must not be used with a y aesthetic.

incomenew <- data_opdracht_income_per_person_xlsx %>%
  gather("1990":"2018", key = "year", value = "income")
incomenew

incomenew$year <- as.numeric(incomenew$year)

incomenew$income <- as.numeric(incomenew$income)


dataexample3 <- incomenew %>%
  filter(country == "Netherlands" | country == "China" | country == "Nigeria")

figure4 <- ggplot(data= dataexample3, mapping = aes(x=year, y=income))

figure4 + geom_histogram() 

How can I change y not to be aesthetic?

Upvotes: 3

Views: 14706

Answers (1)

Beno&#238;t Fayolle
Beno&#238;t Fayolle

Reputation: 349

geom_histogram takes one vector as an argument and will put the data in different 'buckets' or 'bins'

You probably want something like:

figure4 <- ggplot(data= dataexample3, mapping = aes(x=year, y=income))
figure4 + geom_col(aes(color=country)

Upvotes: 2

Related Questions