0

I would like to have the individual values ​​of the species above the bars, i use data from an excel csv file, commands like geom_text(aes(label=y) don't work for me, because i don't know what my y is.

My code looks like this:

ggplot(R_Sandbach, aes(x = fct_infreq(Species), colour = Species)) +
  geom_bar(fill = "white") +
  theme_minimal() +
  theme(
    axis.text.x =
      element_text(angle = 90, size = 5)
  ) +
  xlab("Fischarten") +
  ylab("Individuenanzahl")

This is a small part of the date im using

And this is how i want the bar chart to look like

stefan
  • 90,330
  • 6
  • 25
  • 51
  • Try `geom_text(aes(label=..count..), stat = "count", vjust = -.1)` which using stat ="count" will compute the counts which could be referenced via `..count..` and mapped on y. – stefan Jun 30 '22 at 10:51
  • Possible duplicate: [How to put labels over geom_bar in R with ggplot2](https://stackoverflow.com/questions/6455088/how-to-put-labels-over-geom-bar-in-r-with-ggplot2) – stefan Jun 30 '22 at 10:53
  • @stefan code works, regarding the y-problem do you know how i could use commands like `geom_bar(stat = "identity")` to change the bar colour. I get the error *geom_bar requires the following missing aesthetics: y*. – LayZeDanaDeFoxy Jun 30 '22 at 11:17
  • The `stat` has nothing to do with the colors. (: The bar color is set via the `fill` aes, i.e. use `fill=Species` inside `aes` (perhaps instead of color which is for the bar outline) and remove (!!) `fill = "white"`. If you want specific colors you could set them via `scale_fill_manual`. – stefan Jun 30 '22 at 11:22

0 Answers0