Problem with stacked density plot

99 views
Skip to first unread message

Eckart

unread,
Oct 7, 2010, 7:36:44 AM10/7/10
to ggplot2
Hello!

I am having trouble producing a stacked density plot. I always get
"Error in pairwise(nseq)..." shown below, even for other data sets.
The equivalent notation using ggplot and geom_density leads to the
same error. What am I doing wrong?

Example:
library(ggplot2)
qplot(mpg, ..density.., data=mtcars, geom="density", fill=factor(mtcars
$gear), position="stack")
Error in pairwise(nseq) :
pairwise: N must be positve numeric and of length 1
In addition: Warning message:
In if ((c == ".") | (c == "-")) { :
the condition has length > 1 and only the first element will be used

Thanks,

Eckart

Andrie de Vries

unread,
Oct 7, 2010, 9:22:10 AM10/7/10
to ggplot2
Eckart

Your code ran first time on my machine and plots a graph.

What version of R and ggplot2 are you using?

Can you paste the results of sessionInfo() to this thread?

> sessionInfo()
R version 2.11.1 (2010-05-31)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

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

other attached packages:
[1] ggplot2_0.8.8 proto_0.3-8 reshape_0.8.3 plyr_1.2.1
[5] svSocket_0.9-48 TinnR_1.0.3 R2HTML_2.0.0 Hmisc_3.8-2
[9] survival_2.35-8

loaded via a namespace (and not attached):
[1] cluster_1.13.1 digest_0.4.2 lattice_0.19-11 svMisc_0.9-57
[5] tools_2.11.1

Andrie

Ista Zahn

unread,
Oct 7, 2010, 9:35:12 AM10/7/10
to Eckart, ggplot2
Hi Eckart,
I've noticed that things can get weird when you redundantly specify
the data.frame. Try omitting the mtcars$ part, like this

qplot(mpg, ..density.., data=mtcars, geom="density",

fill=factor(gear), position="stack")

-Ista

> --
> 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
>

--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

Eckart

unread,
Oct 7, 2010, 12:10:11 PM10/7/10
to ggplot2
Hi Andrie!

On Oct 7, 9:22 am, Andrie de Vries <apdevr...@gmail.com> wrote:
> Your code ran first time on my machine and plots a graph.
>
> What version of R and ggplot2 are you using?
>
> Can you paste the results of sessionInfo() to this thread?
>

Thank you for the feed back. I also tried using fill=factor(gear)
instead of fill=factor(mtcars$gear) resulting in the same error.
Should I upgrade to a newer R version?
Here is my sessionInfo() result:
> sessionInfo()
R version 2.10.0 (2009-10-26)
x86_64-unknown-linux-gnu

locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

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

other attached packages:
[1] ggplot2_0.8.8 digest_0.4.2 reshape_0.8.3
plyr_1.2.1
[5] proto_0.3-8 xtable_1.5-5 rnashape_0.6
MASS_7.3-3
[9] rna_0.2 RUnit_0.4.22 ROCR_1.0-3
gplots_2.7.3
[13] caTools_1.10 bitops_1.0-4.1 gdata_2.6.1
gtools_2.6.1
[17] igraph_0.5.4-1 Biostrings_2.14.0 IRanges_1.4.0
bio3d_1.0-6
[21] PROcess_1.22.0 Icens_1.18.0 survival_2.35-7

loaded via a namespace (and not attached):
[1] Biobase_2.6.0 tools_2.10.0

Thanks for any suggestions,

Eckart

Eckart

unread,
Oct 7, 2010, 12:51:33 PM10/7/10
to ggplot2
Ok, I am closer to the solution:
If I only load the ggplot2 library, things work fine, without error
and as advertised! If I, however, load in my self-written library with
its dependencies first, several conflicts appear upon reading the
ggplot2 library. So my error seems to be an issue with name conflicts
and overwritten function definitions. Being a pragmatist, I now write
out the result table from my own analysis to a file, restart R, read
that table back in a load ggplot2. This workaround does the trick.
Any great suggestions though for resolving name conflicts between
libraries or do I have to stick to my workaround?

Eckart


On Oct 7, 9:22 am, Andrie de Vries <apdevr...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages