【问题标题】:Open animated plot in new window在新窗口中打开动画情节
【发布时间】:2021-07-20 17:00:10
【问题描述】:

我是 R 新手,有点迷茫。

我有一个代码:

jpg <- (
xyplot(
  USD + EUR ~ data,
  data = ret,
  type = "l",
  ylab = "GBP",
  xlab = "month",
  key = list(space = "right",
             columns = 1,
             text = list(c("EUR", "USD")),
             rectangles = list(col = c("pink", "green")), 
             cex = 0.7))
)
x11()
print(jpg)

感谢它,我可以在新窗口中自动打开我的情节。 我想对这段代码做同样的事情:

levels(factor(mtcars$cyl))
levels(factor(mtcars$gear))

ggplot(mtcars, aes(factor(cyl), mpg)) + 
  geom_boxplot() + 

  transition_states(
    gear,
    transition_length = 2,
    state_length = 1
  ) +
  enter_fade() + 
  exit_shrink() +
  ease_aes('sine-in-out') + 
  labs(title = 'Fuel consumption for {closest_state} gears', x = 'cyl')

anim_save("mtcars.gif")

,但我不知道怎么做。如何使用 x11() 做到这一点?

【问题讨论】:

    标签: r ggplot2 plot x11 gganimate


    【解决方案1】:

    在 R 中,您可以使用“

    在第一行中,他们使用“jpg

    我不确定你的 "anim_save("mtcars.gif")" 是做什么用的,但是对于上面的行,你可以试试:

    
    levels(factor(mtcars$cyl))
    levels(factor(mtcars$gear))
    
    CARPLOT <- ggplot(mtcars, aes(factor(cyl), mpg)) + 
      geom_boxplot() + 
    
      transition_states(
        gear,
        transition_length = 2,
        state_length = 1
      ) +
      enter_fade() + 
      exit_shrink() +
      ease_aes('sine-in-out') + 
      labs(title = 'Fuel consumption for {closest_state} gears', x = 'cyl')
    
    print (CARPLOT)
    
    

    对于 .gif,您还可以将其分配给对象以对其进行可视化。

    【讨论】:

      猜你喜欢
      • 2014-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-20
      • 2017-08-26
      • 2017-12-22
      • 2011-08-19
      相关资源
      最近更新 更多