Home > Back-end >  How to animate a ternary plot in R
How to animate a ternary plot in R

Time:11-05

I am trying to animate a ternary plot in R with gganimate and I am facing into a wall.

library(tidyverse)
library(gganimate)
library(ggtern)
#> Registered S3 methods overwritten by 'ggtern':
#>   method           from   
#>   grid.draw.ggplot ggplot2
#>   plot.ggplot      ggplot2
#>   print.ggplot     ggplot2
#> --
#> Remember to cite, run citation(package = 'ggtern') for further info.
#> --
#> 
#> Attaching package: 'ggtern'
#> The following objects are masked from 'package:ggplot2':
#> 
#>     aes, annotate, ggplot, ggplot_build, ggplot_gtable, ggplotGrob,
#>     ggsave, layer_data, theme_bw, theme_classic, theme_dark,
#>     theme_gray, theme_light, theme_linedraw, theme_minimal, theme_void

data=tibble(x=runif(200),  y = runif(200),  z = runif(200), time=rep(seq(1:10),20))

ggtern(data, aes(x,y,z))  
  geom_point()  
  theme_rgbw()  
  stat_density_tern(geom = 'polygon',
                    aes(fill  = ..level..,
                        alpha = ..level..), bdl=0.001)  
    scale_fill_gradient(low = "blue",high = "red")   
  guides(color = "none", fill = "none", alpha = "none") 
#> Warning: Removed 1 rows containing non-finite values (StatDensityTern).

Created on 2022-11-04 with enter image description here

  • Related