geom_text giving NAs introduced by coercion

83 views
Skip to first unread message

Chris Brien

unread,
Oct 25, 2012, 9:11:56 PM10/25/12
to ggp...@googlegroups.com
Hi all,

I am adding to lines of text to the last facet of a facet_grid plot and I get 4 warning messages saying that "NAs introduced by coercion".

The code for the plot is below and the plot that is produced looks fine. It is just the annoying warnings that do not appear if I remove the geom_text geoms. Any suggestions as to why I am getting these messages?

Cheers,

Chris

x.lev <- levels(Sources)
annot <- data.frame(Inf, -Inf, factor(x.lev[length(x.lev)], levels = x.lev))
names(annot) <- c("xDay", "backtransformed.predictions", "Sources")
 windows()
  pred.plot <-  ggplot(data=backtransforms,
                         aes_string(x = x.var, y = "backtransformed.predictions")) +
                         scale_colour_manual(values=cbPalette) +
                         scale_shape_manual(values=symb) +
                         scale_x_continuous(x.title) +
                         scale_y_continuous(y.title) +
                         layer(geom = "line", colour = cbPalette[1]) +
                         layer(geom = "point", shape = symb[7])  +
                         facet_grid(~ Sources)
pred.plot <- pred.plot + geom_ribbon(aes(ymin=lower.confidence.limit, ymax=upper.confidence.limit), 
                                    alpha=0.2, fill="blue", show_guide=FALSE) + scale_fill_hue() +
                          geom_text(data = annot, label = "Error bars are",
                                    hjust=1, vjust=-1.3, size = 2) +
                          geom_text(data = annot, label = "confidence intervals",
                                    hjust=1, vjust=-0.3, size = 2)
pred.plot

John Helly

unread,
Oct 25, 2012, 10:54:06 PM10/25/12
to ggp...@googlegroups.com
Hi.

I'm struggling again with annotate.

This time I'm reversing the y-axis and cannot understand why the line
segment is not passing through the specified end-points. It hits the
starting point but the other end just goes off the plot. If I don't
reverse the y-axis it works as expected.

Any help is much appreciated. Attached is a reproducible example.

J.

--
John Helly, University of California, San Diego / San Diego Supercomputer Center / Scripps Institution of Oceanography / 760 840 8660 mobile / stonesteps (Skype) / stonesteps7 (iChat) / http://www.sdsc.edu/~hellyj

myReproducible.R

John Helly

unread,
Oct 25, 2012, 10:55:11 PM10/25/12
to ggp...@googlegroups.com
Hi.

I'm struggling again with annotate.

This time I'm reversing the y-axis and cannot understand why the line
segment is not passing through the specified end-points. It hits the
starting point but the other end just goes off the plot. If I don't
reverse the y-axis it works as expected.

Any help is much appreciated. Attached is a reproducible example.

Thanks.
myReproducible.R

Winston Chang

unread,
Oct 26, 2012, 12:49:27 AM10/26/12
to John Helly, ggp...@googlegroups.com
Hm, I think that's probably a bug. It seems to not be reversing the xend and yend values for annotate(). I've filed it here:

In the meantime, you can create a separate data frame for the segment annotation, and use it with geom_segment:


segment <- data.frame(x=34.00, y=-0.3, xend = 34.5, yend = -0.1)

ggplot(C, aes(Salinity, dO18, color=Site)) +
  geom_point(size=3) +
  geom_segment(data=segment, aes(x=x, y=y, xend=xend, yend=yend),
               linetype=2, color="black") +
  scale_y_reverse()


-Winston



--
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+unsubscribe@googlegroups.com
More options: http://groups.google.com/group/ggplot2

John Helly

unread,
Oct 26, 2012, 12:51:53 AM10/26/12
to Winston Chang, ggp...@googlegroups.com
Thanks very much.
J.
-Winston

Reply all
Reply to author
Forward
0 new messages