Skip to content

Error : Computation failed in stat_bin(): binwidth must be positive  #3043

@rajkstats

Description

@rajkstats

This might be related to a previous issue:
#2312

I am using the function below to create multiple histograms in one plot. It seems that features with zero variance / one value are not getting plotted. It was working with previous version of ggplot2. Please help me in fixing this.

plot_hist_facet <- function(data, bins = 10, ncol = 5,
fct_reorder = FALSE, fct_rev = FALSE,
fill = palette_light()[[3]],
color = "white", scale = "free") {

data_factored <- data %>%
mutate_if(is.character, as.factor) %>%
mutate_if(is.factor, as.numeric) %>%
gather(key = key, value = value, factor_key = TRUE)

if(fct_reorder) {
data_factored <- data_factored %>%
mutate(key = as.character(key) %>% as.factor())
}

if(fct_rev){
data_factored <- data_factored %>%
mutate(key = fct_rev(key))
}

g <- data_factored %>%
ggplot(aes(x = value, group = key )) +
geom_histogram(bins = bins, fill = fill , color = color,
) +
facet_wrap(~ key, ncol = ncol, scale = scale) +
theme_tq()

return(g)

}

Getting Computation failed in stat_bin(): binwidth must be positive error
snip20181221_20

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions