Shiny App 和R语言绘制数据动图

在这里插入图片描述

library(shiny)
library(echarts4r)

# phoney data
df <- data.frame(
  x = 1:100,
  y = runif(100),
  z = runif(100)
)

ui <- fluidPage(
  actionButton("add", "Add series"), 
  actionButton("rm", "Remove series"), 
  echarts4rOutput("chart")
)


server <- function(input, output){
  
  output$chart <- renderEcharts4r({
    e_charts(df, x) |> 
      e_scatter(y, z)
  })
  
  observeEvent(input$add, {
    echarts4rProxy("chart", data = df, x = x) |>  # create a proxy
      e_line(z) |> 
      e_loess(y ~ x, name = "fit") |> 
      e_execute()
  })
  
  observeEvent(input$rm, {
    echarts4rProxy("chart") |>  # create a proxy
      e_remove_serie("z") |> 
      e_remove_serie("fit")
  })
  
}

shinyApp(ui, server)

R语言绘制数据动图

随着互联网+和大数据科技的发展,VFX可视化和数据可视化越来越受到人们的喜爱,在R语言中,绘制GIF动图主要是在gganimate包中运行,制作视频主要是在av包,gganimate是图形语法的扩展,由ggplot2包实现,它增加了对使用ggplot2用户熟悉的API声明动画的支持

library(av)
library(ggplot2)
library(gganimate)
library(tidyverse)
library(lubridate)
`ggplot(mpg,aes(class,hwy,fill=class))+geom_boxplot()+transition_states(cty,transition_length=2,state_length=1)+enter_fade()+exit_shrink()+ease_aes('sine-in-out')`

在这里插入图片描述
小提琴图.gif

ggplot(mpg,aes(class,hwy,fill=class))+geom_violin(alpha=0.3,width=0.9)+geom_jitter(shape=21)+transition_states(year,transition_length=8,state_length=5)+enter_fade()+exit_shrink()+ease_aes('sine-in-out')

在这里插入图片描述
多因素散点图.gif

library(av)
library(ggplot2)
library(gganimate)
library(tidyverse)
library(lubridate)
ggplot(iris, aes(x = Petal.Width, y = Petal.Length)) + geom_point(aes(colour = Species)) +transition_states(Species,transition_length = 2,state_length = 1)

在这里插入图片描述散点图.gif

library(gapminder)
View(gapminder)
ggplot(gapminder,aes(gdpPercap,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()+facet_wrap(~continent)+labs(title='Year:{frame_time}',x='GDP per capita',y='life expectancy')+transition_time(year)+ease_aes('linear')

在这里插入图片描述

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值