Error in if (!all(data$ymin == 0)) warning("Stacking not well defined when ymin != 0", : missing value where TRUE/FALSE needed

873 views
Skip to first unread message

David Young

unread,
May 5, 2010, 5:51:34 PM5/5/10
to ggplot2
I was using the following code successfully until I added a vast
quantity of data. At which point I started getting the error:

Error in if (!all(data$ymin == 0)) warning("Stacking not well defined when ymin != 0", :
missing value where TRUE/FALSE needed

My function (graph8by2) just uses the summary function to create some
factors and the creates a faceted bar chart. I'm fairly new and don't
really understand what the error is telling me and I can't really send
a sample of the data since it worked when it was small and doesn't now
that it's big. Anyway I just thought if anyone had a guess as to
where I should begin looking for problems in the morning (I live in
Spain) then that'd be helpful. Thanks in advance to any responders.

I probably should mention that I did get the warning about "Stacking
not well defined" earlier, but since I wasn't stacking the bars and
the graphs appeared to be coming out fine I ignored it. The "missing
value where TRUE/FALSE needed" is new but the variables have always
had some missing values so it is not really clear what that means or
what is different.

graph8by2 <- function( var1, var2, dep, data) {

temp1 <- summary(data[,var1])
temp2 <- summary(data[,var2])
fac1 <- factor(cut(data[,var1] ,
breaks=c(temp1["Min."], temp1["1st Qu."]-((temp1["Median"]-temp1["1st Qu."])/2),
temp1["1st Qu."], temp1["Median"]-((temp1["Median"]-temp1["1st Qu."])/2),
temp1["Median"], temp1["Median"]+((temp1["3rd Qu."]-temp1["Median"])/2),
temp1["3rd Qu."], temp1["3rd Qu."]+((temp1["3rd Qu."]-temp1["Median"])/2),
temp1["Max."]) ))
fac2 <- factor(cut(data[,var2] ,
breaks=c(temp2["Min."], temp2["1st Qu."]-((temp2["Median"]-temp2["1st Qu."])/2),
temp2["1st Qu."], temp2["Median"]-((temp2["Median"]-temp2["1st Qu."])/2),
temp2["Median"], temp2["Median"]+((temp2["3rd Qu."]-temp2["Median"])/2),
temp2["3rd Qu."], temp2["3rd Qu."]+((temp2["3rd Qu."]-temp2["Median"])/2),
temp2["Max."]) ))

temp3 <- aggregate(data[, dep] ,
list( var1 =fac1, var2 =fac2),
mean)
temp4 <- aggregate(data[, dep] ,
list( var1 =fac1, var2 =fac2 ),
length)
temp4 <- as.vector(temp4$x)

temp3$sample.size <- factor(cut(temp4 , breaks=c(0, 100, 1000, 5000, 1000000 ) ))

qplot(var1, x, fill= sample.size, geom="bar", facets= var2 ~ . , data= temp3,
xlab = var1 , ylab = paste(dep," faceted by ", var2) ,
main = paste(dep, "\n by", var1, ",", var2) )
}





--
Best regards,

David Young
Marketing and Statistical Consultant
Madrid, Spain
+34 913 540 381
http://www.linkedin.com/in/europedavidyoung

mailto:dyo...@telefonica.net

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

hadley wickham

unread,
May 5, 2010, 5:57:15 PM5/5/10
to David Young, ggplot2
If you're not stacking, you can probably fix this by specifying
position = "identity", otherwise I'll need a reproducible example to
track down the bug.

Thanks!

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

Peter

unread,
May 6, 2010, 9:41:20 PM5/6/10
to ggplot2
I was having the same issue - I could run single plots, but once I
added facet_wrap (for 233 factors), I had the same error as David. I
added 'position="identity" to geom_histogram() and it worked. Let me
know if there is any additional detail I can provide to recreate this
error. Is there a way to limit/filter the factors displayed by the
facets (e.g. facet_wrap( ~ color %in% c("J","K")))?

ggplot(data, aes(x=log10(cost))) +
geom_histogram(color="red", fill="white", binwidth=.2,
position="identity") +
facet_wrap(~ DIAG1)
> Department of Statistics / Rice Universityhttp://had.co.nz/
>
> --
> 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

hadley wickham

unread,
May 8, 2010, 9:05:45 AM5/8/10
to Peter, ggplot2
> I was having the same issue - I could run single plots, but once I
> added facet_wrap (for 233 factors), I had the same error as David. I
> added 'position="identity" to geom_histogram() and it worked. Let me
> know if there is any additional detail I can provide to recreate this
> error.

A small reproducible example as described by
http://gist.github.com/270442 would be greatly appreciated.

> Is there a way to limit/filter the factors displayed by the
> facets (e.g. facet_wrap( ~ color %in% c("J","K")))?

No, but you can subset the underlying data.

Hadley

Ismail OURAICH

unread,
Jan 24, 2013, 10:32:22 PM1/24/13
to ggp...@googlegroups.com, Peter

I am having the same problem too. Here is my data and code

DataLink:
https://www.dropbox.com/s/q45t9hng4mryi6y/GTAP_CCShocks2.csv

Coding:
   # Loading the data
   climshocks <- read.csv(file = "F:/Purdue University/RA_Position/PhD_ResearchandDissert/PhD_Draft/GTAP-CGE/GTAP_NewAggDatabase/NewFiles/GTAP_CCShocks2.csv", header=TRUE, sep=",", na.string="NA", dec=".", strip.white=TRUE)

   # Data manipulations
   ccshocks <- as.data.frame(climshocks)
   ccshocks[4:4] <- sapply(ccshocks[4:4],as.numeric)
   ccshocks <- droplevels(ccshocks)
   ccshocks <- transform(ccshocks,region=factor(region,levels=unique(region)))

   library(reshape)
   library(ggplot2)
   library(grid)

   #--------------------------------------------------------------------------------
   #### Average of climate-induced yield percent change for all regions by crop
   #--------------------------------------------------------------------------------

   #_Code_Begin...
   Avgccshocks.f <- melt(ccshocks)
   Avgccshocks.f <- Avgccshocks.f[Avgccshocks.f$sres %in% c("AVERAGE"), ]

   PlotAvgccshocks <- ggplot(data = Avgccshocks.f, aes(factor(region), value))
   PlotAvgccshocks + geom_bar(stat="identity") + 
   theme(axis.text.x = element_text(colour = 'black', angle = 90, size = 14, hjust = 0.5, vjust = 0.5),axis.title.x=element_blank()) + 
   ylab("Yield(%change)") + theme(axis.text.y = element_text(colour = 'black', size = 14, hjust = 0.5, vjust = 0.5), axis.title.y = element_text(size = 14, hjust = 0.5, vjust = 0.5, face = 'bold')) + 
   theme(strip.text.x = element_text(size = 16, hjust = 0.5, vjust = 0.5, face = 'bold')) +
   facet_wrap(~crops, scales="free_y", ncol=3)
   ggsave("PlotAvgccshocks.png")

   #_Code_End...

Results: see image above

In addition to the warning message "1: Stacking not well defined when ymin != 0", I have two additional issues:

1) The order of x-axis labels is thrown off by one region, namely "SEAsia" which should come right after "EAsia" as I did order the data in the data.frame based on region. I suspect this is caused by the stacking error or is causing the error.

2) I am looking to add the x-axis labels below the two remaining columns of barplots. I know I could scales="free", but that would add labels under each panel which would make the plot jagged.

Any help would be greatly appreciated.

Thanks in advance

Ben Bond-Lamberty

unread,
Jan 25, 2013, 6:06:02 AM1/25/13
to ggplot2
> 1) The order of x-axis labels is thrown off by one region, namely "SEAsia"

This seems to be a problem in your data. You have a region "SEAsia" as
well as a region "SEASia".

> 2) I am looking to add the x-axis labels below the two remaining columns

Right, you have a prime number of panels so there isn't a good way to
do this. One option is scales="free"; another would be to print dummy
plots in the empty spots as described here:
https://groups.google.com/forum/?fromgroups=#!topic/ggplot2/i2gPycaqMFE

Ben
> --
> --
> 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
Reply all
Reply to author
Forward
0 new messages