Hi!
I have a dataframe 3 variables, and I did a geom_bar. I try to add the number of observations (variable value
), but I always get an error (Fehler in FUN(X[[i]], ...) : Objekt 'y' nicht gefunden
). The first two lines of plotting work.
My data:
library(dplyr)
library(tidyverse)
library(ggplot2)
library(ggpubr)
library(reshape2)
xy <- data.frame(c("1","2","3","4","5","6","7","8","9"),c(79,2058,11584,2469,527,260,77,10,6),c(532,38,10247,4700,1037,409,89,5,13))
colnames(xy) <- c("Kategorie","x","y")
xy <- melt(xy, id = "Kategorie")
Plotting and trying to add the number of observations:
ggplot() +
geom_bar(data = xy, aes(x = Kategorie, y=value, fill = variable), position = "dodge", stat = "identity")+
scale_x_discrete(breaks = 1:9, name = "Kategorie (min)", labels = c("keine Hst/\nAngabe", "0", "1-5", "6-15", "16-30", "31-60", "61-120", "121-180", ">180")) +
geom_text(aes(label=value),nudge_x=0, nudge_y=250,size=12.5)
# geom_text(data = label_Histo0, aes(label = textlabel,color=NULL, y=y),size=3)
# geom_text(aes(label = y))
# geom_text(aes(label=paste(value)), size=5, hjust=-.6, vjust=1.5)
Here is the image, how it looks right now. Above the bars, I would like to add the number of observations:
I hope, I was clear enough, explaining my problem.
Yours,
Isabella