ProjectMOSAIC / ggformula

Provides a formula interface to 'ggplot2' graphics.
Other
39 stars 11 forks source link

Strange behavior with color in gf_dist #171

Closed lahvak closed 6 months ago

lahvak commented 6 months ago

I am seeing a strange error when I try to use color in gf_dist:

This works fine:

gf_dist("norm", color="red")

as does this:

gf_dist("norm", params = c(mean = 2, sd = 1))

However, this:

gf_dist("norm", params = c(mean = 2, sd = 1), color="red")

gives this error:

Error in dots_for_lines[["size"]] <- NULL : subscript out of bounds

If I add a nonsensical parameter size, it works again:

gf_dist("norm", params = c(mean = 2, sd = 1), color="red", size = 20)

I know that year ago this worked fine, I suspect it has something to do with the renaming of things in ggplot2.

rpruim commented 6 months ago

This is actually related to a response to the change in ggplot2. I've fixed this in github by first checking that "size" is a name before trying to remove that element of the list. (See # 4a6b01bed3fd14c0b160d830d8510d26d232bb32). It's unclear to me why

dots_for_lines[["size"]] <- NULL

fails here, since

x <- list(1, 2, a = 3, b = 4)
x
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 2
#> 
#> $a
#> [1] 3
#> 
#> $b
#> [1] 4
x[["size"]] <- NULL
x
#> [[1]]
#> [1] 1
#> 
#> [[2]]
#> [1] 2
#> 
#> $a
#> [1] 3
#> 
#> $b
#> [1] 4

Created on 2024-03-27 with reprex v2.0.2

rpruim commented 6 months ago

Also note that the use of params is optional.

ggformula::gf_dist("norm", mean = 2, sd = 1, color="red", linewidth = 5)

Created on 2024-03-27 with reprex v2.0.2