I'm trying to show all the years on the x-axis using "seq(1999,2003,1)", but for some reason it is not working. How do I show all the years on the x-axis with 1 year intervals? So it looks like 1999, 2000, 2001, 2002, 2003.
col1 <- c(1999, 2000, 2001, 2002, 2003)
col2 <- c(5,4,3,4,3)
col3 <- c(4,3,1,3,5)
df <- data.frame(col1, col2, col3)
dfmelt <- melt(df, id.vars="col1")
ggplot(dfmelt, aes(x = col1, y = value, fill = variable)) +
geom_col () +
scale_x_discrete(breaks=(seq(1999,2003,1)), limits = c(1999, 2003))
Running this without scale_x_discrete shows all 5 years, but in my actual data, this is not the case, so I'm wondering if there is something wrong with the way I tried to plot this.
TIA
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.