r - 使这个树状图工作需要什么?
问题描述
一直试图让树形图工作,但输出是空白的,不知道为什么。如果我从网上获取一个示例并将其放入我的代码中,则输出工作正常 - 但是当我尝试使用我的数据时它不会输出。
示例代码是..
library(plotly)
labels = c("A1", "A2", "A3", "A4", "A5", "B1", "B2")
parents = c("", "A1", "A2", "A3", "A4", "", "B1")
values = c("11", "12", "13", "14", "15", "20", "30")
fig <- plot_ly(
type="treemap",
labels=labels,
parents=parents,
values=values,
marker=list(colorscale='Reds'))
fig
我使用的数据源是数据框,当我将数据源应用于上述示例时,它根本不起作用。所以,我只能假设它是我的数据框,我不知道为什么,因为我已经尝试了我所知道的一切。
我的数据代码..
Continents_tmap <- df1 %>%
group_by(Continent,Country.x) %>%
summarise(Deaths = sum(Deaths))## %>%
Continents_tmap <- data.frame(Continents_tmap)
labels <- Continents_tmap$Country.x
parents <- Continents_tmap$Continent
values <- Continents_tmap$Deaths
我的用户界面代码..
tabPanel( "TreeMap", plotlyOutput("tmap1")
)
我的服务器端代码....
output$tmap1 <- renderPlotly({
plot_ly(
type="treemap",
labels=labels,
parents=parents,
values=values,
marker=list(colorscale='Reds'))
})
问候
我让它使用 highchart 工作,但仍然没有在情节上 - 我的 highchart 代码是
output$tmap1 <- renderHighchart({
Continents_tmap %>%
filter(Continent == input$continent_2) %>%
group_by(Country.x) %>%
summarise(pts = sum(Deaths), fgpct = sum(Deaths)) %>%
hchart("treemap",
hcaes(
name = Country.x,
value = pts,
color = fgpct
)) %>%
hc_title(text = "Continent- Country Deaths") %>%
hc_subtitle(text = "Deaths Rating")
})
解决方案
推荐阅读
- android - Google MLkit 和其他库中对象/面部标注的准确性低
- c++ - 如何在 C++ 中检索矩阵的每个向量的第一个元素?
- spring - 在这个 Pom.xml 中找不到错误
- linux - 如何找到现在启动的 linux Image 名称
- kotlin-multiplatform - 如何为 iOS 制作多模块 kotlin 多平台库?
- php - 防止 WooCommerce 订单状态从/到特定状态更改
- c++ - 输出一个 200,000 位的巨大数字
- regex - Discord 标记正则表达式验证 Google 表单
- python - 如何为多图布局调整 relplot Seaborn 子图之间的空间
- flutter - 使用颤振 2.0.0 构建旧项目的问题