ShesXiao 2022-05-13 14:47 采纳率: 0%
浏览 63
已结题

R语言的ggplot2,热图,标尺(scale)

我想把0.05到1这个范围的标尺改成灰色

img

library(reshape2)
library(ggplot2)
data_m <-  melt (data2, id.vars= c ( "ID" ))  
p <- ggplot(data_m, aes(x=variable,y=ID)) + 
  xlab( "" ) +
  ylab( "" ) + 
  theme_bw() + 
  theme(panel.grid.major = element_blank()) + 
  theme(legend.key=element_blank()) + 
  coord_fixed(ratio=0.3)+
  theme(axis.text.x=element_text(angle=45,hjust=1, vjust=1)) + 
  theme(legend.position= "right" )+ 
  geom_tile(aes(fill=value),color="black") + 
  scale_fill_fermenter(name = "FDR",
                       breaks = c(0,0.005,0.010,0.015,0.020,0.030,0.040,0.050,1), 
                       limit = c(0, 1),
                       palette = 7 )+
  guides (fill = guide_coloursteps(show.limits = T))



  • 写回答

3条回答 默认 最新

  • ShesXiao 2022-05-14 17:58
    关注

    我修改了一下,0.05到1是没问题了,但0.05一下变成这样子了,是不是与我数据的分布有关系,因为我没有0.05到1之间的数据,我的数据都在0.05一下或者是1

    img

    library(reshape2)
    library(ggplot2)
    data_m <-  melt (data2, id.vars= c ( "ID" ))  
    p <- ggplot(data_m, aes(x=variable,y=ID)) + 
      xlab( "" ) +
      ylab( "" ) + 
      theme_bw() + 
      theme(panel.grid.major = element_blank()) + 
      theme(legend.key=element_blank()) + 
      coord_fixed(ratio=0.3)+
      theme(axis.text.x=element_text(angle=45,hjust=1, vjust=1)) + 
      theme(legend.position= "right" )+ 
      geom_tile(aes(fill=value),color="black") + 
      scale_fill_steps2(name = "FDR",
                           breaks = c(0,0.005,0.010,0.015,0.020,0.030,0.040,0.050,1), 
                           limit = c(0, 1),
                           low = "Red",
                           mid = "Yellow",midpoint = 0.05,
                           high = "Gray",
                           space = "Lab")+
      guides (fill = guide_coloursteps(show.limits = T))
    
    
    评论

报告相同问题?

问题事件

  • 系统已结题 5月21日
  • 修改了问题 5月14日
  • 修改了问题 5月13日
  • 创建了问题 5月13日