yihui / animation

A gallery of animations in statistics and utilities to create animations
https://yihui.org/animation/
206 stars 60 forks source link

legend error using saveGIF #104

Closed weianuk closed 7 years ago

weianuk commented 7 years ago

When I was using saveGIF using the code below,

saveGIF(
{ for (i in 1:5) {
function
legend(x="topleft",legend = c("1", "2","3","4","5","6"), 
                       fill = c("red", "green","yellow", "blue","purple","grey"), bty = "n")
}
},
interval = 0.1, ani.width = 550, ani.height = 550
)

it gave the error of the legend:

[1] 1 Error in strwidth(legend, units = "user", cex = cex, font = text.font) : plot.new has not been called yet In addition: Warning messages: 1: fullpage and expand syntaxes deprecated, use extent. 2: panel.margin is deprecated. Please use panel.spacing property instead

  1. Is there any setting about the legend incorrect?
  2. When I want to enlarge the figure by changing ani.width and ani.height, nothing happened. Is there still something wrong?

Hope for helps on my problem. @yulijia @yihui

Thanks in advance.

yulijia commented 7 years ago

I cannot repeat your code. what is function?

But I can run the demo successfully as shown below.

saveGIF(
  { for (i in 1:5) {
    plot(rnorm(10))
    legend(x="topleft",legend = c("1", "2","3","4","5","6"), 
           fill = c("red", "green","yellow", "blue","purple","grey"), bty = "n")
    }
  },
  interval = 0.1, ani.width = 550, ani.height = 550
)
weianuk commented 7 years ago

@yulijia Thanks for your prompt reply. Function is a complex block that calls many other subfunctions and ggmap, so it is hard to put here. But I realised the error is the legend setting using ggmap.

yulijia commented 7 years ago

If you don't have further questions, I will close this issue.