We want to display a chart with ggplot, the xaxis is constituted with years and we want every year to appear on it.
data <- data.frame("year"=c(2000, 2005, 2006, 2007), "value"=c(10, 25, 20, 30)) ggplot(data) + geom_col(aes(x=year, y=value))
> data year value 1 2000 10 2 2005 25 3 2006 20 4 2007 30
In the x-axis, some years are not displayed
Give values to the axis with
xlabels <- min(data$year):max(data$year) ggplot(data) + geom_col(aes(x=year, y=value)) + scale_x_continuous(labels = xlabels, breaks=xlabels)
We could transform year in a factor but this would remove the missing years. However it can be on purpose.
ggplot(data) + geom_col(aes(x=as.factor(year), y=value))