1

gganimate を使用してデータをアニメーション化したいと考えています。彼らの github ページから例を挙げて、私のケースを反映するように少し変更しました。X 軸は日付で、すべてのフレームで同じ位置にロゴが必要です。

再現可能なコード:

library(magick)
library(gapminder)
library(ggplot2)
library(rsvg)
library(gganimate)

tiger <- image_read_svg('http://jeroen.github.io/images/tiger.svg', width = 400)

(p <- ggplot(gapminder, aes(year, lifeExp, size = pop, colour = country)) +
  geom_point(alpha = 0.7, show.legend = FALSE) +
  scale_colour_manual(values = country_colors) +
  scale_size(range = c(2, 12)) +
  scale_x_log10() +
  annotation_raster(tiger, ymin = 75, ymax = 100, xmin = 1965, xmax = 2005) )

# here the animate part (not needed just for ilustrative purposes)

p + labs(title = 'Year: {frame_time}', x = 'Year', y = 'life expectancy') +
  transition_time(year) +
  ease_aes('linear')

問題は、x 軸が日付でない場合、任意のグラフにロゴをプロットできることです。

この問題は日付タイプに関連していると思われますが、これまでのところ成功していません。

4

1 に答える 1