R studio histogram Error: stat_bin() must not be used with a y aesthetic
13,958
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)
Author by
G.ven
Updated on June 27, 2022Comments
-
G.ven almost 2 years
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?-
divibisan about 5 yearsPlease don't post data as images or links. Make a minimal reproducible example of your problem and include it as formatted text in your question.
-
camille about 5 yearsIt's really hard to help without knowing anything about your data. But is a histogram what you actually want? That's a chart that shows the distribution of a continuous variable, where the y-axis shows the count or density of values within given bins. So setting a y-value doesn't make sense. Maybe you want a bar chart
-
-
G.ven about 5 yearshow can i get the bars from each country next to each other, instead of on top of each other?
-
Benoît Fayolle about 5 yearsgeom_col(aes(color=country),position = "dodge")
-
G.ven about 5 yearsThank you for your help!