I didn't use r
but I have recently decided to use it to plot graphs – because of its great capability to do so.
I would like to make my graph better. Specifically, I'd plot numbers over bars.
I saw Adding labels to ggplot bar chart and I tried to use
geom_text(aes(x=years, y=freq, ymax=freq, label=value,
hjust=ifelse(sign(value)>0, 1, 0)),
position = position_dodge(width=1)) +
But the numbers failed to show up.
Here's my code:
# Load ggplot2 graphics package
library(ggplot2)
# Create dataset
dat <- data.frame(years = c("1991", "1993", "1997", "2001", "2005", "2007", "2011", "2015"),
freq = c(43.20, 52.13, 47.93, 46.29, 40.57, 53.88, 48.92, 50.92))
# Plot dataset with ggplot2
ggplot(dat, aes(years, freq)) + geom_bar(stat = "identity", width=0.55)
+ labs(x="Year",y="") + theme_classic()
# Comma as decimal mark
format(df, decimal.mark=",")