Reputation: 11
How do I show the x-axis label from 2010 to 2019? Currently, it only shows 2010.0, 2012.5, 2015.0, 2017.5
Here are my codes:
ggplot(data=combineboth,aes(x=Year,y=`Percentage Change`,fill=Town))+
geom_bar(stat='identity',position = 'dodge')+
scale_colour_manual("",
breaks = c("Serangoon", "Bukit_Timah"),
values = c("Serangoon"="green", "Bukit_Timah"="blue")) +
ggtitle("Percentage Change in HDB Resale Prices")+ xlab("Year")+ ylab("Percent (%)")+
theme(
plot.title = element_text(color="red",size=7, face="bold.italic", hjust = 0.5),
axis.title.x = element_text(color="red", size=8, face="bold"),
axis.title.y = element_text(color="red", size=8, face="bold"),
axis.text=element_text(size=5)
)
Upvotes: 1
Views: 251
Reputation: 125697
A simple solution to get nice date breaks is by converting year to a factor. Using some random data try this:
And if you want every year to show up then remove scale_x_discrete
.
library(ggplot2)
d <- data.frame(year = 2010:2020, y = runif(11))
ggplot(d, aes(factor(year), y)) +
geom_bar(stat = "identity") +
scale_x_discrete(breaks = seq(2010, 2020, 2))
Created on 2020-06-21 by the reprex package (v0.3.0)
Upvotes: 1