使用闪亮的IGRAPHE对象的刷牙选项

使用闪亮的IGRAPHE对象的刷牙选项,r,shiny,igraph,R,Shiny,Igraph,将闪亮刷牙选项与igraph库集成的最佳方式是什么? 现在,我知道在ggplot2中使用brushedPoints效果最好,但是有没有一种方法可以用于igraph?是否有办法将网络转换为ggplot2对象,以便可以使用panelvar1和panelvar=NONE 我创建了一个闪亮的应用程序来可视化网络。抱歉,数据帧稍大一些(它们来自教程)。请先创建数据帧,因为闪亮应用程序依赖于它们。应用程序包括刷牙选项 # nodes for network id <- c('s01', 's02',

将闪亮刷牙选项与igraph库集成的最佳方式是什么? 现在,我知道在ggplot2中使用brushedPoints效果最好,但是有没有一种方法可以用于igraph?是否有办法将网络转换为ggplot2对象,以便可以使用panelvar1和panelvar=NONE

我创建了一个闪亮的应用程序来可视化网络。抱歉,数据帧稍大一些(它们来自教程)。请先创建数据帧,因为闪亮应用程序依赖于它们。应用程序包括刷牙选项

# nodes for network
id <- c('s01', 's02', 's03', 's04', 's05', 's06', 's07', 's08', 's09', 's10', 's11', 's12', 's13', 's14', 's15', 's16', 's17')
media <- c('NY Times', 'Washington Post', 'Wall Street Journal', 'USA Today', 'LA Times', 'New York Post', 'CNN', 'MSNBC', 'FOX News', 'ABC', 'BBC', 'Yahoo News', 'Google News', 'Reuters.com', 'NYTimes.com', 'WashingtonPost.com', 'AOL.com')
media.type <- c(1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3)
type.label <- c('Newspaper', 'Newspaper', 'Newspaper', 'Newspaper', 'Newspaper', 'Newspaper', 'TV', 'TV', 'TV', 'TV', 'TV', 'Online', 'Online', 'Online', 'Online', 'Online', 'Online')
audience.size <- c(20, 25, 30, 32, 20, 50, 56, 34, 60, 23, 34, 33, 23, 12, 24, 28, 33)
nodes <- data.frame(id, media, media.type, type.label, audience.size)
str(nodes)
网络节点
id这里尝试使用Stéphane Laurent在评论中建议的
ggraph
。我省略了图形美学,如节点颜色、大小等

library(shiny)
library(igraph)
library(ggraph) 
ui
与您的相同:

ui <- fluidPage(
  tabsetPanel(
    tabPanel("tab", #tab ----
             sidebarLayout(
               sidebarPanel("text",
                            helpText("Submit for Analysis"),
                            actionButton("button1", "Submit")
               ),
               mainPanel(
                 verbatimTextOutput("info_n_head"),
                 verbatimTextOutput("info_e_head"),
                 plotOutput("graph_1", brush = "plot_brush", width = "100%", height = '600px'),
                 verbatimTextOutput("info")
               )
             )

    )
  )
)

server <- function(input, output) {
 output$info_n_head <- renderPrint({
    # Shows peview of Data.
    head(nodes)
  })
  output$info_e_head <- renderPrint({
    # Shows peview of Data.
    head(links)
  })

  net <- graph_from_data_frame(d = links,
                               vertices = nodes,
                               directed = F)
  set.seed(1)
  net_lay <- ggraph::create_layout(net,
                                   layout = "nicely")

  observeEvent(input$button1, {
    output$graph_1 <- renderPlot({
      ggraph(net_lay) +
        geom_edge_link() +
        geom_node_point() 
    })
  })

  output$info <- renderPrint({
    brush_net <- brushedPoints(net_lay,
                               input$plot_brush)
      nodes[as.character(nodes$id) %in%  as.character(brush_net$name),]
  })

}

shinyApp(ui, server)

ui您是否考虑过
ggraph
软件包?它可以将
igraph
图形绘制为
ggplot
。是的,这里有一个很好的例子:()。它能够得到坐标。我希望建立到节点文件和所有其他属性的链接。也许可以用串扰库做些什么?目前我正在探索不同的选项,但没有一个能让我从节点文件中进行过滤。谢谢,这是解决这个问题的好方法。
library(shiny)
library(igraph)
library(ggraph) 
ui <- fluidPage(
  tabsetPanel(
    tabPanel("tab", #tab ----
             sidebarLayout(
               sidebarPanel("text",
                            helpText("Submit for Analysis"),
                            actionButton("button1", "Submit")
               ),
               mainPanel(
                 verbatimTextOutput("info_n_head"),
                 verbatimTextOutput("info_e_head"),
                 plotOutput("graph_1", brush = "plot_brush", width = "100%", height = '600px'),
                 verbatimTextOutput("info")
               )
             )

    )
  )
)

server <- function(input, output) {
 output$info_n_head <- renderPrint({
    # Shows peview of Data.
    head(nodes)
  })
  output$info_e_head <- renderPrint({
    # Shows peview of Data.
    head(links)
  })

  net <- graph_from_data_frame(d = links,
                               vertices = nodes,
                               directed = F)
  set.seed(1)
  net_lay <- ggraph::create_layout(net,
                                   layout = "nicely")

  observeEvent(input$button1, {
    output$graph_1 <- renderPlot({
      ggraph(net_lay) +
        geom_edge_link() +
        geom_node_point() 
    })
  })

  output$info <- renderPrint({
    brush_net <- brushedPoints(net_lay,
                               input$plot_brush)
      nodes[as.character(nodes$id) %in%  as.character(brush_net$name),]
  })

}

shinyApp(ui, server)