iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 22
0

networkD3:
D3 JavaScript Network Graphs from R

install.packages("networkD3") 

library(networkD3) #networkD3 
library(magrittr)  #輸出使用

先以一個小小的案例,實作完整個流程先。
預計將以一個小小的網路圖串接實作與匯出

# Create fake data
src <- c("A", "A", "A", "A","B", "B", "C", "C", "D")
target <- c("B", "C", "D", "J", "E", "F", "G", "H", "I")
networkData <- data.frame(src, target)
# 繪圖Plot
simpleNetwork(networkData)

https://ithelp.ithome.com.tw/upload/images/20180102/20107033QUk8BdCJqc.png

#輸出為單獨的html
simpleNetwork(networkData) %>%
  saveNetwork(file = 'NetWorkT1.html')
#上方為繪圖跟輸出,寫在一起
#下方是輸出單獨寫的部分
saveNetwork(simpleNetwork(networkData),file = 'NetWorkT1.html')

輸出Output

  • Saving to an external stand alone HTML file
    請詳見前述案例做法
  • Including in an RMarkdown file
  • Including in Shiny web apps
  • Saving as static PNG image
    Viewer下輸出image
    https://ithelp.ithome.com.tw/upload/images/20180102/20107033f9HKEgwfRk.png
x<-read.csv("D:/Kimi Lin/Desktop/toPost.csv")
city<-str_sub(x[,2],1,3)
area<-str_sub(x[,2],4,str_length(x[,2]))

a<-data.frame(city,area)
View(a)

simpleNetwork(a,height = 100,width = 100,charge = -1,zoom = 2)

simpleNetwork(a) %>%
  saveNetwork(file = 'NetWorkT1.html')

參考資料

networkD3:D3 JavaScript Network Graphs from R


上一篇
(Day21)專案實作-使用leaflet 套件繪製互動式地圖網頁
下一篇
(Day23)用Shiny套件打造互動式資料視覺化網站-(上)
系列文
職場老鳥的資料科學初體驗-R語言專案實作紀錄30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言