对于一份有关核废料问题的研究论文,我试图通过以下方式制作一个“ 属性”(在X中)与“ 模型”(在Y中)的热图。为每个(X,Y)对指定一些离散值(以Z表示,着色)。我针对不同的“ 场景”进行了所有这些操作。
我的数据集如下:
head(tspa)
ï..Scenarios Components
1 Total System (10,000 years) Unsaturated Zone Flow
2 Total System (10,000 years) Unsaturated Zone Flow
3 Total System (10,000 years) Unsaturated Zone Flow
4 Total System (10,000 years) Unsaturated Zone Flow
5 Total System (10,000 years) Unsaturated Zone Flow
6 Total System (10,000 years) EBS Environment
Models WTYPE WCOMP WRAD WPROP WTREAT WFORM
1 Site-Scale UZ Flow 0 0 0 0 0 0
2 Infiltration Analysis 0 0 0 0 0 0
3 Climate Analysis 0 0 0 0 0 0
4 Drift Seepage 0 0 0 0 0 0
5 Drift Wall Condensation 0 0 0 0 0 0
6 EBS Thermal-Hydrologic Environment 0 0 0 0 0 1
WPACKAGE STRUCT OVERPACK ROCK GEOPHYS GEOCHEM HYDRO BIO SEISM VOLCA
1 0 0 0 1 0 0 1 0 0 0
2 0 0 0 1 0 0 1 0 0 0
3 0 0 0 0 0 0 0 0 0 0
4 0 1 0 1 0 0 1 0 0 0
5 0 1 0 0 0 0 1 0 0 0
6 1 1 0 0 1 0 1 0 0 0
CLIMA HUMAN
1 0 0
2 0 0
3 1 0
4 0 0
5 0 0
6 0 0
数据注释:
这是我目前的“有效”脚本:
# Heatmap 2
# Load dependancies
library(tidyr) # consistent data.frame cleaning
library(ggplot2) # base plots are for Coursera professors
library(gridExtra) # a helper for arranging individual ggplot objects
library(ggthemes) # has a clean theme for ggplot2
# Read data and format for heatmap
tspa <- read.csv(file="tspa3.csv",header=TRUE,sep=",")
tspa.long <- gather(data = tspa, key = Attributes.name, value = Attributes.value, -c(1:3))
gg <- ggplot(data = tspa.long, mapping = aes(x = factor(Attributes.name, levels = unique(Attributes.name)),
y = factor(Models, levels = unique(Models)),
fill = Attributes.value), stat="identity")
gg <- gg + facet_wrap(~ ï..Scenarios , ncol=6)
gg <- gg + geom_tile(color="grey", size=0.1)
gg <- gg + coord_equal()
gg <- gg + scale_y_discrete(limits = rev(levels(tspa.long$Models)))
gg <- gg + labs(x=NULL, y=NULL, title=NULL)
gg <- gg + theme(plot.title=element_text(hjust=0))
gg <- gg + theme(axis.ticks=element_blank())
gg <- gg + theme(axis.text=element_text(size=7))
gg <- gg + theme(axis.text.x=element_text(angle=90))
gg <- gg + theme(legend.position = "none")
gg <- gg + scale_fill_gradient2(low="white", high=muted("red"), limits=range(tspa.long$Attributes.value))
gg
此脚本仅按方案生成带有以下构面的以下热图:Result
但是,即使在广泛搜索该主题并尝试使用various approaches(ggplot2,过热,heatmaply,heatmap ...)之后,我仍然无法准确绘制所需的内容。
这就是我所苦恼的:
由于我是R语言的新手,并且通常来说是数据可视化的,所以我对R代码的工作原理仍然知之甚少。我怀疑我可能不得不使用各种数据帧或使用IF / THEN循环,但是我不知道该怎么做。
我对如何为数据集和脚本使用哪些体系结构和功能有一般性的指导意见是可以的,以后我可以自己弄清楚。谢谢!