日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

R语言timevis包的学习

發(fā)布時間:2025/7/14 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 R语言timevis包的学习 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

timevis包可以實現(xiàn)時間線的可視化,并支持交互。更好的是,也可以在shiny和Rmarkdown中使用!

此外此外,還有眾多的API,可以在創(chuàng)建后修改。支持從外部獲取數(shù)據(jù)。返回的是htmlwidgets對象。

基本用法

timevis(data, groups, showZoom = TRUE, zoomFactor = 0.5, fit = TRUE,options, width = NULL, height = NULL, elementId = NULL)

?data? 包括時間線各項的數(shù)據(jù)框,每行為一個時間線。包括以下各項:

  • start? (必須)item開始的日期,如"1988-11-22" or "1988-11-22 16:30:00"
  • content? (必須)item的內(nèi)容,可以是文本或者HTML代碼
  • end? (可選)item結(jié)束的日期,如有,則此item是一個范圍,如無,則此item為一個點
  • id? (可選)item的id,建議使用,因為在查詢item時會用到
  • type? (可選)item的類型,默認'box',還有'point','range','background'。前兩者只需開始時間,而后兩者需要開始和結(jié)束時間
  • title? (可選)item的標(biāo)題,當(dāng)鼠標(biāo)移到它們上時顯示,僅支持文本
  • editable? (可選)若為TRUE,此item能被鼠標(biāo)操縱,鼠標(biāo)單擊開始或結(jié)束日期時,會出現(xiàn)刪除符號,可刪除;雙擊一個日期時,會在此添加一個點狀的item
  • group? (可選)組的id,當(dāng)設(shè)置時,同一組的item將在同一個時間線上。一個豎直的軸展示各組的名字
  • subgroup? (可選)子組的id,將所有項目分組的每個子組中的item,放在相同的高度上,而不是將它們堆疊在一起。
  • className? (可選)用于指定類名,從而為item設(shè)置css樣式
  • style? (可選)css樣式設(shè)置,例如 color: red;.

這些參數(shù)中,如果某個參數(shù)只用于部分行,則可用NA補齊;此外,這些參數(shù)還可以用setItems函數(shù)來指定

?groups? (可選)包含組數(shù)據(jù)的數(shù)據(jù)框,同一組的item將在同一個時間線上。一個豎直的軸展示各組的名字,其包括以下各項:

  • id? (必須)組的id
  • content? (必須)組的內(nèi)容,可以是文本或者HTML代碼
  • title? 組的標(biāo)題,當(dāng)鼠標(biāo)移到它們上時顯示,僅支持文本
  • subgroupOrder??按字段名稱排序子組,默認地,組通過first-come, first-show排序
  • className,style 使用方法與上面data中同

?showZoom? (TRUE)包含放大/縮小的按鈕

?zoomFactor? 放大因子。例如放大因子為0.5,起初顯示20天,放大一下將顯示30天,再放大一下將顯示45天

?fit? (TRUE)當(dāng)時間線初始化時,匹配時間線上的所有數(shù)據(jù);否則,時間線將展示當(dāng)前日期

?options? 配置項的列表,可用的配置項見 點擊

?

實例

啊,講了這么多,來個小實例吧。這些實例都是來自timesvis的說明文檔

#----------------------- Minimal data ----------------- timevis(data.frame(id = 1:2,content = c("one", "two"),start = c("2016-01-10", "2016-01-12")) )#----------------------- Hide the zoom buttons, allow items to be editable ----------------- timevis(data.frame(id = 1:2,content = c("one", "two"),start = c("2016-01-10", "2016-01-12")),showZoom = FALSE,options = list(editable = TRUE, height = "200px") )#----------------------- You can use %>% pipes to create timevis pipelines ----------------- timevis() %>%setItems(data.frame(id = 1:2,content = c("one", "two"),start = c("2016-01-10", "2016-01-12"))) %>%setOptions(list(editable = TRUE)) %>%addItem(list(id = 3, content = "three", start = "2016-01-11")) %>%setSelection("3") %>%fitWindow(list(animation = FALSE))#------- Items can be a single point or a range, and can contain HTML ------- timevis(data.frame(id = 1:2,content = c("one", "two<br><h3>HTML is supported</h3>"),start = c("2016-01-10", "2016-01-18"),end = c("2016-01-14", NA),style = c(NA, "color: red;")) )#----------------------- Alternative look for each item ----------------- timevis(data.frame(id = 1:2,content = c("one", "two"),start = c("2016-01-10", "2016-01-14"),end = c(NA, "2016-01-18"),type = c("point", "background")) )#----------------------- Using a function in the configuration options ----------------- timevis(data.frame(id = 1,content = "double click anywhere<br>in the timeline<br>to add an item",start = "2016-01-01"),options = list(editable = TRUE,onAdd = htmlwidgets::JS('function(item, callback) {item.content = "Hello!<br/>" + item.content;callback(item);}')) )#----------------------- Using groups ----------------- timevis(data = data.frame(start = c(Sys.Date(), Sys.Date(), Sys.Date() + 1, Sys.Date() + 2),content = c("one", "two", "three", "four"),group = c(1, 2, 1, 2)),groups = data.frame(id = 1:2, content = c("G1", "G2")))#----------------------- Getting data out of the timeline into Shiny ----------------- if (interactive()) { library(shiny)data <- data.frame(id = 1:3,start = c("2015-04-04", "2015-04-05 11:00:00", "2015-04-06 15:00:00"),end = c("2015-04-08", NA, NA),content = c("<h2>Vacation!!!</h2>", "Acupuncture", "Massage"),style = c("color: red;", NA, NA) )ui <- fluidPage(timevisOutput("appts"),div("Selected items:", textOutput("selected", inline = TRUE)),div("Visible window:", textOutput("window", inline = TRUE)),tableOutput("table") )server <- function(input, output) {output$appts <- renderTimevis(timevis(data,options = list(editable = TRUE, multiselect = TRUE, align = "center")))output$selected <- renderText(paste(input$appts_selected, collapse = " "))output$window <- renderText(paste(input$appts_window[1], "to", input$appts_window[2]))output$table <- renderTable(input$appts_data) } shinyApp(ui, server) }

?

更多的shiny關(guān)于timevis的應(yīng)用見此?點擊

參考:timevis包timevis函數(shù)的說明文檔。

轉(zhuǎn)載于:https://www.cnblogs.com/Hyacinth-Yuan/p/8343425.html

總結(jié)

以上是生活随笔為你收集整理的R语言timevis包的学习的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。