Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need range01 function #8

Closed
dicook opened this issue Sep 19, 2022 · 3 comments · Fixed by #13
Closed

Need range01 function #8

dicook opened this issue Sep 19, 2022 · 3 comments · Fixed by #13

Comments

@dicook
Copy link
Collaborator

dicook commented Sep 19, 2022

In converting from

temp.gly <- glyphs(nasa, "long", "day", "lat",
                   "ozone", height=2.5, 
                   y_scale = range01, polar = TRUE)
ggplot(temp.gly, ggplot2::aes(gx, gy, group = gid)) +
  geom_polygon(data=sth_america, 
            aes(x=long, y=lat, group=group), 
            fill="grey70") +
  add_ref_lines(temp.gly, color = "grey90") +
  add_ref_boxes(temp.gly, color = "grey90") +
  geom_path() +
  labs(x = "", y = "") +
  coord_map() +
  theme_map()  

to

ggplot() +
  geom_polygon(data=sth_america, 
           aes(x=long, y=lat, group=group), 
          fill="#014221", alpha=0.5, colour="#ffffff") +
  geom_glyph_box(data=nasa, aes(x_major = long, x_minor = day,
            y_major = lat, y_minor = ozone), fill=NA) +
  geom_glyph_line(data=nasa, aes(x_major = long, x_minor = day,
            y_major = lat, y_minor = ozone)) +
  geom_glyph(data=nasa, aes(x_major = long, x_minor = day,
            y_major = lat, y_minor = ozone), 
            y_scale = range01, polar = TRUE) +
  theme_map()

will throw an error. cubble is missing the range01 function, that will scale each spatial location data to range between 0 and 1, necessary to make polar glyphs with local scale.

@dicook
Copy link
Collaborator Author

dicook commented Sep 19, 2022

Oh, it is because there is a computing problem, not that it is missing:

Error in `dplyr::mutate()`:
! Problem while computing `y_minor =
  rlang::exec(unique(params$y_scale), .data$y_minor)`.
ℹ The error occurred in group 1: group = -113.8.-21.2.
Caused by error in `unique.default()`:
! unique() applies only to vectors
Run `rlang::last_error()` to see where the error occurred.

@huizezhang-sherry
Copy link
Owner

x/y_scale needs to be specified as a string rather than a function. Would be worthwhile to document it in the @param:

library(cubble)
library(ggplot2)
range01 <- GGally::range01
#> Registered S3 method overwritten by 'GGally':
#>   method from   
#>   +.gg   ggplot2
GGally::nasa %>%
  ggplot(aes(x_major = long, x_minor = day,
             y_major = lat, y_minor = ozone)) +
  geom_glyph_box(fill=NA) +
  geom_glyph_line() +
  geom_glyph(y_scale = "range01", polar = TRUE) +
  ggthemes::theme_map()

Created on 2022-09-23 by the reprex package (v2.0.1)

@schloerke
Copy link
Contributor

This needs to be a change within {cubble} to support functions directly.
Strings should not be documented that they are supported.

Broken example

local({
  library(GGally)
  library(cubble)
  my_custom_function <- GGally::range01
  p <- ggplot(data = GGally::nasa,
        aes(x_major = long, x_minor = day,
            y_major = lat, y_minor = surftemp)) +
    geom_glyph_box() +
    geom_glyph_line() +
    geom_glyph(y_scale = "my_custom_function") +
    theme_bw()
  print(p)
})
#> Error in `dplyr::mutate()`:
#> ℹ In argument: `y_minor = rlang::exec(unique(params$y_scale), .data$y_minor)`.
#> ℹ In group 1: `group = -113.8.-21.2`.
#> Caused by error in `my_custom_function()`:
#> ! could not find function "my_custom_function"
#> Run `rlang::last_error()` to see where the error occurred.

Fixing this would also allow removal of all quosures from ggobi/ggally#433


I'll have a PR and fixes to ggobi/ggally#433 shortly

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants