显示文本时geom_tile的晶格等价物

时间:2014-08-06 15:28:37

标签: r ggplot2 heatmap lattice

当我想要将因子水平/地图填充显示到文本时,我有兴趣知道ggplot2中是否存在替代geom_tile()的格子。示例数据框(df)遵循......

Gene Sample Mutation
A1    2       Missense
A2    2       WT
A1    3       Missense
A2    3       Missense

使用ggplot2这是微不足道的

qplot(df, y=Gene, x=Sample, fill=Mutation, geom='tile')

格子相当于什么? (我对此感兴趣,因为在绘图之间的ggplot2中的轴对齐是复杂且当前很麻烦)。

df <- structure(list(Gene = structure(c(1L, 2L, 1L, 2L), .Label = c("A1",  "A2"), class = "factor"), 
                     Sample = structure(c(1L, 1L, 2L, 2L ), .Label = c("2", "3"), class = "factor"), 
                     Mutation = structure(c(1L,  2L, 1L, 1L), .Label = c("Missense", "WT"), class = "factor")), .Names = c("Gene",  "Sample", "Mutation"), row.names = c(NA, -4L), class = "data.frame")

1 个答案:

答案 0 :(得分:1)

查看格子中的levelplot()函数,例如

library("lattice")
df <- transform(df, Sample = factor(Sample))
levelplot(Mutation ~ Gene * Sample, data = df)

你需要自己计算色标键。