qplot removes missing values but there are no missing values in the dataset

2,668 views
Skip to first unread message

Agustin Lobo

unread,
Jun 1, 2011, 4:45:57 PM6/1/11
to ggp...@googlegroups.com
Hi!

I do
> qplot(x=Wavelength,y=value,data=whtourDNm,color=target,geom="text",label=substr(whtourDNm[,2],5,5),size=I(2),xlim=c(300,800))
and works fine but try
> qplot(x=Wavelength,y=value,data=whtourDNm,color=target,geom="point",size=2,xlim=c(300,800))
Warning message:
Removed 9075 rows containing missing values (geom_point).
Nevertheless:
> any(is.na(whtourDNm))
[1] FALSE

Why are the 9075 rows removed?

Data in
https://sites.google.com/site/filestemp2/home/whtourDNm.rda

Thanks

Agus

Brandon Hurr

unread,
Jun 1, 2011, 4:52:56 PM6/1/11
to Agusti...@ija.csic.es, ggp...@googlegroups.com
xlim=c(300,800))

Because you told it to with your xlim statement. You need to use coord_cartesian to adjust the limits. 

On Wed, Jun 1, 2011 at 21:45, Agustin Lobo <alobo...@gmail.com> wrote:
xlim=c(300,800))

Agustin Lobo

unread,
Jun 1, 2011, 5:07:14 PM6/1/11
to Brandon Hurr, ggp...@googlegroups.com
Thanks for your fast answer, but why this problem does not come up in

> qplot(x=Wavelength,y=value,data=whtourDNm,color=target,geom="text",label=substr(whtourDNm[,2],5,5),size=I(2),xlim=c(300,800))

?

Agus

2011/6/1 Brandon Hurr <brando...@gmail.com>:

> --
> You received this message because you are subscribed to the ggplot2 mailing
> list.
> Please provide a reproducible example: http://gist.github.com/270442
>
> To post: email ggp...@googlegroups.com
> To unsubscribe: email ggplot2+u...@googlegroups.com
> More options: http://groups.google.com/group/ggplot2
>

Brandon Hurr

unread,
Jun 2, 2011, 2:19:38 AM6/2/11
to Agusti...@ija.csic.es, ggp...@googlegroups.com
Agus, 

If you supplied a reproducible example I could possibly figure it out because this issue is very data specific. With such complex calls, you should consider using the ggplot() instead of the qplot() call. 

When you supply a dataframe to plot and limit an axis, it is supposed to cut off the points that are outside of that range. I'm not entirely sure why there is a difference between geom_text and geom_point. I would expect both to behave the same, but perhaps they do not. 

Brandon

Agustin Lobo

unread,
Jun 2, 2011, 2:30:16 AM6/2/11
to Brandon Hurr, ggp...@googlegroups.com
Brandon,

I did supply the link to the data in my original message, but you cut
it and did not include it
in your answer:

"Data in
https://sites.google.com/site/filestemp2/home/whtourDNm.rda"

The question is why the response is different with different geom

Thanks

Agus

2011/6/2 Brandon Hurr <brando...@gmail.com>:

Brandon Hurr

unread,
Jun 2, 2011, 2:46:18 AM6/2/11
to Agusti...@ija.csic.es, ggp...@googlegroups.com
I'm sorry for overlooking that Agus. I just ran it and you're right, you get the warning in one case and not in the other. Your 33 spectra go from 325 to 1075 and you're limiting it to 800 so you are ignoring a lot of points. 

The plots are exactly the same as far as I can tell. I wonder if for some reason the geom_text call is suppressing the warning. This sort of thing would have to be answered by Hadley or Takahasi or someone else who knows the inner working better. 

Brandon

R version 2.13.0 RC (2011-04-06 r55347)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid      stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] mgcv_1.7-5    ggplot2_0.8.9 proto_0.3-9.1 reshape_0.8.4 plyr_1.4.1   

loaded via a namespace (and not attached):
[1] digest_0.4.2       lattice_0.19-23    Matrix_0.999375-49 nlme_3.1-100       tools_2.13.0      
point.png
text.png

Hadley Wickham

unread,
Jun 6, 2011, 8:24:21 PM6/6/11
to Brandon Hurr, Agusti...@ija.csic.es, ggp...@googlegroups.com
> The plots are exactly the same as far as I can tell. I wonder if for some
> reason the geom_text call is suppressing the warning. This sort of thing
> would have to be answered by Hadley or Takahasi or someone else who knows
> the inner working better.

It's not suppressing it - I just forgot to add the check to geom_text.

Hadley


--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/

KAMALAKKANNAN SRINIVASAN

unread,
Jul 21, 2018, 2:25:57 PM7/21/18
to ggplot2
Reply all
Reply to author
Forward
0 new messages