gpt4 book ai didi

r - 用 hexSticker 修剪六边形形状?

转载 作者:行者123 更新时间:2023-12-02 02:58:59 26 4
gpt4 key购买 nike

假设我们有一张带有图像的六角贴纸,如下所示

library(ggplot2)
library(hexSticker)

p <- ggplot(aes(x = mpg, y = wt), data = mtcars) + geom_point()
p <- p + theme_void() + theme_transparent()

sticker("wat.png", package="hexSticker", p_size=8, s_x=1, s_y=.75, s_width=1.3, s_height=1,filename="test.png")
system("open test.png")

生成

enter image description here

我们如何修剪六边形,以便 image不会突出到六边形的边界而不改变图像、它的大小等(也就是说,六边形内部的内容应该保持原样,我们只是希望绿色边框之外的内容不存在)

最佳答案

更新请参阅 @Marcinthebox的答案(它将创建一个透明背景,而不是 99% 的情况下您想要的白色背景)。

旧答案如下:


这可以通过选项white_around_sticker = TRUE来完成,例如

像这样

sticker("wat.png", package="hexSticker", p_size=8, s_x=1, s_y=.75, s_width=1.3, 
s_height=1,filename="test.png", white_around_sticker = T)

enter image description here

关于r - 用 hexSticker 修剪六边形形状?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60426922/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com