GithubHelp home page GithubHelp logo

ggblend's People

Contributors

mjskay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

vineetp6

ggblend's Issues

Release ggblend 0.1.0

First release:

Prepare for release:

  • usethis::use_version('minor')
  • git pull
  • Check if any deprecation processes should be advanced, as described in Gradual deprecation
  • urlchecker::url_check()
  • spelling::spell_check_package()
  • devtools::build_readme()
  • devtools::check(remote = TRUE, manual = TRUE)
  • devtools::check_win_devel()
  • rhub::check_for_cran()
  • git push
  • Draft blog post

Submit to CRAN:

  • devtools::release()
  • Approve email

Wait for CRAN...

  • Accepted ๐ŸŽ‰
  • put [![CRAN status](https://www.r-pkg.org/badges/version/ggblend)](https://CRAN.R-project.org/package=ggblend) back into readme
  • merge dev onto main and cran.
  • usethis::use_github_release()
  • create zenodo release and add it to citation info
  • usethis::use_dev_version()
  • usethis::use_news_md()
  • git push
  • add to ggplot extensions archive
  • Tweet

Document graphics device setup

Would be helpful to folks to have somewhere to point folks to help them configure a graphics device that supports blending. Maybe a mini vignette.

  • a list of (currently) viable graphics devices
  • how to configure them to support blending in common setups (script, rmarkdown, rstudio, ... maybe pkgdown?)
  • pointer to Paul Murrell's article
  • update the check_blend(), check_affine_transform() warning messages to point to the mini-vignette.
  • update the README to point to the mini-vignette.

Make sure ggblend works with ggrastr

Will probably have to investigate ggrastr internals for this. These two plots should be different but aren't:

library(ggplot2)
library(ggblend)
library(ggrastr)

diamonds |>
  ggplot() + 
  geom_point(aes(carat, price, colour = cut)) |> rasterize(dpi = 30)

image

diamonds |>
  ggplot() + 
  geom_point(aes(carat, price, colour = cut)) |> blend("multiply") |> rasterize(dpi = 30)

image

Second one should look like this:

diamonds |>
  ggplot() + 
  geom_point(aes(carat, price, colour = cut)) |> blend("multiply")

image

Warning: blend = "darken" does not appear to be supported by your graphics device.

Great package idea, thank you!

I tried one of the examples you provided and I got the below warning & plot.

library(ggplot2)
library(ggblend)

set.seed(1234)
df_a = data.frame(x = rnorm(500, 0), y = rnorm(500, 1), set = "a")
df_b = data.frame(x = rnorm(500, 1), y = rnorm(500, 2), set = "b")

df_ab = rbind(df_a, df_b) |>
  transform(order = "draw a then b")

df_ba = rbind(df_b, df_a) |>
  transform(order = "draw b then a")

df = rbind(df_ab, df_ba)

df |>
  ggplot(aes(x, y, color = set)) +
  geom_point(size = 3) |> blend("darken") +
  scale_color_brewer(palette = "Set2") +
  facet_grid(~ order) +
  ggtitle("Scatterplot with blend('darken'): draw order does not matter")
#> Warning: blend = "darken" does not appear to be supported by your graphics device.
#>  - Blending output may not be as expected.
#>  - If your current graphics device *does* support blend = "darken"
#>    but auto-detection failed, consider reporting a bug.
#> Warning in drawDetails.GridGroup(x, recording = FALSE): Group definition failed

#> Warning in drawDetails.GridGroup(x, recording = FALSE): Group definition failed

Created on 2022-05-06 by the reprex package (v2.0.1)

Session info
sessioninfo::session_info()
#> โ”€ Session info โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
#>  setting  value
#>  version  R version 4.2.0 (2022-04-22)
#>  os       macOS Big Sur/Monterey 10.16
#>  system   x86_64, darwin17.0
#>  ui       X11
#>  language (EN)
#>  collate  en_CA.UTF-8
#>  ctype    en_CA.UTF-8
#>  tz       America/Toronto
#>  date     2022-05-06
#>  pandoc   2.17.1.1 @ /Applications/RStudio.app/Contents/MacOS/quarto/bin/ (via rmarkdown)
#> 
#> โ”€ Packages โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
#>  package      * version    date (UTC) lib source
#>  assertthat     0.2.1      2019-03-21 [1] CRAN (R 4.2.0)
#>  cli            3.3.0      2022-04-25 [1] CRAN (R 4.2.0)
#>  colorspace     2.0-3      2022-02-21 [1] CRAN (R 4.2.0)
#>  crayon         1.5.1      2022-03-26 [1] CRAN (R 4.2.0)
#>  curl           4.3.2      2021-06-23 [1] CRAN (R 4.2.0)
#>  DBI            1.1.2      2021-12-20 [1] CRAN (R 4.2.0)
#>  digest         0.6.29     2021-12-01 [1] CRAN (R 4.2.0)
#>  dplyr          1.0.8      2022-02-08 [1] CRAN (R 4.2.0)
#>  ellipsis       0.3.2      2021-04-29 [1] CRAN (R 4.2.0)
#>  evaluate       0.15       2022-02-18 [1] CRAN (R 4.2.0)
#>  fansi          1.0.3      2022-03-24 [1] CRAN (R 4.2.0)
#>  farver         2.1.0      2021-02-28 [1] CRAN (R 4.2.0)
#>  fastmap        1.1.0      2021-01-25 [1] CRAN (R 4.2.0)
#>  fs             1.5.2      2021-12-08 [1] CRAN (R 4.2.0)
#>  generics       0.1.2      2022-01-31 [1] CRAN (R 4.2.0)
#>  ggblend      * 0.0.0.9000 2022-05-06 [1] Github (mjskay/ggblend@c09c183)
#>  ggplot2      * 3.3.6      2022-05-03 [1] CRAN (R 4.2.0)
#>  glue           1.6.2      2022-02-24 [1] CRAN (R 4.2.0)
#>  gtable         0.3.0      2019-03-25 [1] CRAN (R 4.2.0)
#>  highr          0.9        2021-04-16 [1] CRAN (R 4.2.0)
#>  htmltools      0.5.2      2021-08-25 [1] CRAN (R 4.2.0)
#>  httr           1.4.2      2020-07-20 [1] CRAN (R 4.2.0)
#>  knitr          1.39       2022-04-26 [1] CRAN (R 4.2.0)
#>  labeling       0.4.2      2020-10-20 [1] CRAN (R 4.2.0)
#>  lifecycle      1.0.1      2021-09-24 [1] CRAN (R 4.2.0)
#>  magrittr       2.0.3      2022-03-30 [1] CRAN (R 4.2.0)
#>  mime           0.12       2021-09-28 [1] CRAN (R 4.2.0)
#>  munsell        0.5.0      2018-06-12 [1] CRAN (R 4.2.0)
#>  pillar         1.7.0      2022-02-01 [1] CRAN (R 4.2.0)
#>  pkgconfig      2.0.3      2019-09-22 [1] CRAN (R 4.2.0)
#>  purrr          0.3.4      2020-04-17 [1] CRAN (R 4.2.0)
#>  R.cache        0.15.0     2021-04-30 [1] CRAN (R 4.2.0)
#>  R.methodsS3    1.8.1      2020-08-26 [1] CRAN (R 4.2.0)
#>  R.oo           1.24.0     2020-08-26 [1] CRAN (R 4.2.0)
#>  R.utils        2.11.0     2021-09-26 [1] CRAN (R 4.2.0)
#>  R6             2.5.1      2021-08-19 [1] CRAN (R 4.2.0)
#>  RColorBrewer   1.1-3      2022-04-03 [1] CRAN (R 4.2.0)
#>  reprex         2.0.1      2021-08-05 [1] CRAN (R 4.2.0)
#>  rlang          1.0.2      2022-03-04 [1] CRAN (R 4.2.0)
#>  rmarkdown      2.14       2022-04-25 [1] CRAN (R 4.2.0)
#>  rstudioapi     0.13       2020-11-12 [1] CRAN (R 4.2.0)
#>  scales         1.2.0      2022-04-13 [1] CRAN (R 4.2.0)
#>  sessioninfo    1.2.2      2021-12-06 [1] CRAN (R 4.2.0)
#>  stringi        1.7.6      2021-11-29 [1] CRAN (R 4.2.0)
#>  stringr        1.4.0      2019-02-10 [1] CRAN (R 4.2.0)
#>  styler         1.7.0      2022-03-13 [1] CRAN (R 4.2.0)
#>  tibble         3.1.7      2022-05-03 [1] CRAN (R 4.2.0)
#>  tidyselect     1.1.2      2022-02-21 [1] CRAN (R 4.2.0)
#>  utf8           1.2.2      2021-07-24 [1] CRAN (R 4.2.0)
#>  vctrs          0.4.1      2022-04-13 [1] CRAN (R 4.2.0)
#>  withr          2.5.0      2022-03-03 [1] CRAN (R 4.2.0)
#>  xfun           0.30       2022-03-02 [1] CRAN (R 4.2.0)
#>  xml2           1.3.3      2021-11-30 [1] CRAN (R 4.2.0)
#>  yaml           2.3.5      2022-02-21 [1] CRAN (R 4.2.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.2/Resources/library
#> 
#> โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

vector algebra form

More musings: maybe this really needs to turn into more of a vector algebra... e.g. vectors of layers. Because what you really want to be able to do for something like this is have two layers: the densities and the lines, add densities to [0, lines] and do blend("clear") on the second element (so maybe something like densities + c(0, lines) |> c(1, blend("clear"))...

geom_sf() error: Cannot provide both the `object` and `blend` arguments to `blend()` simultaneously.

I'm trying to use ggblend with relayer and sf to create a choropleth with a "combined" 2D color scale, where one variable is shaded from white to red, the other from white to blue, and locations high in both will be purple. In the MWE below, the scatterplot using ggblend and relayer works as expected, with the two color scales combining nicely; as does a single-color choropleth that doesn't use either ggblend or relayer. The map I'd like to construct throws the error Cannot provide both the objectandblendarguments toblend() simultaneously. The final map includes ggblend without relayer, and produces the same error, suggesting that the issue it with ggblend.

library(tidyverse)
theme_set(theme_light())
library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(ggblend)
library(relayer)
#> Note: The package "relayer" is highly experimental. Use at your own risk.

demo(nc, ask = FALSE, echo = FALSE)

## Scatterplot with combined color scales: works as expected
ggplot(nc, aes(BIR74, SID74)) +
    list(
        geom_point(aes(color = BIR74)), 
        geom_point(aes(col2 = SID74)) |> 
            rename_geom_aes(new_aes = c('color' = 'col2'))
    ) |> 
    blend('multiply') +
    scale_color_gradient(low = 'white', high = 'blue',
                         aesthetics = 'color',
                         guide = 'none') +
    scale_color_gradient(low = 'white', high = 'red',
                         aesthetics = 'col2',
                         guide = 'none')
#> Warning in geom_point(aes(col2 = SID74)): Ignoring unknown aesthetics: col2

## sf map with a single color scale: works as expected
ggplot(nc) +
    geom_sf(aes(fill = BIR74)) +
    scale_color_gradient(low = 'white', high = 'blue',
                         aesthetics = 'fill',
                         guide = 'none')

## sf map with two color scales: 
## Error: Cannot provide both the `object` and `blend` arguments to `blend()` simultaneously.
ggplot(nc) +
    list(geom_sf(aes(fill = BIR74)),
         geom_sf(aes(fill2 = SID74)) |> 
             rename_geom_aes(new_aes = c('fill' = 'fill2'))) |> 
    blend('multiply') |> 
    scale_color_gradient(low = 'white', high = 'blue',
                         aesthetics = 'fill',
                         guide = 'none') +
    scale_color_gradient(low = 'white', high = 'red',
                         aesthetics = 'fill2',
                         guide = 'none')
#> Warning in layer_sf(geom = GeomSf, data = data, mapping = mapping, stat = stat,
#> : Ignoring unknown aesthetics: fill2
#> Error: Cannot provide both the `object` and `blend` arguments to `blend()` simultaneously.

## Taking relayer out of the picture doesn't remove the error
ggplot(nc) +
    list(geom_sf(aes(fill = BIR74))) |> 
    blend('multiply') |> 
    scale_color_gradient(low = 'white', high = 'blue',
                         aesthetics = 'fill',
                         guide = 'none')
#> Error: Cannot provide both the `object` and `blend` arguments to `blend()` simultaneously.

Created on 2023-05-17 with reprex v2.0.2

Session info
sessioninfo::session_info()
#> โ”€ Session info โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
#>  setting  value
#>  version  R version 4.3.0 (2023-04-21)
#>  os       macOS Big Sur 11.7.6
#>  system   x86_64, darwin20
#>  ui       X11
#>  language (EN)
#>  collate  en_US.UTF-8
#>  ctype    en_US.UTF-8
#>  tz       America/Los_Angeles
#>  date     2023-05-17
#>  pandoc   2.19.2 @ /Applications/RStudio.app/Contents/Resources/app/quarto/bin/tools/ (via rmarkdown)
#> 
#> โ”€ Packages โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
#>  package     * version    date (UTC) lib source
#>  class         7.3-21     2023-01-23 [1] CRAN (R 4.3.0)
#>  classInt      0.4-9      2023-02-28 [1] CRAN (R 4.3.0)
#>  cli           3.6.1      2023-03-23 [1] CRAN (R 4.3.0)
#>  colorspace    2.1-0      2023-01-23 [1] CRAN (R 4.3.0)
#>  curl          5.0.0      2023-01-12 [1] CRAN (R 4.3.0)
#>  DBI           1.1.3      2022-06-18 [1] CRAN (R 4.3.0)
#>  digest        0.6.31     2022-12-11 [1] CRAN (R 4.3.0)
#>  dplyr       * 1.1.2      2023-04-20 [1] CRAN (R 4.3.0)
#>  e1071         1.7-13     2023-02-01 [1] CRAN (R 4.3.0)
#>  evaluate      0.21       2023-05-05 [1] CRAN (R 4.3.0)
#>  fansi         1.0.4      2023-01-22 [1] CRAN (R 4.3.0)
#>  farver        2.1.1      2022-07-06 [1] CRAN (R 4.3.0)
#>  fastmap       1.1.1      2023-02-24 [1] CRAN (R 4.3.0)
#>  forcats     * 1.0.0      2023-01-29 [1] CRAN (R 4.3.0)
#>  fs            1.6.2      2023-04-25 [1] CRAN (R 4.3.0)
#>  generics      0.1.3      2022-07-05 [1] CRAN (R 4.3.0)
#>  ggblend     * 0.0.0.9000 2023-05-17 [1] Github (mjskay/ggblend@7475e8e)
#>  ggplot2     * 3.4.2      2023-04-03 [1] CRAN (R 4.3.0)
#>  glue          1.6.2      2022-02-24 [1] CRAN (R 4.3.0)
#>  gtable        0.3.3      2023-03-21 [1] CRAN (R 4.3.0)
#>  highr         0.10       2022-12-22 [1] CRAN (R 4.3.0)
#>  hms           1.1.3      2023-03-21 [1] CRAN (R 4.3.0)
#>  htmltools     0.5.5      2023-03-23 [1] CRAN (R 4.3.0)
#>  httr          1.4.6      2023-05-08 [1] CRAN (R 4.3.0)
#>  KernSmooth    2.23-20    2021-05-03 [1] CRAN (R 4.3.0)
#>  knitr         1.42       2023-01-25 [1] CRAN (R 4.3.0)
#>  labeling      0.4.2      2020-10-20 [1] CRAN (R 4.3.0)
#>  lifecycle     1.0.3      2022-10-07 [1] CRAN (R 4.3.0)
#>  lubridate   * 1.9.2      2023-02-10 [1] CRAN (R 4.3.0)
#>  magrittr      2.0.3      2022-03-30 [1] CRAN (R 4.3.0)
#>  mime          0.12       2021-09-28 [1] CRAN (R 4.3.0)
#>  munsell       0.5.0      2018-06-12 [1] CRAN (R 4.3.0)
#>  pillar        1.9.0      2023-03-22 [1] CRAN (R 4.3.0)
#>  pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 4.3.0)
#>  plyr          1.8.8      2022-11-11 [1] CRAN (R 4.3.0)
#>  proxy         0.4-27     2022-06-09 [1] CRAN (R 4.3.0)
#>  purrr       * 1.0.1      2023-01-10 [1] CRAN (R 4.3.0)
#>  R6            2.5.1      2021-08-19 [1] CRAN (R 4.3.0)
#>  Rcpp          1.0.10     2023-01-22 [1] CRAN (R 4.3.0)
#>  readr       * 2.1.4      2023-02-10 [1] CRAN (R 4.3.0)
#>  relayer     * 0.1.0      2023-05-17 [1] Github (clauswilke/relayer@8a1d49e)
#>  reprex        2.0.2      2022-08-17 [1] CRAN (R 4.3.0)
#>  rlang         1.1.1      2023-04-28 [1] CRAN (R 4.3.0)
#>  rmarkdown     2.21       2023-03-26 [1] CRAN (R 4.3.0)
#>  rstudioapi    0.14       2022-08-22 [1] CRAN (R 4.3.0)
#>  scales        1.2.1      2022-08-20 [1] CRAN (R 4.3.0)
#>  sessioninfo   1.2.2      2021-12-06 [1] CRAN (R 4.3.0)
#>  sf          * 1.0-12     2023-03-19 [1] CRAN (R 4.3.0)
#>  stringi       1.7.12     2023-01-11 [1] CRAN (R 4.3.0)
#>  stringr     * 1.5.0      2022-12-02 [1] CRAN (R 4.3.0)
#>  tibble      * 3.2.1      2023-03-20 [1] CRAN (R 4.3.0)
#>  tidyr       * 1.3.0      2023-01-24 [1] CRAN (R 4.3.0)
#>  tidyselect    1.2.0      2022-10-10 [1] CRAN (R 4.3.0)
#>  tidyverse   * 2.0.0      2023-02-22 [1] CRAN (R 4.3.0)
#>  timechange    0.2.0      2023-01-11 [1] CRAN (R 4.3.0)
#>  tzdb          0.4.0      2023-05-12 [1] CRAN (R 4.3.0)
#>  units         0.8-2      2023-04-27 [1] CRAN (R 4.3.0)
#>  utf8          1.2.3      2023-01-31 [1] CRAN (R 4.3.0)
#>  vctrs         0.6.2      2023-04-19 [1] CRAN (R 4.3.0)
#>  withr         2.5.0      2022-03-03 [1] CRAN (R 4.3.0)
#>  xfun          0.39       2023-04-20 [1] CRAN (R 4.3.0)
#>  xml2          1.3.4      2023-04-27 [1] CRAN (R 4.3.0)
#>  yaml          2.3.7      2023-01-23 [1] CRAN (R 4.3.0)
#> 
#>  [1] /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library
#> 
#> โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

Blend option for ggplot color aes

First of all, thank you for this great package. I am currently working in single-cell transcriptomics, and often plotting a UMAP representation of cells along with the expression of two (or more) genes can be a problem, as one can mask the other and make it seem like the expression of one gene is higher than the other simply because of the order in which they were plotted -- As noted in your documentation, draw order matters.

I was wondering if it's possible to use this tool to merge ggplots in which 2 aes colours have been used. For example:

ggplot1 <- ggplot(df, aes(x = coord_x, y = coord_y, color = var1) + geom_point() +
scale_color_continuous(low = "blue", high = "black")
ggplot2 <- ggplot(df, aes(x = coord_x, y = coord_y, color = var2) + geom_point() +
scale_color_continuous(low = "yellow", high = "red")

Where df contains 4 columns with the continuous variables: coord_x, coord_y, var1, var2. Thanks in advance!

  • Ana C.

Please adopt a specific open source LICENSE

What a great package! Thanks for publishing it here.

However, right now the LICENSE file in this repository only lists the copyright year and authors, and is not a license. Please follow these easy instructions in GitHub's documentation to choose and apply a proper open source license for this package, such as the GNU GPLv3. Otherwise, other people won't be allowed to study, share, and build on the code.

If it helps, I'm happy to submit a pull request with the needed changes.

Could anyone, please, confirm this warning?

I'm using R 4.2. I'm having the following warning

Warning messages:
1: blend = "darken" does not appear to be supported by your graphics device.
 - Blending output may not be as expected.
 - If your current graphics device *does* support blend = "darken"
   but auto-detection failed, consider reporting a bug. 
2: In drawDetails.GridGroup(x, recording = FALSE) :
  Group definition failed

Demo of alpha blending

A few of the responses to your tweet announcement asked about alpha blending. It's probably worth having some sort of demo showing why alpha blending isn't always reliable or consistent.

library(tidyverse)

tibble(
  x = 1:10,
  alpha = x / 10
) %>% 
ggplot() +
  aes(x=x, y=y, alpha=alpha) +
  annotate("text", x=-6, size=10, hjust=0, vjust=0.5, label="Alpha blending is order dependent", y=12) +
  
  annotate("point", x=-6, y=11, alpha=0) + # spacer
  geom_point(size=10, shape=16, color="#E41A1C", y=10) +
  annotate("text", x=-1, size=10, hjust=1, vjust=0.5, alpha=0.5, label="No background", y=10) +
  
  annotate("tile", x=5.5, width=11, height=1.8, fill="#377EB8", alpha=0.5, y=8) +
  geom_point(size=10, shape=16, color="#E41A1C", y=8) +
  annotate("text", x=-1, size=10, hjust=1, vjust=0.5, alpha=0.5, label="Tile then points", y=8) +
  
  geom_point(size=10, shape=16, color="#E41A1C", y=6) +
  annotate("tile", x=5.5, width=11, height=1.8, fill="#377EB8", alpha=0.5, y=6) +
  annotate("text", x=-1, size=10, hjust=1, vjust=0.5, alpha=0.5, label="Points then tile", y=6) +
  
  guides(alpha = 'none') +
  theme_void()

image

Adjustment operation

Another good use case for a layer algebra: putting a white line behind a line geom for clarity.

Might be done using the distributive law and an operation for adjusting layer parameters, maybe like this:

geom_line() * (adjust(color = "white", size = 2) + clone())

or

geom_line() * (adjust(color = "white", size = 2) + adjust())

There is now a basic implementation of this.

certain blend operations cannot be applied to > 2 grobs simultaneously

Certain blend ops (e.g. "atop") can only be applied to pairs of grobs using grid::groupGrob(src, op, dst) instead of grid::groupGrob(src, op) where src is (say) a grobTree or some other collection of grobs.

Need to fix blend() so that it is compatible with these binary-only ops to allow using ops like "atop". One option is to maintain a table of ops known to be compatible with > 2 grob blending and fall back to a Reduce() for the other ops (since that should definitely work but will be slower).

More syntax thoughts: blend_group aes or split_layer operator?

Thinking more about how the syntax is evolving into something more algebraic... The use of layer_set * (blend1 + blend2) is nice because it follows the distributive law: it's equivalent to layer_set * blend1 + layer_set * blend2 (here layer_set might be a geom or a list of geoms, and blend1 / blend2 calls to blend()).

Currently there's syntax like this:

ggplot(aes(blend_group = some_column)) + geom_X() * blend(...)

which splits the data in geom_X() along levels of some_column and then blends those together. This breaks the "algebraic" approach. But blend already operates on layer sets, so an alternative might be a function or operator that splits (or acts like it splits) a geom into a set of layers. Something like:

  • geom_X() * split_layer(col1, col2, ...) * blend(...)
  • geom_X() * split_on(col1, col2, ...) * blend(...)
  • geom_X() * condition_on(col1, col2, ...) * blend(...)
  • (geom_X() | columns(col1, col2, ...)) * blend(...)
  • geom_X() / columns(col1, col2, ...) * blend(...)
  • geom_X() / variables(col1, col2, ...) * blend(...)

(though "columns" is a bit of a misnomer since these can be any variable expression on the right-hand side of an aes(...) subexpression)

Where the result of geom_X() * split_layer(col1, col2, ...) * blend(...) is a layer set (or something that behaves like one), so the semantics of blend(...) when a blend_group is present are now no longer a special case, but just another application of a blend to a layer set.

This also raises the possibility to think of split_layer() and blend() as two more general operators in an algebra for manipulating ggplot layers. There are some other bits of functionality in that direction (around modifying existing layers in a plot) I've been thinking about that maybe could fit in that broader version of this package.

Save figures with ggsave

Hi mjskay,

I would like to save the plots made with ggplot and ggblend.

When I use ggsave for my plot (geom_point), I don't have the points and just the grid.
My warnings
blend = "darken" does not appear to be supported by your graphics device.

  • Blending output may not be as expected.
  • If your current graphics device does support blend = "darken"
    but auto-detection failed, consider reporting a bug.

and

In drawDetails.GridGroup(x, recording = FALSE) : Group definition failed

I already had a display problem in Rstudio (MacOS) but this works after putting the backend of my graphic device in cairo.

test

Can you tell me how to properly save my plot please?

Best regards

Christophe

caught segfault - address (nil), cause 'memory not mapped' when using blend

I was trying the package using DEMO
First normal ggplot without blend function works and plot fine,
but the segmentation fault Error shows up when I start using the blend function

df |>
  ggplot(aes(x, y, color = set)) +
  geom_point(size = 3) |> blend("darken") +
  scale_color_brewer(palette = "Set2") +
  facet_grid(~ order) +
  ggtitle("Scatterplot with blend('darken'): draw order does not matter")

this can be saved as p fine. but the error shows up again when trying to print the ggplot.

Error:

 *** caught segfault ***
address (nil), cause 'memory not mapped'

Traceback:
 1: .defineGroup(grp$src, grp$op, grp$dst)
 2: drawDetails.GridGroup(x, recording = FALSE)
 3: drawDetails(x, recording = FALSE)
 4: drawGTree(x)
 5: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
 6: grid.draw.gTree(x$children[[i]], recording = FALSE)
 7: grid.draw(x$children[[i]], recording = FALSE)
 8: drawGTree(x)
 9: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
10: grid.draw.gTree(x$children[[i]], recording = FALSE)
11: grid.draw(x$children[[i]], recording = FALSE)
12: drawGTree(x)
13: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
14: grid.draw.gTree(x$children[[i]], recording = FALSE)
15: grid.draw(x$children[[i]], recording = FALSE)
16: drawGTree(x)
17: recordGraphics(drawGTree(x), list(x = x), getNamespace("grid"))
18: grid.draw.gTree(gtable)
19: grid.draw(gtable)
20: print.ggplot(x)
21: (function (x, ...) UseMethod("print"))(x)

Possible actions:
1: abort (with core dump, if enabled)
2: normal R exit
3: exit R without saving workspace
4: exit R saving workspace
Selection: 

I have been using new conda environment with either 4.2.0 and 4.2.2 but the error persist.
Here's the sessionInfo using 4.2.0 version of R.

Would love to hear if anyone encounter this and/or have solution. Thanks!

sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: x86_64-conda-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: {SomePath}/miniconda3/envs/ggblend/lib/libopenblasp-r0.3.21.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] ggblend_0.0.0.9000 ggplot2_3.4.0     

loaded via a namespace (and not attached):
 [1] fansi_1.0.3      withr_2.5.0      dplyr_1.0.10     utf8_1.2.2      
 [5] grid_4.2.0       R6_2.5.1         lifecycle_1.0.3  jsonlite_1.8.4  
 [9] gtable_0.3.1     magrittr_2.0.3   scales_1.2.1     pillar_1.8.1    
[13] rlang_1.0.6      cli_3.6.0        curl_4.3.3       remotes_2.4.2   
[17] generics_0.1.3   vctrs_0.5.1      tools_4.2.0      glue_1.6.2      
[21] munsell_0.5.0    compiler_4.2.0   pkgconfig_2.0.3  colorspace_2.0-3
[25] tidyselect_1.2.0 tibble_3.1.8    

ggblend on continuous scale

Hi!

FOA, thank you for the package! It's great, really.

Have you thought in making the blend compatible with multiple geoms? As an example, I would like to plot one numeric variable as a geom_point() with one color and blend it with another numeric variable in another geom_point() with a different color.

Do you thinks this would be feasible?

Thanks!

Pedro

blend = "darken" does not appear to be supported

  1. Using R 4.2.0 and R Studio 2022.02.2 Build 485
  2. Installed remotes::install_github("mjskay/ggblend")
  3. Try to run examples from https://mjskay.github.io/ggblend/

I get an empty plot with warnings (...the first normal plot works fine)

image

Warning messages:
1: blend = "darken" does not appear to be supported by your graphics device.
 - Blending output may not be as expected.
 - If your current graphics device *does* support blend = "darken"
   but auto-detection failed, consider reporting a bug. 
2: In drawDetails.GridGroup(x, recording = FALSE) :
  Group definition failed
3: In drawDetails.GridGroup(x, recording = FALSE) :
  Group definition failed

R Studio settings:
image
(R Studio reboot and other graphic settings do not help)

> sessionInfo()
R version 4.2.0 (2022-04-22)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Big Sur 11.6.5

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] forcats_0.5.1      stringr_1.4.0      dplyr_1.0.9        purrr_0.3.4        readr_2.1.2        tidyr_1.2.0       
 [7] tibble_3.1.7       tidyverse_1.3.1    ggblend_0.0.0.9000 ggplot2_3.3.6     

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.