r - 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
到目前为止的代码:
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,
hole = '0.75',
type = 'pie',
rotation = 14.4, # somehow the inner donut is skewed?
textposition = 'inside',
textinfo = 'label',
insidetextfont = list(color = '#FFFFFF'),
hoverinfo = 'text',
text = ~paste(dtArticles$ids, ': ', dtArticles$labels),
labels = dtArticles$ids,
values = dtArticles$values,
showlegend=FALSE,
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)
解决方案
推荐阅读
- azure-data-factory-2 - 在 Azure 数据工厂的复制活动中添加动态列
- anova - 2way 非参数方差分析的替代方案
- python - 根据日期对字典中的键进行分组?
- datatable - 数据表中的非聚集索引
- python - 如何从本地连接到 GCP Memorystore redis?
- c# - 为什么错误处理中间件在asp中不起作用
- ios - 'textureNamed(_:)':在需要时使用或提前存储在属性中?
- docker - 为什么 Docker 总是生成 none:none 图像(使用过什么选项)?
- r - 查找一个字符向量的哪个元素另一个向量的元素开始
- dynamics-crm - 在 Dynamics 365 中将电子邮件转换为案例