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

Strip above plot #121

Open
MyKo101 opened this issue Jan 13, 2021 · 1 comment
Open

Strip above plot #121

MyKo101 opened this issue Jan 13, 2021 · 1 comment

Comments

@MyKo101
Copy link

MyKo101 commented Jan 13, 2021

The white_around_sticker=TRUE argument doesn't cover enough area. IT leaves a small strip at the top of the plot, if there is an overflow. See the below reprex for an example:

library(hexSticker)
library(ggplot2)

#Create a plain red plot that fills the plot window
p <- ggplot() + 
  theme_void() +
  theme(plot.background=element_rect(fill="red"))

#Create the sticker
s <- sticker(p,package = "",
             s_x=1,s_y=1,s_width=2,s_height=2.5,
             white_around_sticker=TRUE)
#Plot to see it
plot(s)
@gangstR
Copy link

gangstR commented Jan 30, 2021

I also have encountered this issue and was going to log it today. Thanks to @MyKo101 for beating me to it and also providing a clear reprex. For most of my color choices, I had not noticed the faint gray line there until now. Fortunately, I ordinarily use a full pkgdown build script that uses magick for my top-secret corporate packages (!?!?) since I need to do some post-processing of the sticker. That gave me an idea. So, in the interim, you can use magick (no pun intended) to work around this issue. I made a few small changes to the great reprex:

library(hexSticker)
library(ggplot2)
library(magick)

#Create a plain red plot that fills the plot window
p <- ggplot() +
  theme_void() +
  theme(plot.background=element_rect(fill="red"))

#Create the sticker.... and save it, too!
s <- sticker(p,package = "",
             s_x=1,s_y=1,s_width=2,s_height=2.5,
             white_around_sticker=TRUE, filename = "test.png")

#Plot to see it
plot(s)

# use some magick
s.img <- image_read("test.png")
# get the image details
s.info <- image_info(s.img)
# extract the bitmap
s.bitmap <- s.img[[1]]
# replace the top line of pixels with a white row
s.bitmap[, 1:s.info$width, 1] <- as.raw(c(0xff, 0xff, 0xff))
# convert the bitmap back and save
image_write(image_read(s.bitmap), "test.png", format = "png")

# Abracadabra!
plot(image_read("test.png"))
file.remove("test.png")   # a good reprex should clean up after itself :-)

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

2 participants