Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upgradient/spotlight #7
Comments
|
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: Somehow makes sense to have hexagon-shaped highlights in a hexagonal image. |
|
@GuangchuangYu , do you think it could be included into |
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")By default, see 5a442e7. |
|
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. |
|
@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 You can remove and/or rearrange any layer except the 1st layer. |
|
Just a minor suggestion @GuangchuangYu : could you please add a parameter to specify the alpha/transparency of the spotlight? |
|
@jotsetung you mean the |
|
yes, right, the max alpha. |
|
already added, bb722a3. |



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
hexStickeras well?