索引值的热图样式可视化
•浏览 1
Heat map style visualize of index values
我想用一个色标来可视化/绘制数据,代表 GIC.Fish 和 GIC 中的值。按 Dive.Number 缩放列。这有点像相关矩阵或热图,除了 Fish 和 Zoop 值彼此不相关,而是与潜水次数相关。以下数据是数据帧"temp"。
Dive.Number GIC.Fish GIC.Zoop
[1,] 1 0.83 0.37
[2,] 2 0.88 0.41
[3,] 3 0.98 0.57
[4,] 4 0.90 0.43
[5,] 5 1.00 0.58
[6,] 6 0.92 0.44
[7,] 7 0.71 0.33
[8,] 8 0.99 0.55
[9,] 9 0.94 0.47
[10,] 10 0.95 0.48
[11,] 11 0.91 0.44
[12,] 12 0.96 0.50
[13,] 13 0.86 0.39
[14,] 14 0.94 0.47
[15,] 15 0.91 0.43
[16,] 16 0.89 0.41
[17,] 17 0.92 0.45
[18,] 18 0.94 0.47
[19,] 19 1.00 0.59
[20,] 20 0.96 0.53
[21,] 21 0.96 0.52
[22,] 22 1.00 0.68
[23,] 23 0.99 0.73
[24,] 24 0.98 0.77
[25,] 25 0.96 0.80
[26,] 26 0.83 0.98
[27,] 27 0.72 1.00
[28,] 28 0.98 0.77
[29,] 29 0.44 0.73
[30,] 30 0.29 0.44
[31,] 31 0.31 0.48
[32,] 32 0.64 0.97
[33,] 33 0.08 0.04
[34,] 34 0.09 0.05
[35,] 35 0.61 0.96
[36,] 36 0.36 0.59 p<-ggplot(temp, aes(x=GIC.Fish, y=Dive.Number, fill=GIC.Fish))+
geom_tile() +
scale_fill_gradient2(midpoint=.5, low="blue", high="red") +
guides(fill=FALSE)setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
as.matrix(temp)
plot.table(temp, highlight=TRUE, colorbar=TRUE)dat$Dive.Number <- factor(dat$Dive.Number)
library(reshape2)
dat.m <- melt(dat, variable.name ="GIC.type", value.name ="GIC")
p <- ggplot(dat.m, aes(GIC, Dive.Number)) + geom_point(aes(colour = GIC)) +
scale_colour_gradient(low ="blue", high ="red") +
facet_wrap(~GIC.type)
pp <- ggplot(dat.m, aes(GIC.type, Dive.Number)) + geom_tile(aes(fill = GIC)) +
scale_fill_gradient(low ="blue", high ="red")plot(GIC.Fish ~ GIC.Zoop, data=dat, ylim=c(0,1.1) )
with(dat, lines(GIC.Fish ~ GIC.Zoop) )
with(dat, text(GIC.Zoop, GIC.Fish+.05, labels=Dive.Number ,
col= colorRampPalette( c("#FFFFD4","#FED98E","#FE9929",
"#D95F0E","#993404"), space ="Lab")(36)[Dive.Number]) )c("#00FFD4","#00D98E","#880088","#D900ff","#993404")
这段代码让我有点接近,但只有一列相关数据。
Dive.Number GIC.Fish GIC.Zoop
[1,] 1 0.83 0.37
[2,] 2 0.88 0.41
[3,] 3 0.98 0.57
[4,] 4 0.90 0.43
[5,] 5 1.00 0.58
[6,] 6 0.92 0.44
[7,] 7 0.71 0.33
[8,] 8 0.99 0.55
[9,] 9 0.94 0.47
[10,] 10 0.95 0.48
[11,] 11 0.91 0.44
[12,] 12 0.96 0.50
[13,] 13 0.86 0.39
[14,] 14 0.94 0.47
[15,] 15 0.91 0.43
[16,] 16 0.89 0.41
[17,] 17 0.92 0.45
[18,] 18 0.94 0.47
[19,] 19 1.00 0.59
[20,] 20 0.96 0.53
[21,] 21 0.96 0.52
[22,] 22 1.00 0.68
[23,] 23 0.99 0.73
[24,] 24 0.98 0.77
[25,] 25 0.96 0.80
[26,] 26 0.83 0.98
[27,] 27 0.72 1.00
[28,] 28 0.98 0.77
[29,] 29 0.44 0.73
[30,] 30 0.29 0.44
[31,] 31 0.31 0.48
[32,] 32 0.64 0.97
[33,] 33 0.08 0.04
[34,] 34 0.09 0.05
[35,] 35 0.61 0.96
[36,] 36 0.36 0.59 p<-ggplot(temp, aes(x=GIC.Fish, y=Dive.Number, fill=GIC.Fish))+
geom_tile() +
scale_fill_gradient2(midpoint=.5, low="blue", high="red") +
guides(fill=FALSE)setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
as.matrix(temp)
plot.table(temp, highlight=TRUE, colorbar=TRUE)dat$Dive.Number <- factor(dat$Dive.Number)
library(reshape2)
dat.m <- melt(dat, variable.name ="GIC.type", value.name ="GIC")
p <- ggplot(dat.m, aes(GIC, Dive.Number)) + geom_point(aes(colour = GIC)) +
scale_colour_gradient(low ="blue", high ="red") +
facet_wrap(~GIC.type)
pp <- ggplot(dat.m, aes(GIC.type, Dive.Number)) + geom_tile(aes(fill = GIC)) +
scale_fill_gradient(low ="blue", high ="red")plot(GIC.Fish ~ GIC.Zoop, data=dat, ylim=c(0,1.1) )
with(dat, lines(GIC.Fish ~ GIC.Zoop) )
with(dat, text(GIC.Zoop, GIC.Fish+.05, labels=Dive.Number ,
col= colorRampPalette( c("#FFFFD4","#FED98E","#FE9929",
"#D95F0E","#993404"), space ="Lab")(36)[Dive.Number]) )c("#00FFD4","#00D98E","#880088","#D900ff","#993404")
这让我更接近了,但我不想要 Dive Number 列,也不想在单元格中显示实际值,我希望能够更改颜色栏中的颜色。
Dive.Number GIC.Fish GIC.Zoop
[1,] 1 0.83 0.37
[2,] 2 0.88 0.41
[3,] 3 0.98 0.57
[4,] 4 0.90 0.43
[5,] 5 1.00 0.58
[6,] 6 0.92 0.44
[7,] 7 0.71 0.33
[8,] 8 0.99 0.55
[9,] 9 0.94 0.47
[10,] 10 0.95 0.48
[11,] 11 0.91 0.44
[12,] 12 0.96 0.50
[13,] 13 0.86 0.39
[14,] 14 0.94 0.47
[15,] 15 0.91 0.43
[16,] 16 0.89 0.41
[17,] 17 0.92 0.45
[18,] 18 0.94 0.47
[19,] 19 1.00 0.59
[20,] 20 0.96 0.53
[21,] 21 0.96 0.52
[22,] 22 1.00 0.68
[23,] 23 0.99 0.73
[24,] 24 0.98 0.77
[25,] 25 0.96 0.80
[26,] 26 0.83 0.98
[27,] 27 0.72 1.00
[28,] 28 0.98 0.77
[29,] 29 0.44 0.73
[30,] 30 0.29 0.44
[31,] 31 0.31 0.48
[32,] 32 0.64 0.97
[33,] 33 0.08 0.04
[34,] 34 0.09 0.05
[35,] 35 0.61 0.96
[36,] 36 0.36 0.59 p<-ggplot(temp, aes(x=GIC.Fish, y=Dive.Number, fill=GIC.Fish))+
geom_tile() +
scale_fill_gradient2(midpoint=.5, low="blue", high="red") +
guides(fill=FALSE)setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
as.matrix(temp)
plot.table(temp, highlight=TRUE, colorbar=TRUE)dat$Dive.Number <- factor(dat$Dive.Number)
library(reshape2)
dat.m <- melt(dat, variable.name ="GIC.type", value.name ="GIC")
p <- ggplot(dat.m, aes(GIC, Dive.Number)) + geom_point(aes(colour = GIC)) +
scale_colour_gradient(low ="blue", high ="red") +
facet_wrap(~GIC.type)
pp <- ggplot(dat.m, aes(GIC.type, Dive.Number)) + geom_tile(aes(fill = GIC)) +
scale_fill_gradient(low ="blue", high ="red")plot(GIC.Fish ~ GIC.Zoop, data=dat, ylim=c(0,1.1) )
with(dat, lines(GIC.Fish ~ GIC.Zoop) )
with(dat, text(GIC.Zoop, GIC.Fish+.05, labels=Dive.Number ,
col= colorRampPalette( c("#FFFFD4","#FED98E","#FE9929",
"#D95F0E","#993404"), space ="Lab")(36)[Dive.Number]) )c("#00FFD4","#00D98E","#880088","#D900ff","#993404")
这是你所追求的吗?假设您的数据是 dat:
Dive.Number GIC.Fish GIC.Zoop
[1,] 1 0.83 0.37
[2,] 2 0.88 0.41
[3,] 3 0.98 0.57
[4,] 4 0.90 0.43
[5,] 5 1.00 0.58
[6,] 6 0.92 0.44
[7,] 7 0.71 0.33
[8,] 8 0.99 0.55
[9,] 9 0.94 0.47
[10,] 10 0.95 0.48
[11,] 11 0.91 0.44
[12,] 12 0.96 0.50
[13,] 13 0.86 0.39
[14,] 14 0.94 0.47
[15,] 15 0.91 0.43
[16,] 16 0.89 0.41
[17,] 17 0.92 0.45
[18,] 18 0.94 0.47
[19,] 19 1.00 0.59
[20,] 20 0.96 0.53
[21,] 21 0.96 0.52
[22,] 22 1.00 0.68
[23,] 23 0.99 0.73
[24,] 24 0.98 0.77
[25,] 25 0.96 0.80
[26,] 26 0.83 0.98
[27,] 27 0.72 1.00
[28,] 28 0.98 0.77
[29,] 29 0.44 0.73
[30,] 30 0.29 0.44
[31,] 31 0.31 0.48
[32,] 32 0.64 0.97
[33,] 33 0.08 0.04
[34,] 34 0.09 0.05
[35,] 35 0.61 0.96
[36,] 36 0.36 0.59 p<-ggplot(temp, aes(x=GIC.Fish, y=Dive.Number, fill=GIC.Fish))+
geom_tile() +
scale_fill_gradient2(midpoint=.5, low="blue", high="red") +
guides(fill=FALSE)setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
as.matrix(temp)
plot.table(temp, highlight=TRUE, colorbar=TRUE)dat$Dive.Number <- factor(dat$Dive.Number)
library(reshape2)
dat.m <- melt(dat, variable.name ="GIC.type", value.name ="GIC")
p <- ggplot(dat.m, aes(GIC, Dive.Number)) + geom_point(aes(colour = GIC)) +
scale_colour_gradient(low ="blue", high ="red") +
facet_wrap(~GIC.type)
pp <- ggplot(dat.m, aes(GIC.type, Dive.Number)) + geom_tile(aes(fill = GIC)) +
scale_fill_gradient(low ="blue", high ="red")plot(GIC.Fish ~ GIC.Zoop, data=dat, ylim=c(0,1.1) )
with(dat, lines(GIC.Fish ~ GIC.Zoop) )
with(dat, text(GIC.Zoop, GIC.Fish+.05, labels=Dive.Number ,
col= colorRampPalette( c("#FFFFD4","#FED98E","#FE9929",
"#D95F0E","#993404"), space ="Lab")(36)[Dive.Number]) )c("#00FFD4","#00D98E","#880088","#D900ff","#993404")
编辑
根据您的评论,也许这更像您的想象:
Dive.Number GIC.Fish GIC.Zoop
[1,] 1 0.83 0.37
[2,] 2 0.88 0.41
[3,] 3 0.98 0.57
[4,] 4 0.90 0.43
[5,] 5 1.00 0.58
[6,] 6 0.92 0.44
[7,] 7 0.71 0.33
[8,] 8 0.99 0.55
[9,] 9 0.94 0.47
[10,] 10 0.95 0.48
[11,] 11 0.91 0.44
[12,] 12 0.96 0.50
[13,] 13 0.86 0.39
[14,] 14 0.94 0.47
[15,] 15 0.91 0.43
[16,] 16 0.89 0.41
[17,] 17 0.92 0.45
[18,] 18 0.94 0.47
[19,] 19 1.00 0.59
[20,] 20 0.96 0.53
[21,] 21 0.96 0.52
[22,] 22 1.00 0.68
[23,] 23 0.99 0.73
[24,] 24 0.98 0.77
[25,] 25 0.96 0.80
[26,] 26 0.83 0.98
[27,] 27 0.72 1.00
[28,] 28 0.98 0.77
[29,] 29 0.44 0.73
[30,] 30 0.29 0.44
[31,] 31 0.31 0.48
[32,] 32 0.64 0.97
[33,] 33 0.08 0.04
[34,] 34 0.09 0.05
[35,] 35 0.61 0.96
[36,] 36 0.36 0.59 p<-ggplot(temp, aes(x=GIC.Fish, y=Dive.Number, fill=GIC.Fish))+
geom_tile() +
scale_fill_gradient2(midpoint=.5, low="blue", high="red") +
guides(fill=FALSE)setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
as.matrix(temp)
plot.table(temp, highlight=TRUE, colorbar=TRUE)dat$Dive.Number <- factor(dat$Dive.Number)
library(reshape2)
dat.m <- melt(dat, variable.name ="GIC.type", value.name ="GIC")
p <- ggplot(dat.m, aes(GIC, Dive.Number)) + geom_point(aes(colour = GIC)) +
scale_colour_gradient(low ="blue", high ="red") +
facet_wrap(~GIC.type)
pp <- ggplot(dat.m, aes(GIC.type, Dive.Number)) + geom_tile(aes(fill = GIC)) +
scale_fill_gradient(low ="blue", high ="red")plot(GIC.Fish ~ GIC.Zoop, data=dat, ylim=c(0,1.1) )
with(dat, lines(GIC.Fish ~ GIC.Zoop) )
with(dat, text(GIC.Zoop, GIC.Fish+.05, labels=Dive.Number ,
col= colorRampPalette( c("#FFFFD4","#FED98E","#FE9929",
"#D95F0E","#993404"), space ="Lab")(36)[Dive.Number]) )c("#00FFD4","#00D98E","#880088","#D900ff","#993404")
(警告。不是 ggplot2 创作。我从来没有学会用那个模型思考。)我想你可能正在寻找一个可以用颜色编码的二维密度地图,所以我绘制了 GIC.Zoop 和 GIC.Fish。从该结果生成密度图的概念似乎不符合数据的模式,因此我画了线以查看是否存在明显的序列。然后我用 Dive.Number 标记点,用颜色编码:
Dive.Number GIC.Fish GIC.Zoop
[1,] 1 0.83 0.37
[2,] 2 0.88 0.41
[3,] 3 0.98 0.57
[4,] 4 0.90 0.43
[5,] 5 1.00 0.58
[6,] 6 0.92 0.44
[7,] 7 0.71 0.33
[8,] 8 0.99 0.55
[9,] 9 0.94 0.47
[10,] 10 0.95 0.48
[11,] 11 0.91 0.44
[12,] 12 0.96 0.50
[13,] 13 0.86 0.39
[14,] 14 0.94 0.47
[15,] 15 0.91 0.43
[16,] 16 0.89 0.41
[17,] 17 0.92 0.45
[18,] 18 0.94 0.47
[19,] 19 1.00 0.59
[20,] 20 0.96 0.53
[21,] 21 0.96 0.52
[22,] 22 1.00 0.68
[23,] 23 0.99 0.73
[24,] 24 0.98 0.77
[25,] 25 0.96 0.80
[26,] 26 0.83 0.98
[27,] 27 0.72 1.00
[28,] 28 0.98 0.77
[29,] 29 0.44 0.73
[30,] 30 0.29 0.44
[31,] 31 0.31 0.48
[32,] 32 0.64 0.97
[33,] 33 0.08 0.04
[34,] 34 0.09 0.05
[35,] 35 0.61 0.96
[36,] 36 0.36 0.59 p<-ggplot(temp, aes(x=GIC.Fish, y=Dive.Number, fill=GIC.Fish))+
geom_tile() +
scale_fill_gradient2(midpoint=.5, low="blue", high="red") +
guides(fill=FALSE)setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
as.matrix(temp)
plot.table(temp, highlight=TRUE, colorbar=TRUE)dat$Dive.Number <- factor(dat$Dive.Number)
library(reshape2)
dat.m <- melt(dat, variable.name ="GIC.type", value.name ="GIC")
p <- ggplot(dat.m, aes(GIC, Dive.Number)) + geom_point(aes(colour = GIC)) +
scale_colour_gradient(low ="blue", high ="red") +
facet_wrap(~GIC.type)
pp <- ggplot(dat.m, aes(GIC.type, Dive.Number)) + geom_tile(aes(fill = GIC)) +
scale_fill_gradient(low ="blue", high ="red")plot(GIC.Fish ~ GIC.Zoop, data=dat, ylim=c(0,1.1) )
with(dat, lines(GIC.Fish ~ GIC.Zoop) )
with(dat, text(GIC.Zoop, GIC.Fish+.05, labels=Dive.Number ,
col= colorRampPalette( c("#FFFFD4","#FED98E","#FE9929",
"#D95F0E","#993404"), space ="Lab")(36)[Dive.Number]) )c("#00FFD4","#00D98E","#880088","#D900ff","#993404")
您可以尝试颜色过渡。此颜色矢量提供更多对比度:
Dive.Number GIC.Fish GIC.Zoop
[1,] 1 0.83 0.37
[2,] 2 0.88 0.41
[3,] 3 0.98 0.57
[4,] 4 0.90 0.43
[5,] 5 1.00 0.58
[6,] 6 0.92 0.44
[7,] 7 0.71 0.33
[8,] 8 0.99 0.55
[9,] 9 0.94 0.47
[10,] 10 0.95 0.48
[11,] 11 0.91 0.44
[12,] 12 0.96 0.50
[13,] 13 0.86 0.39
[14,] 14 0.94 0.47
[15,] 15 0.91 0.43
[16,] 16 0.89 0.41
[17,] 17 0.92 0.45
[18,] 18 0.94 0.47
[19,] 19 1.00 0.59
[20,] 20 0.96 0.53
[21,] 21 0.96 0.52
[22,] 22 1.00 0.68
[23,] 23 0.99 0.73
[24,] 24 0.98 0.77
[25,] 25 0.96 0.80
[26,] 26 0.83 0.98
[27,] 27 0.72 1.00
[28,] 28 0.98 0.77
[29,] 29 0.44 0.73
[30,] 30 0.29 0.44
[31,] 31 0.31 0.48
[32,] 32 0.64 0.97
[33,] 33 0.08 0.04
[34,] 34 0.09 0.05
[35,] 35 0.61 0.96
[36,] 36 0.36 0.59 p<-ggplot(temp, aes(x=GIC.Fish, y=Dive.Number, fill=GIC.Fish))+
geom_tile() +
scale_fill_gradient2(midpoint=.5, low="blue", high="red") +
guides(fill=FALSE)setInternet2(TRUE)
con = gzcon(url('http://www.systematicportfolio.com/sit.gz', 'rb'))
source(con)
close(con)
as.matrix(temp)
plot.table(temp, highlight=TRUE, colorbar=TRUE)dat$Dive.Number <- factor(dat$Dive.Number)
library(reshape2)
dat.m <- melt(dat, variable.name ="GIC.type", value.name ="GIC")
p <- ggplot(dat.m, aes(GIC, Dive.Number)) + geom_point(aes(colour = GIC)) +
scale_colour_gradient(low ="blue", high ="red") +
facet_wrap(~GIC.type)
pp <- ggplot(dat.m, aes(GIC.type, Dive.Number)) + geom_tile(aes(fill = GIC)) +
scale_fill_gradient(low ="blue", high ="red")plot(GIC.Fish ~ GIC.Zoop, data=dat, ylim=c(0,1.1) )
with(dat, lines(GIC.Fish ~ GIC.Zoop) )
with(dat, text(GIC.Zoop, GIC.Fish+.05, labels=Dive.Number ,
col= colorRampPalette( c("#FFFFD4","#FED98E","#FE9929",
"#D95F0E","#993404"), space ="Lab")(36)[Dive.Number]) )c("#00FFD4","#00D98E","#880088","#D900ff","#993404")