-1

如何可视化 3 维矩阵?

  • 第一个维度是 x 坐标 = 不同的大学
  • 第二个维度是 y 坐标 = 学科或专业(物理、数学、艺术......)
  • 第三维是颜色=不同的年份
  • 圆圈大小=相应学科/大学的论文数量
4

4 回答 4

2

使用@alexis_laz 的示例数据:

将数据重新组织为 -ggplot2友好的:

library("reshape2")
mm <- melt(mat)

加载包(包括viridis更漂亮的颜色):

library("ggplot2"); theme_set(theme_bw())
library("viridis")

按要求绘制(使用大小范围,直到你喜欢结果):

ggplot(mm)+
    geom_point(aes(x=univ,y=dis,colour=yr, size=value))+
        scale_color_viridis()+
            scale_size(range=c(2,18))

在此处输入图像描述 但是,ggplot2它为您提供了很大的自由度,我建议您注意Cleveland 层次结构,它表示很难区分按大小绘制的定量特征。根据您最感兴趣的比较,您可以尝试以下操作:

library(grid)  ## for unit(), to squash panels
ggplot(mm,aes(x=yr,y=value,colour=univ))+
    geom_point()+geom_line()+
        facet_wrap(~dis)+
            scale_color_brewer(palette="Set1")+
                theme(panel.margin=unit(0,"lines"))

在此处输入图像描述

(当然,数据看起来很乱,因为它们是随机生成的......)

于 2015-10-16T17:00:31.727 回答
1

假设您有如下数据:

set.seed(911)
mat = tapply(sample(0:200, 5*10*16, TRUE, prob = rev(prop.table(0:200))), 
             expand.grid(univ = paste("univ", 1:5, sep = ""), 
                         dis = paste("dis", 1:10, sep = ""), 
                         yr = 2000:2015), 
             I)

您可以尝试以下方式:

#convert to easy to manipulate format            
DF = as.data.frame(as.table(mat))

#x
xlvs = unique(DF$univ)
xx = match(DF$univ, xlvs)

#y
ylvs = unique(DF$dis)
yy = match(DF$dis, ylvs)

#colors
collvs = unique(DF$yr)
cols = terrain.colors(length(collvs), alpha = 0.75)[match(DF$yr, collvs)]

#sizes
maxcex = 5
cexs = (DF$Freq * maxcex) / max(DF$Freq)


layout(matrix(c(1, 1, 1, 1, 1, 2), nrow = 1))
#plot 1
plot(xx, yy, col = cols, cex = cexs, pch = 19, axes = FALSE, frame.plot = TRUE)
axis(1, at = seq_along(xlvs), labels = xlvs)
axis(2, at = seq_along(ylvs), labels = ylvs, las = 1)   

#plot 2 
par(mar = c(1, 1, 1, 4))
fill = terrain.colors(length(collvs) * 9, alpha = 0.75)  #higher 'resolution' of plot
barplot(matrix(rep_len(1L, length(fill))), col = fill, border = NA, axes = FALSE)
axis(4, at = seq(1, length(fill), 9) + 4, labels = collvs, las = 1) 

这使: 在此处输入图像描述

于 2015-10-16T16:10:01.007 回答
0

====================数据============

num univ dis 论文引用年份

1 北京物理 193 4555 2005

2 北京物理 197 2799 2006

3 北京物理 240 2664 2007

4 北京物理 200 3191 2008

5 北京物理 268 2668 2009

6 北京物理 249 2300 2010

7 北京物理 262 2080 2011

8 北京物理 230 2371 2012

9 北京物理 309 1367 2013

10 北京物理 284 615 2014

11 北京化学143 1650 2005

12 北京化学 149 2379 2006

13 北京化学 190 2566 2007

14 北京化学147 1888 2008

15北京化学184 2146 2009

16北京化学214 2568 2010

---

  mm <- read.table("data.txt", header = TRUE, sep = "", encoding='UTF-8')

  library("ggplot2")
  theme_set(theme_bw())
  library("viridis")

  ggplot(mm)+
  geom_point(aes(x=univ,y=dis,colour=year, size=paper))+
  scale_color_viridis()+
  scale_size(range=c(2,18))

==================================================== ======== 但是,年份变为 2005.0 2007.5 2010.0 2012.5 在此处输入图像描述

于 2015-10-17T03:52:09.280 回答
0

你可以做类似的事情

fulldata <- read.csv(...) # your data.frame
colors=c(...) # create your color array here
plot(NULL,xlim=1:9,ylim=1:20) # just to define the area of the graph
abline(v=1:9,h=1:20) # the axis inside the graph
for (y in 2013:2002) {
    data <- fulldata[which(fulldata$year == y),]
    circle(data$university,data$discipline,size=data$numberofpapers,col=year[y-2001])
}
axis(...) # or mtext or whatever to put the labels on the axis
于 2015-10-16T11:43:23.710 回答