There have been a few questions asking how to change ggplot x axis tick but I am having trouble possibly because of other asthetics I am using to plot. I want to extend the x axis tick to 25 from 7.
I'm using the following vector:
var <- c(2,2,1,0,1,1,1,1,1,3,2,3,3,5,1,4,4,0,3,4,1,0,3,3,0,0,
1,3,2,6,2,2,2,1,0,2,3,2,0,0,0,0,3,2,2,4,3,2,2,0,4,1,0,1,3,1,4,3,1,2,
6,7,6,1,2,2,4,5,3,0,6,5,2,0,7,1,7,3,1,4,1,1,2,1,1,2,1,1,4,2,0,3,3,2,2,2,5,3,2,5,2,5)
I use the code below to make a histogram where the x axis tick is beneath the bar
df <- data.table(x = var)
df <- df[, .N, by=x]
p <- ggplot(df, aes(x=factor(x), y=N)) +
geom_bar(stat="identity", width=1.0,
colour = "darkgreen",
fill = 'lightslateblue')
p <- p + labs(title = "hello world", x = "x tick", y = "ytick")
print(p)
When I print the histogram I would like the x axis ticks to reach 25
I tried using coord_cartesian(xlim = c(-0, 25))
but it does not plot properly as I would like the ticks to be labeled along the x axis.