ggfx包给图片添加阴影

2021-02-28  本文已影响0人  R语言数据分析指南

ggfx软件包是由Thomas Lin Pedersen开发的一种在R绘图中访问像素级图像滤镜的方法,尤其是在使用ggplot2绘图时可以用来给图片添加阴影。喜欢的小伙伴可以关注我的公众号R语言数据分析指南,持续分享更多优质资源,后台回复关键词ggplot2获取一份绝佳ggplot2学习教程
链接:https://mp.weixin.qq.com/s/c8DXQXcP3-2HF6gup2xW7Q

安装最新版ggfx

devtools::install_github('thomasp85/ggfx')
library(ggfx)
library(ggplot2)
ggplot(mtcars, aes(x = mpg, y = disp)) +
  with_blur(geom_point(),sigma = unit(1, 'mm')) + 
  geom_smooth()
library(grid)
circle_left <- circleGrob(x = 0.25, y = 0.5, r = 0.2)
circle_right <- with_blur(circleGrob(x = 0.75, y = 0.5, r = 0.2),
                          sigma = unit(1, 'mm'))
grid.newpage()
grid.draw(circle_left)
grid.draw(circle_right)
checker <- expand.grid(x = 1:6, y = 1:6)
checker <- checker[checker$x %% 2 == checker$y %% 2, ]
ggplot() + as_reference(
    geom_tile(aes(x = x, y = y), checker),
    id = 'pattern') + with_blend(
    geom_text(aes(x = 3.5, y = 3.5, label = '🚀GGFX🚀'), size = 15),
    bg_layer = 'pattern',
    blend_type = 'xor')
ggplot() + with_blend(
    geom_tile(aes(x = x, y = y), checker),
    bg_layer = wave,blend_type = 'copy_red',
    alpha = 'src',id = 'wave-checker') +with_variable_blur(
    geom_abline(aes(intercept = -6:6, slope = 1)),
    x_sigma = ch_hue('wave-checker'),
    y_sigma = ch_luminance('wave-checker'),
    x_scale = unit(3, 'mm'))
ggplot(mtcars,aes(mpg,disp))+
  with_shadow(geom_smooth(alpha=1),singma=4)+
  with_shadow(geom_point(size=3),sigma=4)+
  theme_bw()
volcano_long <- data.frame(
  x = as.vector(col(volcano)),
  y = as.vector(row(volcano)),
  z = as.vector(volcano))

ggplot(volcano_long,aes(y,x))+
  as_reference(geom_raster(aes(alpha=z),fill="black",
                    interpolate=TRUE,show.legend=FALSE),id='height_map')+
           with_shade(geom_contour_filled(aes(z=z,fill=after_stat(level))),
height_map=ch_alpha('height_map'),azimuth=150,height=5)
上一篇下一篇

猜你喜欢

热点阅读