On Sun, Jan 26, 2014 at 12:23 PM, Thomas <
thoma...@maine.edu> wrote:
> There are two questions here. 1) Why is annotate still not working with
> dates
Well, that is once question you can ask. Another is how can I add a
line to a plot with dates on one or more axis? The answer seems to be
"use aesthetic mapping rather then setting fixed values". To
illustrate:
require(lubridate)
require(ggplot2)
tmp.df <- data.frame(x1 = seq(ymd("2010-03-02"), by = 1, length.out=20),
y1 = runif(20),
fac=rep(c(0,1),10))
p <- ggplot(data=tmp.df, aes(x1,y1)) +
geom_point()
## annotate does not work:
p + annotate("segment",
x = min(tmp.df$x),
xend = max(tmp.df$x),
y = 0,
yend = Inf,
col="red")
## Error in Ops.POSIXt((x - from[1]), diff(from)) :
## '/' not defined for "POSIXt" objects
## geom_segment with fixed values does not work:
p + geom_segment(x = min(tmp.df$x),
xend = max(tmp.df$x),
y = 0,
yend = Inf,
col="red")
## Error in Ops.POSIXt((x - from[1]), diff(from)) :
## '/' not defined for "POSIXt" objects
## geom_segment with mapping does work. This is they way I recommend.
p + geom_segment(aes(xend = xend, yend = yend),
data = data.frame(
x1 = min(tmp.df$x1),
y1 = 0,
xend = max(tmp.df$x1),
yend = Inf),
color = "red")
## Works
and 2) Is it possible to draw a line between two facets.
Yes, it is, though as far as I know it will be very difficult to align
such a line with data points on the plot:
library(grid)
p + facet_wrap(~fac) +
annotation_custom(
grob = linesGrob(x = unit(c(0.1, 0.9), "npc"), y = unit(c(0.1, 0.9), "npc"))
)
grid.lines(x = unit(c(0, 1), "npc"), y = unit(c(.5, .8), "npc"), gp =
gpar(col = "red"))
HTH,
Ista
> --
> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example:
>
https://github.com/hadley/devtools/wiki/Reproducibility
>
> To post: email
ggp...@googlegroups.com
> To unsubscribe: email
ggplot2+u...@googlegroups.com
> More options:
http://groups.google.com/group/ggplot2
>
> ---
> You received this message because you are subscribed to the Google Groups
> "ggplot2" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
ggplot2+u...@googlegroups.com.
> For more options, visit
https://groups.google.com/groups/opt_out.