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

gradient/spotlight #7

Closed
sgibb opened this issue Mar 24, 2017 · 10 comments
Closed

gradient/spotlight #7

sgibb opened this issue Mar 24, 2017 · 10 comments

Comments

@sgibb
Copy link
Contributor

sgibb commented Mar 24, 2017

All the handcrafted (made with Illustrater) stickers at https://github.com/Bioconductor/BiocStickers have a colour gradient for the background colour. Would it be possible to add this to hexSticker as well?

@jorainer
Copy link

Alternative approach: use a spotlight. I played a little bit around and found the following solution:

library(hexSticker)
library(ggplot2)
library(lattice)
library(grid)
library(hexbin)

p <- ggplot(aes(x = mpg, y = wt), data = mtcars) + geom_point()
## Add highlight:
set.seed(123)
vals_x <- rnorm(500000, sd = 2, mean = 0)
vals_y <- rnorm(500000, sd = 2, mean = 0)
whiteTrans <- function(n) {
    rgb(r = rep(1, n), g = rep(1, n), b = rep(1, n),
        alpha = seq(0, 0.4, length.out = n))
}
hgl <- hexbinplot(vals_x ~ vals_y, colramp = whiteTrans, colorkey = FALSE,
                  bty = "n", scales = list(draw = FALSE), xlab = "", ylab = "",
                  border = NA, par.settings = list(axis.line = list(col = NA)))
## Combine the plots; have to adjust x, y, width and height to the mtcars data
p <- p + geom_subview(hgl, x = 21.5, y = 2.2,
                      width = 50, height = 50) +
    theme_void() + theme_transparent()
print(p)
sticker(p, package="hexSticker", p_size=8, s_x=1, s_y=.75, s_width=1.3, s_height=1,
        filename="ggplot2_highlight.png")

it involves a little try and error but looks not too bad I think:

ggplot2_highlight

Somehow makes sense to have hexagon-shaped highlights in a hexagonal image.

@jorainer
Copy link

jorainer commented Apr 5, 2017

@GuangchuangYu , do you think it could be included into hexSticker? See related Bioconductor/BiocStickers#27

@GuangchuangYu
Copy link
Owner

GuangchuangYu commented Apr 5, 2017

require(ggplot2)
require(hexSticker)
p <- ggplot(aes(x = mpg, y = wt), data = mtcars) + geom_point() + 
        theme_void() + theme_transparent()
sticker(p, package="hexSticker", p_size=8, 
            s_x=1, s_y=.75, s_width=1.3, s_height=1, 
            spotlight=T,  filename="ggplot2_highlight.png")

ggplot2_highlight

By default, spotlight=FALSE. If we set spotlight=TRUE, it will be added and parameters, l_x, l_y, l_width and l_height, will work for the spotlight.

see 5a442e7.

@jorainer
Copy link

jorainer commented Apr 5, 2017

Awesome @GuangchuangYu ! Just one minor comment: you think it would be possible to put the highlight on the very top layer? In your example the highlight is below the points, but it should be on top of the data points.

@GuangchuangYu
Copy link
Owner

done!

ggplot2_highlight

@GuangchuangYu
Copy link
Owner

GuangchuangYu commented Apr 5, 2017

@jotsetung actually, you can arrange layers after the sticker was created.

pg <- sticker(p, package="hexSticker", p_size=8, 
            s_x=1, s_y=.75, s_width=1.3, s_height=1, 
            spotlight=T,  filename="ggplot2_highlight.png")
pg$layers = pg$layers[c(1, 3, 2, 4)]
save_sticker('ggplot2_highlight2.png', pg)

Then ggplot2_highlight2.png will be the first version.

You can remove and/or rearrange any layer except the 1st layer.

@jorainer
Copy link

jorainer commented Apr 6, 2017

Just a minor suggestion @GuangchuangYu : could you please add a parameter to specify the alpha/transparency of the spotlight?

@GuangchuangYu
Copy link
Owner

@jotsetung you mean the 0.4 in https://github.com/GuangchuangYu/hexSticker/blob/master/R/sticker.R#L78 ?

@jorainer
Copy link

jorainer commented Apr 6, 2017

yes, right, the max alpha.

@GuangchuangYu
Copy link
Owner

already added, bb722a3.

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

No branches or pull requests

3 participants