I am trying to plot the following vector using ggplot
:
library(ggplot2)
vec =c(44.55 ,47.81 ,40.28 ,44.32 ,53.57 ,45.68 ,52.02 ,44.27 ,33.44 ,41.16)
by = c("1994-04-30", "1994-05-31", "1994-06-30", "1994-07-31", "1994-08-31", "1994-09-30", "1994-10-31", "1994-11-30", "1994-12-31", "1995-01-31")
vec.zoo = zoo(vec, order.by = as.Date(by))
g <-ggplot(vec.zoo) +
geom_line (aes(x=index(vec.zoo), y=coredata(vec.zoo)), color = "cadetblue4", size = 0.6) +
theme(axis.text.x = element_text(angle = 45, hjust = 1)) +
xlab("Time") +
ylab("Hit Ratio") +
scale_y_continuous(limits = c(0, 100))
scale_x_date(limits = c(start(vec.zoo), end(vec.zoo)))
g
Although I set the limits of the axis, they still don't intersect at origin. I would like to set the intersection at x= 0
and y = start(vec)
.
Here is the result I obtain:
Any help would be appreciated!! Thanks!!
You may use the
expand
argument in yourscale
calls. Settingexpand
to zero, removes the default, small gap between data and axes (see here)