查看原文
其他

Mark Roepke 2018-06-07

还记得我的hexSticker包吗?我已经使用它生成了treeioggtree的六角贴,请移步:《一大波贴纸来袭》。并且我还有clusterProfilerChIPseeker等包的六角贴哦,不过我还没打印啦。等有空搞个全套来送给粉丝!最近有一篇文章记录了用户使用hexSticker包制作六角贴的全过程,并且作者在推特上AT了我,于是我搬运过来和大家分享一下,有了hexSticker包,做六角贴,就是这么容易,已经有相当多的包使用它来制作了:


这个包在github上已经有超过100个star,而且我时不时还会在twitter上收到一些表扬:

In my first post I introduced flxr, a basic R package I wrote to retrieve basic movie data from the web. Because any respectable R package has a hex sticker, I decided to put my design skills to the test and create one for flxr. This is an overview of that process that can hopefully be followed by those wanting to create their own hex sticker.

hexSticker Package

I had no idea where to begin in creating a hex sticker for flxr, but I immediately thought there could be an R package for creating hex stickers and I was correct. Guangchuang Yu created the hexSticker package to enable R users to easily create hex stickers for various purposes. The README on the package's GitHub page gives a great overview and displays stickers users have made with the package, which is great for sharing and inspiration!

The hexSticker package is on CRAN, so it can easily be installed and loaded:

install.packages("hexSticker")
library(hexSticker)
library(hexSticker)

Obtaining a Sticker Feature

The next step in creating a hex sticker is to determine its "feature", a central object that is the focus of the sticker. It's a good idea to make the feature a representation of the purpose of the R package. For example, the dplyr sticker has pliers as its feature:

In a similar spirit, I decided to use a clip art image of a movie camera for flxr given that it scrapes data about movies:

If you do not wish to use an image as the feature of your sticker, there are other examples available on the hexSticker GitHub page.

Creating the Sticker

The sticker() function in the hexSticker package is used for actually creating a sticker. It automatically creates the hexagonal shape and correct size, as well as provides a default template as a starting point. However, it's the default is not extremely detailed and it's likely easier to edit something more detailed. The code I used to create the flxr sticker is below:

sticker(
 package = "flxr",                     # package name to display on sticker            
 p_size = 24,                          # size of package name
 p_y = 1.5,                            # y of package name
 p_color = "#C9B128",                  # color of package name
 subplot = "base_camera.png",          # sticker feature
 s_x = 1.085,                          # x of feature
 s_y = .8,                             # y of feature
 s_width = .48,                        # width of feature - maintains aspect ratio
 h_size = 2,                           # border
 h_color = "#C9B128",                  # color of border
 h_fill = "black",                     # color of background
 url = "github.com/markroepke/flxr",   # url at the bottom
 u_color = "white",                    # color of url at the bottom
 u_size = 3.5,                         # size of url at the bottom
 filename = "flxr.png"                 # location to save the image
)

Note that the sticker image created by the sticker() function does not display in the plot or viewer window within RStudio, but it does save to the location specified in the filename parameter.

Here is the sticker I've created for flxr, which is a direct result of the above code:

Hopefully this is a decent guide for quickly creating a hex sticker with the hexSticker R package. I would like to play around with this some more to better understand the package's full functionality.

猜你喜欢

    您可能也对以下帖子感兴趣

    文章有问题?点此查看未经处理的缓存