lionel- / ggstance

Horizontal ggplot2 components

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: stat_summary with ggstance

eipi10 opened this issue · comments

It looks like you can't use stat_summary with ggstance (please correct me if I'm wrong about this). For example, say I want to use a different function to generate the values for a boxplot. Then I would use stat_summary to create the boxplot. But with geom=boxploth, this throws an error (see reproducible examples below). I'm guessing this is because fun.data returns y values, but ggstance is expecting them to be x values. If it's possible, it would be nice to be able to use stat_summary with ggstance geoms.

library(ggstance)

# Function to use boxplot.stats to set the box-and-whisker locations  
mybxp = function(x) {
  bxp = boxplot.stats(x)[["stats"]]
  names(bxp) = c("ymin","lower", "middle","upper","ymax")
  return(bxp)
}

# Works
ggplot(mtcars, aes(x=mpg, y=factor(cyl))) +
  geom_boxploth()

# Works
ggplot(mtcars, aes(x=factor(cyl), y=mpg)) +
  stat_summary(fun.data=mybxp, geom="boxplot")

# Error
ggplot(mtcars, aes(x=mpg, y=factor(cyl))) +
  stat_summary(fun.data=mybxp, geom="boxploth")

Error in $<-.data.frame(*tmp*, "xmin", value = numeric(0)) :
replacement has 0 rows, data has 27
In addition: Warning messages:
1: In min(x, na.rm = na.rm) :
no non-missing arguments to min; returning Inf
2: In max(x, na.rm = na.rm) :
no non-missing arguments to max; returning -Inf
3: In min(diff(sort(x))) : no non-missing arguments to min; returning Inf

Thanks Lionel!

no worries :)