画图鬼才:纹理填充

2020-01-17  本文已影响0人  吴十三和小可爱的札记

作者mikefc 写了很多很鬼才的包,包括devout 图片纯文本输出;devoutaudio实现了把画图变成了音频;而devoutsvg利用svgout实现了纹理填充图片。

patternplot 解决所有作图底层系统纹理填充。

环境搭建

# Colour encoding
devtools::install_github("coolbutuseless/lofi") 

# SVG creation
devtools::install_github("coolbutuseless/minisvg") 

# Device interface
devtools::install_github("coolbutuseless/devout") 

devtools::install_github("coolbutuseless/devoutsvg") 

示例

library(svgpatternsimple)
library(devoutsvg)
library(lofi)
library(devout)
library(tidyverse)
​
# 填充颜色、纹理设置 ---------------------------------------------------------------
gear4_colour <- svgpatternsimple::encode_pattern_params_as_hex_colour(
 pattern_name = 'null', 
 colour       = '#123456'
)
​
gear6_colour <- svgpatternsimple::encode_pattern_params_as_hex_colour(
 pattern_name = 'stipple',  # 设定纹理样式
 colour       = '#ff4455',  # 设定纹理中的颜色
 spacing      = 20          # 纹理间距
)
​
gear8_colour <- svgpatternsimple::encode_pattern_params_as_hex_colour(
 pattern_name  = 'hex', 
 angle         = 0, 
 spacing       = 20, 
 fill_fraction = 0.1,
 colour        = '#125634'
)
​

# 出图 ----------------------------------------------------------------------
svgout(filename = # 输出图片位置
 "C:\\Users\\Administrator\\Desktop\\abc\\example-manual3.svg", 
 pattern_pkg = "svgpatternsimple")
ggplot(mtcars) + 
 geom_bar(aes(as.factor(cyl), fill = as.factor(cyl)), colour = 'black') + 
 labs(title = basename("Example - manual pattern specification")) + 
 theme_bw() +
 theme(legend.key.size = unit(1.5, "cm")) + 
 scale_fill_manual(
 values = c(
 '4' = gear4_colour,
 '6' = gear6_colour,
 '8' = gear8_colour
 )
 )
invisible(dev.off())
example-manual3.png
上一篇下一篇

猜你喜欢

热点阅读