I am totally new to R and I need a Histogram which shows 5 different years on the x axis and the corresponding median on the y axis. And I am getting the error stat_bin() can only have an x or y aesthetic. I don´t know how to solve this :(
library(ggplot2)
myvars <- c("1965", "1975", "1985", "1995", "2005")
newdata <- Countries_GDP_1960_2020[myvars]
sapply(newdata, mean, na.rm=TRUE)
median1 <- sapply(newdata, median, na.rm=TRUE)
myvars1 <- as.numeric(as.character(myvars))
median2 <- data.frame(median1)
p <- ggplot(median2, aes(x=myvars1, y=median1)) + geom_bar(stat='identity') +
geom_histogram()
p