I am using bar graph with ggplot2 library and when number of values (dates in my case) on x-axis is high, additional blank value ticks appear on the beginig and the end of axis. Please, is there a way how to remove these? Reproducible code and image below.
library(ggplot2)
a <- runif(28, 2.0, 7.5)
b <- seq(as.Date("1910/1/1"), as.Date("1910/1/28"), "days")
ds = data.frame(a, b)
p <-
ggplot(data=ds, aes(b, a), environment = environment()) +
theme(panel.grid.major.x = element_blank(), panel.grid.minor = element_blank(),
panel.grid.major.y = element_line(color="grey"),
panel.background = element_blank(), panel.border = element_rect(fill= NA, colour = "grey")) +
geom_bar(width=.4,stat="identity") +
xlab(" ") + ylab(" ") +
theme(text = element_text(size=20), axis.text.x = element_text(angle=90), axis.text = element_text(color="black"),
legend.key = element_rect(fill="white")) +
scale_x_date(breaks = date_breaks("1 day"), labels = date_format("%d.%B %y"))
print(p)
When I put breaks = b
instead of breaks = date_breaks("1 day")
, it solves the problem. Also you need library(scales)
to run your example now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With