easystats / see

:art: Visualisation toolbox for beautiful and publication-ready figures
https://easystats.github.io/see/
Other
890 stars 43 forks source link

plot fails for rope/hdi? #20

Closed strengejacke closed 5 years ago

strengejacke commented 5 years ago

Not sure why this now happens, but when I run

library(rstanarm)
library(bayestestR)

model <- rstanarm::stan_glm(Sepal.Length ~ Petal.Width * Species, data = iris)
result <- rope(model, ci = c(0.9, 0.95))

plot(result, data = model, rope_color = "red") +
  theme_modern()

I get an error:

Error: Discrete value supplied to continuous scale

The y-value for the plot-data is not numeric, but "Posterior". I think the source of the error is somewhere here: https://github.com/easystats/see/blob/master/R/plot.hdi.R#L10

@DominiqueMakowski any ideas?

DominiqueMakowski commented 5 years ago

very curious, the error happens in plot.see_rope:

x %>%
    as.data.frame() %>%
    ggplot(aes(
      x = .data$x,
      y = .data$y,
      height = .data$height,
      group = .data$y,
      fill = .data$fill
    )) +
    ggridges::geom_ridgeline_gradient() +
    annotate(
      "rect",
      xmin = attributes(x)$info$rope_range[1],
      xmax = attributes(x)$info$rope_range[2],
      ymin = 0,
      ymax = Inf,
      fill = rope_color,
      alpha = rope_alpha
    ) +
    add_plot_attributes(x)

Basically, the error appears if we swap the annotation layer with the geom_ridgeline_gradient... (I wanted to put the rectangle behind the data as you mentioned)

strengejacke commented 5 years ago

ok, let's revert the change and put the rectangle above the data.

DominiqueMakowski commented 5 years ago

Yes I did it, but still though, that's weird!