R/Shiny:连接情节圆环图的切片

问题描述

在您的帮助下,我已经能够创建一个双圆环图。我现在要添加的是内部甜甜圈切片之间的一些线条。不幸的是,我不知道如何:)

我想要实现的是能够加载一个将旧 ID 链接到新 ID 的 csv,然后在 plot_ly() 中动态地看到它作为新层/跟踪呈现。

例如,在下面的代码中,我想链接

  • IV.1 到 X.2
  • IV.1 到 X.6
  • IV.7 到 X.2
  • XII.11 至 VII.5
  • XII.13 至 VII.5 和 XII.11

完整的数据集可用 here链接列表可用 here

到目前为止的代码

library(shiny)
library(dplyr)
library(plotly)

# Define UI for application that draws a line-connected donut chart
ui <- fluidPage(
    plotlyOutput("plot"),)

server <- function(input,output,session) {
    dtRutte3 <- read.csv("Herverkaveling.Rutte3.csv",sep=';',dec=',',fileEncoding="Windows-1252")
    
    # Read csv containing the internally connecting lines
    dtHerverkavelingen <- read.csv("Herverkavelingen.Rutte3.csv")
    
    # Filter out chapters and articles
    dtChapters <- dtRutte3 %>% 
        group_by(parents) %>%
        filter(parents=='root') %>% 
        ungroup()
    dtArticles <- dtRutte3 %>% 
        group_by(parents) %>%
        filter(parents!='root') %>% 
        ungroup()
    
    # Render the donut
    output$plot <- renderPlotly({

        fig <- plot_ly(height=1024,sort=FALSE)
        # Outer donut containing chapters
        fig <- add_trace(fig,hole = '0.75',type = 'pie',rotation = 0,textposition = 'inside',textinfo = 'label',insidetextfont = list(color = '#FFFFFF'),hoverinfo = 'text',text = ~paste(dtChapters$ids,': ',dtChapters$labels),labels = dtChapters$ids,values = dtChapters$values,showlegend=FALSE,domain = list(x = c(0.1,0.9),y = c(0,1))
        )
        # Inner donut containing articles
        fig <- add_trace(fig,rotation = 14.4,# somehow the inner donut is skewed?
            textposition = 'inside',text = ~paste(dtArticles$ids,dtArticles$labels),labels = dtArticles$ids,values = dtArticles$values,domain = list(x = c(0.2,0.8),y = c(0.1,0.9))
        )
        fig <- fig %>% layout(title="Herverkaveling Rutte 3")
        fig

        #add_lines? add_trace? how to calculate coordinates?
    })
}
shinyApp(ui,server)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...