teunbrand / ggh4x

ggplot extension: options for tailored facets, multiple colourscales and miscellaneous
https://teunbrand.github.io/ggh4x/
Other
542 stars 33 forks source link

ggh4x can not work #54

Closed shanwai1234 closed 2 years ago

shanwai1234 commented 2 years ago

Hi Developer,

I used the ggh4x package to generate the nested plot. I used a demo code from previous posted examples for ggh4x as below

library(ggh4x)
#> Loading required package: ggplot2
library(patchwork)

df <- iris
df$nester <- ifelse(df$Species == "setosa",
                    "Short Leaves",
                    "Long Leaves")

g <- ggplot(df, aes(Sepal.Length, Petal.Length)) +
  geom_point()
g1 <- g + facet_nested(nester + Species ~ .)
g2 <- g + facet_nested(~ nester + Species)

g1 + g2

However, I got an issue as

ERROR while rich displaying an object: Error: widths must be a unit object

Traceback:
1. FUN(X[[i]], ...)
2. tryCatch(withCallingHandlers({
 .     if (!mime %in% names(repr::mime2repr)) 
 .         stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
 .     rpr <- repr::mime2repr[[mime]](obj)
 .     if (is.null(rpr)) 
 .         return(NULL)
 .     prepare_content(is.raw(rpr), rpr)
 . }, error = error_handler), error = outer_handler)
3. tryCatchList(expr, classes, parentenv, handlers)
4. tryCatchOne(expr, names, parentenv, handlers[[1L]])
5. doTryCatch(return(expr), name, parentenv, handler)
6. withCallingHandlers({
 .     if (!mime %in% names(repr::mime2repr)) 
 .         stop("No repr_* for mimetype ", mime, " in repr::mime2repr")
 .     rpr <- repr::mime2repr[[mime]](obj)
 .     if (is.null(rpr)) 
 .         return(NULL)
 .     prepare_content(is.raw(rpr), rpr)
 . }, error = error_handler)
7. repr::mime2repr[[mime]](obj)
8. repr_text.default(obj)
9. paste(capture.output(print(obj)), collapse = "\n")
10. capture.output(print(obj))
11. evalVis(expr)
12. withVisible(eval(expr, pf))
13. eval(expr, pf)
14. eval(expr, pf)
15. print(obj)
16. print.patchwork(obj)
17. build_patchwork(plot, plot$layout$guides %||% "auto")
18. lapply(x$plots, plot_table, guides = guides)
19. FUN(X[[i]], ...)
20. plot_table.ggplot(X[[i]], ...)
21. ggplotGrob(x)
22. ggplot_gtable(ggplot_build(x))
23. ggplot_gtable.ggplot_built(ggplot_build(x))
24. layout$render(geom_grobs, data, theme, plot$labels)
25. f(..., self = self)
26. self$facet$draw_panels(panels, self$layout, self$panel_scales_x, 
  .     self$panel_scales_y, self$panel_params, self$coord, data, 
  .     theme, self$facet_params)
27. f(..., self = self)
28. strip$setup(layout, params, theme, type = "grid")
29. f(..., self = self)
30. self$get_strips(x = structure(col_vars, type = "cols"), y = structure(row_vars, 
  .     type = "rows"), params$labeller, theme, params = self$params, 
  .     layout_x = layout_x, layout_y = layout_y)
31. f(..., self = self)
32. self$build_strip(y, labeller, theme, FALSE, params, layout_y)
33. f(..., self = self)
34. self$assemble_strip(labels, "left", elem, params, layout)
35. f(..., self = self)
36. self$finish_strip(unname(strips), width, height, position, layout, 
  .     dim = c(nrow(layout), nlayers), params$clip)
37. f(...)
38. gtable(widths = width, height = height[1])
39. stop("widths must be a unit object", call. = FALSE)

Do you have any suggestions? Thank you!

Zhikai

shanwai1234 commented 2 years ago

it seems due to the version of ggh4x. I have fixed it.

teunbrand commented 2 years ago

Hi there,

Thanks for reporting the issue. It sounds very similar as issue #49 and there is a suggestion here if you'd like to run the most recent version on R3.6.

Best wishes, Teun