Skip to content

ggplot2 error: "Error in as.environment(where) : 'where' is missing"

5 messages · Bert Gunter, arun, Brian Smith +1 more

#
I just wanted to point out that the construction:

dataf <- as.data.frame(cbind(Sample,Vals))

is **EVIL** .

Why?
cbind() constructs a matrix out of the separate vectors, and must
coerce columns of different types, as is the case here, to do so (a
matrix must be of one data type). Consequently
Sample     Vals
"factor" "factor"

## is almost certainly not what is wanted.

The correct way to create the data frame is simply:
Sample      Vals
 "factor" "integer"

I have no idea whether the evil construction this is related to your
difficulties, but it couldn't help.

Cheers,
Bert
On Tue, Jun 11, 2013 at 10:44 AM, Brian Smith <bsmith030465 at gmail.com> wrote:

  
    
#
Hi,
dataf <- as.data.frame(cbind(Sample,Vals))
?str(dataf)
#'data.frame':??? 20 obs. of? 2 variables:
# $ Sample: Factor w/ 2 levels "A","B": 1 1 1 1 1 1 1 1 1 1 ...
# $ Vals? : Factor w/ 20 levels "121","154","159",..: 20 12 13 1 2 14 18 5 17 10 ...
ggplot(dataf,aes(x=Vals,colour=Sample))+geom_density()
#Error in as.environment(where) : 'where' is missing


dataf<- data.frame(Sample,Vals)
?str(dataf)
#'data.frame':??? 20 obs. of? 2 variables:
# $ Sample: Factor w/ 2 levels "A","B": 1 1 1 1 1 1 1 1 1 1 ...
# $ Vals? : int? 96 712 765 121 154 78 821 258 812 51 ...

ggplot(dataf,aes(x=Vals,colour=Sample))+geom_density() #no error
A.K.




----- Original Message -----
From: Brian Smith <bsmith030465 at gmail.com>
To: r-help Help <r-help at r-project.org>
Cc: 
Sent: Tuesday, June 11, 2013 1:44 PM
Subject: [R] ggplot2 error: "Error in as.environment(where) : 'where' is
	missing"

Hmm...I think it used to work before, but it gives an error now. Here is
some sample code:

=============
library(ggplot2)
Sample <- rep(c('A','B'),rep(10,2))
Vals <- sample(1:1000,20)
dataf <- as.data.frame(cbind(Sample,Vals))
myplot <- ggplot(dataf,aes(x=Vals,colour=Sample)) + geom_density()
myplot
=============

I get the following error:

"Error in as.environment(where) : 'where' is missing"

Am I doing something wrong?

thanks!



**************** sessionInfo() ***************

R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

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

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

other attached packages:
[1] gridExtra_0.9.1? ? ?  sm_2.2-4.1? ? ? ? ? ? imputation_2.0.1
locfit_1.5-9? ? ? ? ? TimeProjection_0.2.0? Matrix_1.0-12
timeDate_2160.97
[8] lubridate_1.2.0? ? ?  gbm_2.0-8? ? ? ? ? ?  survival_2.37-4
gplots_2.11.0? ? ? ?  MASS_7.3-23? ? ? ? ?  KernSmooth_2.23-10
caTools_1.14
[15] gdata_2.12.0? ? ? ? ? heatmap.plus_1.3? ? ? ggdendro_0.1-12
ggplot2_0.9.3.1? ? ?  hgu133a.db_2.7.1? ? ? affy_1.34.0
genefilter_1.38.0
[22] biomaRt_2.12.0? ? ? ? org.Hs.eg.db_2.7.1? ? GOstats_2.22.0
graph_1.34.0? ? ? ? ? Category_2.22.0? ? ?  GO.db_2.7.1
RSQLite_0.11.2
[29] DBI_0.2-5? ? ? ? ? ?  geneplotter_1.34.0? ? lattice_0.20-15
annotate_1.34.1? ? ?  AnnotationDbi_1.18.4? Biobase_2.16.0
BiocGenerics_0.2.0
[36] colorRamps_2.3? ? ? ? RColorBrewer_1.0-5? ? sparcl_1.0.3
gap_1.1-9? ? ? ? ? ?  plotrix_3.4-6? ? ? ?  som_0.3-5
pvclust_1.2-2
[43] RobustRankAggreg_1.0? impute_1.30.0? ? ? ?  reshape_0.8.4
plyr_1.8? ? ? ? ? ? ? zoo_1.7-9? ? ? ? ? ?  data.table_1.8.8
foreach_1.4.0
[50] foreign_0.8-53? ? ? ? languageR_1.4? ? ? ?  preprocessCore_1.18.0
gtools_2.7.1? ? ? ? ? BiocInstaller_1.4.9?  hash_2.2.6

loaded via a namespace (and not attached):
[1] affyio_1.24.0? ? bitops_1.0-4.2?  codetools_0.2-8? colorspace_1.2-1
dichromat_2.0-0? digest_0.6.3? ?  GSEABase_1.18.0? gtable_0.1.2
IRanges_1.14.4
[10] iterators_1.0.6? labeling_0.1? ?  munsell_0.4? ? ? proto_0.3-10
RBGL_1.32.1? ? ? RCurl_1.95-4.1?  reshape2_1.2.2?  scales_0.2.3
stats4_2.15.2
[19] stringr_0.6.2? ? tools_2.15.2? ?  tree_1.0-33? ? ? XML_3.96-1.1
xtable_1.7-1? ?  zlibbioc_1.2.0

??? [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
#
On Jun 11, 2013, at 10:44 AM, Brian Smith wrote:

            
It's _almost_always_ incorrect to do:  as.data.frame(cbind(anything))

No error with:

dataf <- data.frame(Sample,Vals)
David Winsemius
Alameda, CA, USA