我正在使用 geom_tile() 制作热图。我想根据聚类订购y轴(sp)(实际数据有大约200条sp记录)。
sp <- c("sp1","sp1","sp1","sp2","sp2","sp2","sp3","sp3","sp3","sp4","sp4","sp4","sp5","sp5","sp5")
category <- c("a","b","c","a","b","c","a","b","c","a","b","c","a","b","c")
count <- c(1,2,1,1,4,2,3,1,3,1,4,5,2,5,1)
d <- data.frame(cbind(sp, category, count))
t <- d %>%
ggplot(aes(category, sp))+
geom_tile(aes(fill = as.numeric(count)))+
scale_fill_gradient(low = "white", high = "red")
plot(t)