You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

高维分类变量可视化难题:多维度项目数据可视化方案咨询

针对多关联分类变量的可视化方案建议

结合你数据集的特点(300个项目、多分类变量、单项目多区域/机构关联),以下是几个针对性的可视化方案:

1. 展示项目-区域-机构的多对多关联

桑基图(Sankey Diagram)

清晰呈现项目、区域、机构之间的关联流动,适合直观看到哪些项目关联了哪些区域和机构,以及关联的频次。用networkD3实现:

library(networkD3)
library(dplyr)

# 提取项目与区域、项目与机构的唯一关联
project_region <- data_lon_lat %>% distinct(ID, Region) %>% rename(source = ID, target = Region)
project_inst <- data_lon_lat %>% distinct(ID, Institution) %>% rename(source = ID, target = Institution)

# 整理为桑基图所需格式
links <- bind_rows(project_region, project_inst) %>% 
  mutate(value = 1) %>% 
  group_by(source, target) %>% summarise(value = n())

nodes <- data.frame(name = unique(c(links$source, links$target)))
links$source <- match(links$source, nodes$name) - 1
links$target <- match(links$target, nodes$name) - 1

# 生成桑基图
sankeyNetwork(Links = links, Nodes = nodes, Source = "source", 
              Target = "target", Value = "value", NodeID = "name",
              fontSize = 12, nodeWidth = 30)

和弦图(Chord Diagram)

如果重点关注区域和机构之间的直接关联(无需通过项目),可以用circlize绘制和弦图,展示不同区域与机构的协作频次:

library(circlize)

# 统计区域与机构的关联项目数
region_inst_counts <- data_lon_lat %>% 
  distinct(Region, Institution, ID) %>% 
  group_by(Region, Institution) %>% 
  summarise(count = n())

# 转换为矩阵格式
inst_region_matrix <- xtabs(count ~ Institution + Region, data = region_inst_counts)

# 绘制和弦图
chordDiagram(inst_region_matrix, annotationTrack = "grid", 
             preAllocateTracks = list(track.height = max(strwidth(colnames(inst_region_matrix)))))

2. 优化区域维度的可视化

带机构分组的堆叠条形图

解决原条形图信息量单一的问题,通过堆叠展示每个区域内参与项目的机构分布(只保留Top5机构避免过度拥挤):

library(ggplot2)

# 统计每个区域-机构组合的项目数
region_inst_projects <- data_lon_lat %>% 
  distinct(Region, Institution, ID) %>% 
  group_by(Region, Institution) %>% 
  summarise(project_count = n()) %>% 
  arrange(desc(project_count))

# 提取每个区域的Top5参与机构
region_top5_inst <- region_inst_projects %>% 
  group_by(Region) %>% 
  slice_max(project_count, n = 5)

ggplot(region_top5_inst, aes(x = reorder(Region, -project_count), y = project_count, fill = Institution)) +
  geom_col(position = "stack") +
  coord_flip() +
  theme_clean() +
  labs(x = "区域", y = "项目数量", fill = "参与机构")

增强交互的Leaflet地图

给地图添加动态弹窗,点击标记可查看该区域的项目总数、核心机构及影响领域,同时用标记大小区分项目数量:

library(leaflet)
library(htmltools)

# 按区域聚合数据,生成弹窗内容
region_agg <- data_lon_lat %>% 
  group_by(Region, lon, lat) %>% 
  summarise(
    total_projects = n_distinct(ID),
    top_institutions = paste(head(unique(Institution), 3), collapse = "<br>"),
    impact_areas = paste(unique(`impact area`), collapse = "<br>")
  )

# 绘制交互地图
leaflet(region_agg) %>% 
  addTiles() %>% 
  addCircleMarkers(
    lng = ~lon, lat = ~lat,
    radius = ~sqrt(total_projects)*3,  # 半径与项目数正相关
    popup = ~HTML(paste0(
      "<strong>区域:</strong> ", Region, "<br>",
      "<strong>项目总数:</strong> ", total_projects, "<br>",
      "<strong>核心机构:</strong><br>", top_institutions, "<br>",
      "<strong>影响领域:</strong><br>", impact_areas
    ))
  )

3. 处理高基数分类变量

旭日图(Sunburst Chart)

如果有多层分类(比如影响领域→区域→机构),用旭日图展示层级分布,用plotly实现:

library(plotly)

# 整理层级数据
sunburst_data <- data_lon_lat %>% 
  distinct(ID, `impact area`, Region, Institution) %>% 
  group_by(`impact area`, Region, Institution) %>% 
  summarise(count = n())

plot_ly(sunburst_data, ids = ~`impact area`, labels = ~Region, parents = ~`impact area`, values = ~count, type = 'sunburst') %>%
  layout(margin = list(l = 0, r = 0, b = 0, t = 0))

多维尺度分析(MDS)降维可视化

针对高基数变量(比如151个水平的机构),用MDS将机构间的关联相似性转换为二维坐标,展示机构的聚类情况:

library(ggplot2)
library(vegan)

# 构建机构-项目关联矩阵
inst_project_matrix <- xtabs(~Institution + ID, data = data_lon_lat)
# 计算机构间的Jaccard相似度
inst_dist <- vegdist(t(inst_project_matrix), method = "jaccard")
# MDS降维
inst_mds <- metaMDS(inst_dist, k = 2)

# 整理坐标并关联区域信息
inst_mds_df <- data.frame(
  Institution = rownames(inst_mds$points),
  x = inst_mds$points[,1],
  y = inst_mds$points[,2]
) %>% left_join(data_lon_lat %>% distinct(Institution, Region), by = "Institution")

ggplot(inst_mds_df, aes(x = x, y = y, color = Region, label = Institution)) +
  geom_point(size = 3) +
  geom_text(hjust = 0, vjust = 0, size = 2.5) +
  theme_minimal() +
  labs(title = "机构关联相似性分布(按区域分组)")

内容的提问来源于stack exchange,提问作者Lai Jatta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 12:18:19