作者:卓慧大美女_502 | 来源:互联网 | 2023-05-18 18:37
Immakingaheatmapusingggplot2.Iwanttoputthevaluesthemselvesinsidetheheatmapboxes,bu
I'm making a heatmap using ggplot2. I want to put the values themselves inside the heatmap boxes, but I'm finding that while that works okay when not faceting, as soon as I facet, the numbers go to all the wrong boxes - see attached pictures. Any tips on how to make the numbers stay in the right boxes when faceting?
我正在用ggplot2做一个热图。我想把这些值放到加热地图盒里,但是我发现当我不面朝时,当我看到这些数字的时候,这些数字就会出现在所有错误的盒子里——见附件图片。关于如何让数字保持在正确的盒子里的任何提示?
ALso, some other minor questions: how to change the tile sizes when and when not faceting; changing the color of the value text in the boxes (<- tried the obvious solutions but don't seem to work...)
另外,还有一些次要问题:如何在不使用面板的情况下改变尺寸大小;改变框中值文本的颜色(<-尝试了明显的解决方案,但似乎没有效果…)
Thanks everyone!
谢谢大家!
Code (Can see where the facet is commented out):
代码(可以看到facet被注释掉的地方):
fpdata<-read.csv("fp.csv",header=T)
fpdata$Dimension=factor(fpdata$Dimension,levels(fpdata$Dimension)[c(4,1,3,2,5)])
fpdata$Trait=factor(fpdata$Trait,levels(fpdata$Trait)[c(22,15,16,3,4,9,21,20,10,14,6,2,1,
13,8,11,12,17,24,25,18,5,23,19,7)])
matrix <- melt(fpdata)
matrix
matrix$value[is.na(matrix$value)] <- 2
matrix
p3 <- ggplot(data = matrix, aes(variable, Trait, fill = value))+
geom_tile(color = "white")+
scale_fill_gradient2(low = "blue", high = "firebrick", mid = "deepskyblue",
midpoint = 0.6, limit = c(0.6,1), space = "Lab",
name="Factor Loadings")+labs(x = "Reduction #")+
geom_text(aes(label=ifelse(matrix$value<2,matrix$value," ")))
##+facet_grid(~Dimension, scale="free")
p3 <- p3 +
theme (axis.title.x = element_text(size=20),
axis.title.y = element_text(size=20),
axis.text.x = element_text(angle = 0, vjust = 1, size = 14, hjust = 0.5),
axis.text.y = element_text(size=16),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
legend.title = element_text(size=16),
legend.text = element_text(size=14),
strip.text.x = element_text(size=13, face="bold"))+coord_fixed()
p3
Heat Map without Facet
热图不方面
Heat Map with Facet
热量地图方面
1 个解决方案