问题描述
我想在下图中添加两点:
- 向 geom_tile 图形添加图例(zp 或 df$legend)(类似于每个块)
- 为每个图块指定特定颜色(每个块重复)而不是 scale_fill_continuous,但为 NA 值保留“白色”颜色。
library(ggplot2)
library(RColorBrewer)
xp <- c('disease_1','disease_2','disease_3','disease_4')
yp <- c('B Cell','T Cell')
zp <- c('feature1','feature2','feature3','feature4','feature5','feature6','feature7','feature8')
xp1 <- xp[1:2]
df <- list(x=1:2,y=1:4,xp1,yp)
df <- expand.grid(df)
df$z <- c(1.804344554,1.158037086,1.686173307,0.500280283,1.710806067,0.857513435,0.66474755,1.164780941,1.769090931,2.058400169,3.114233859,1.436684123,1.770306398,0.995507604,2.538556363,2.264486118,1.424789875,1.816608927,2.773082903,1.197434618,0.829416784,1.622892741,2.035117094,1.650363345,1.927235048,1.546477438,2.308773122,1.041881013,1.216029616,0.478353441,0.834348006,1.240448774)
df$legend <- rep(c('feature1','feature8'))
cols <- rev(brewer.pal(11,'RdYlBu'))
p <- ggplot(df)
p <- p + geom_tile(aes(x,y,fill = ifelse(z > 1,z,NA)),colour = "black",width=0.85,height=0.85,size=1) +
scale_fill_continuous(name = "z Scale",na.value = 'white') +
labs() +
facet_grid(Var3~Var4) +
theme(strip.background =element_blank(),#remove bg color of facet_grid texts
strip.text.x = element_text(size=12,color="black",face="bold"),strip.text.y = element_text(size=10,face="bold"))
print(p)
p + coord_fixed() +
theme(
axis.title = element_blank(),axis.text=element_blank(),axis.ticks=element_blank(),plot.background=element_blank(),panel.border=element_blank(),panel.background = element_blank())
提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)