R studio直方图错误:不得将stat_bin()用于y美观

时间:2019-03-04 17:42:36

标签: r ggplot2 histogram

enter image description here

我想用上面的数据制作直方图,数据显示某个国家的人均收入。使用此命令,我不断得到

  

错误:stat_bin()不能与y美学一起使用。

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() 

如何更改y不美观?

1 个答案:

答案 0 :(得分:0)

geom_histogram以一个向量作为参数,并将数据放入不同的“存储桶”或“容器”

您可能想要类似的东西:

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