获取geom_tile绘制正方形而不是矩形单元格
问题描述:
我试图使用ggplot
的geom_tile
生成heatmap
绘图。我的数据有比行多得多的行。获取geom_tile绘制正方形而不是矩形单元格
set.seed(1)
df <- data.frame(val=rnorm(100),gene=rep(letters[1:20],5),cell=c(sapply(LETTERS[1:5],function(l) rep(l,20))))
运行:
library(ggplot2)
ggplot(df,aes(y=gene,x=cell,fill=val))+geom_tile(color="white")
如何获得heatmap
细胞是对称的尺寸 - 方形而不是长方形(高度=宽度)?而不会扭曲图的尺寸。
但是,如果我的实际数据有更多行:df dan
但是...你_want_广场。我不确定你打算如何在没有漫长阴谋的情况下获得广场。你可以'coord_flip()'它(我会在尝试之前交换x和y,因为它是相同的事物,并且更容易记住)。或者你可以将它分成2,3,4个图,但保持相同的色阶。 – hrbrmstr