rggplot2

Error message in when running functions from ggside package


I am getting an error when I run the ggside package with any plot. This is from the package vignette (so it should work)

i2 <- iris %>%
  mutate(Species2 = rep(c("A","B"), 75))
p <- ggplot(i2, aes(Sepal.Width, Sepal.Length, color = Species)) +
  geom_point()
p2 <- p + geom_xsidedensity(aes(y = after_stat(density))) +
  geom_ysidedensity(aes(x = after_stat(density))) +
  theme_bw() 

p2

Returns the error.

Error in `geom_xsidedensity()`:
! Problem while computing aesthetics.
ℹ Error occurred in the 2nd layer.
Caused by error in `scales_add_defaults()`:
! could not find function "scales_add_defaults"

Has anyone encountered this and knows what to do?


Solution

  • Ensure you have both ggplot2 and ggside

    install.packages("ggplot2")
    install.packages("ggside")
    

    Ensure you have the scales package:

    install.packages("scales")
    

    Then, try running the vignette code again. Hope it works!