向灰度曲线添加渐变和手绘效果

问题描述 投票:1回答:1

我对将gganimate用于渐变以及手绘和绘画式填充效果感兴趣(请参见此处的草图,绘画和渐变:https://semiotic.nteract.io/guides/sketchy-painty-patterns)。这可能吗?我发现ggroughhttps://xvrdm.github.io/ggrough/)能够转换ggplot2对象以具有这些效果。但是,是否可以将ggrough或其他东西与gganimate结合使用?

并且还有另一种方法可以做到这一点,即使在基数为ggplot2的情况下(即,不使用gganimate?)请注意,我担心这两个问题的答案都不会,特别是对于渐变填充(请参阅@hadley Hadley Wickhams的答案)这个问题:How to add texture to fill colors in ggplot2)。

或者是否还有其他解决方案仍使用ggplot2,但不使用gganimate?我想如果在ggplot2基中有可能我可以制作许多单独的文件并将它们缝合在一起以制成.gif。尽管从理论上讲,我可以使用ggrough的输出来执行此操作。

r ggplot2 textures gradient gganimate
1个回答
0
投票

[另一个选择可能是使用xkcd库来获取波浪线。它不会散乱地填充,但这是一个开始,并且位于正确的美学区域。我无法使用gganimate开箱即用,但是可以使用tweenr(依赖于gganimate的同一包)准备数据并将其馈送到gganimate::transition_manual中,以达到不错的效果:] >

enter image description here


这是怎么回事。鉴于此假数据:

library(tidyverse); library(gganimate)
df <- tibble(Group = rep(1:3, times = 3),
             value = c(1:6, 3:1),
             period = rep(1:3, each = 3))

我们可以使用geom_rectgganimate::transition_states制作动画。 geom_col在这里会更容易,但我想稍后显示与xkcd::xkcdrect的相似性。

ggplot() +
  geom_rect(data = df,
           aes(xmin = Group - 0.4, xmax = Group + 0.4,
               ymin = 0, ymax = value), 
           fill = "gray80") +
  transition_states(period)

enter image description here

当我放入xkcd::xkcdrect等效项时出现错误:

# Doesn't work
ggplot() +
  xkcd::xkcdrect(aes(xmin = Group - 0.4, xmax = Group + 0.4,
                     ymin = 0, ymax = value), fill = "gray80",
                 df) +
  transition_states(period)

if(nrow(from)== 0 && nrow(to)== 0的错误,{:缺少值需要TRUE / FALSE的地方另外:警告消息:1:在rep(“ raw”,length = nrow(from)):'length.out'使用的第一个元素参数2:在rep(“ raw”,length = nrow(to))中:'length.out'参数3:在rep(NA_integer_,length = nrow(to))中:'length.out'参数使用的第一个元素

但是我们可以通过手动准备补间数据,然后将其输入到transition_manual中来到达相同的位置:

df_tween <- tweenr::tween_states(
  list(df[1:3,],
       df[4:6,],
       df[7:9,]), 3, 1, 'cubic-in-out', 100)


  ggplot() +
  xkcd::xkcdrect(aes(xmin = Group - 0.4, xmax = Group + 0.4,
                     ymin = 0, ymax = value), fill = "gray80",
                 df_tween) +
  transition_manual(.frame)
© www.soinside.com 2019 - 2024. All rights reserved.