您好我正在尝试在属于class2的特定框上绘制对角线。 我懂了: Image1
我的数据集:
samples genes value class
sample1 geneA 0.52 class2
sample1 geneB 1 class1
sample1 geneC 1 class1
sample2 geneD 1 class1
sample2 geneB 1 class1
sample2 geneH 0.4 class2
sample2 geneC 1 class1
sample3 geneE 0.44 class2
sample3 geneF 0.34 class2
sample3 geneB 1 class1
sample3 geneI 0.65 class2
sample3 geneC 1 class1
sample4 geneB 0.72 class2
sample4 geneC 0.41 class2
sample5 geneG 1 class1
sample5 geneB 1 class1
sample5 geneC 1 class1
Class1标有包围方框的黄线。你能不能帮我弄清楚属于class2的盒子上的插入对角线。
我想这样:
谢谢, kumarr
答案 0 :(得分:0)
这是一种方法:
p <- ggplot(df, aes(x=genes,y=samples,fill=class)) + geom_tile()
p + geom_segment(
aes(x=xmin,xend=xmax,y=ymin,yend=ymax),
subset(ggplot_build(p)$data[[1]],fill=="#00BFC4"),
inherit.aes=F
)
与
library(ggplot2)
df <- read.table(header=T, text="samples genes value class
sample1 geneA 0.52 class2
sample1 geneB 1 class1
sample1 geneC 1 class1
sample2 geneD 1 class1
sample2 geneB 1 class1
sample2 geneH 0.4 class2
sample2 geneC 1 class1
sample3 geneE 0.44 class2
sample3 geneF 0.34 class2
sample3 geneB 1 class1
sample3 geneI 0.65 class2
sample3 geneC 1 class1
sample4 geneB 0.72 class2
sample4 geneC 0.41 class2
sample5 geneG 1 class1
sample5 geneB 1 class1
sample5 geneC 1 class1")