【问题标题】:Highlight tiles with ggplot2 geom_tile() + geom_point()使用 ggplot2 geom_tile() + geom_point() 突出显示图块
【发布时间】:2013-05-03 04:17:56
【问题描述】:

我有如下的情节:

我正在尝试根据找到的以下代码在另一层中添加点here

我正在导入的数据框如下所示:

residue_id  residue_num per_ddg pg9_seq_bool
A   96  0.00437094862845686 FALSE
A   97  -0.0026333752377897 FALSE
A   98  -0.00453070737795937    FALSE
A   99  -0.0130564560942629 TRUE
A   100 -0.00578979380922636    FALSE
A   101 -0.0128130535970934 FALSE
A   102 -0.0264740211311766 FALSE
A   103 -0.183036342874782  FALSE
A   104 -0.00550669729238368    FALSE

并使用以下代码生成绘图:

library(ggplot2)
input_ddg <-read.table('per_residue_average.txt',header=T,sep="\t",stringsAsFactors=TRUE)
input_ddg$pg9_seq_bool[input_ddg$pg9_seq == "TRUE"] <- T
input_ddg$pg9_seq_bool[input_ddg$pg9_seq == "FALSE"] <- F


pdf("output.pdf")                                                                                                                                                      
ggplot(input_ddg, aes(residue_id,residue_num,fill=per_ddg) ) +                            
  theme_bw() +                                                                
  geom_tile() +                  
  geom_point(data=input_ddg,aes(size=ifelse(pg9_seq_bool, "dot", "no_dot"))) +
  scale_size_manual(values=c(dot=6,no_dot=NA))+                                                                 
  scale_fill_gradient2(low="blue", mid="white",high="red", midpoint=-.25, na.value="black") +     
  ylab( "Residue Number" ) +                                                  
  xlab( "Mutation Identity")    +     
  scale_y_continuous(breaks=96:125,expand=c(0,0))+
  scale_x_discrete(expand=c(0,0))+
  labs(fill=expression(Delta*Delta*"G(REU)")) +
  ggtitle(expression("Average"~Delta*Delta*"G for Mutations by CDR3 Position")) +
  theme(  panel.background=element_rect(fill="black"), panel.grid.minor=element_blank(), panel.grid.major=element_blank())
dev.off()

我收到一个错误:

Error in grid.Call.graphics(L_setviewport, pvp, TRUE) : 
Non-finite location and/or size for viewport
Calls: print ... lapply -> FUN -> push.vp.viewport -> grid.Call.graphics
In addition: Warning message:
Removed 461 rows containing missing values (geom_point). 
Execution halted

我有一种感觉是因为我用 ifelse 解析了 TRUE 和 FALSE,但我完全按照帖子进行了操作。

【问题讨论】:

    标签: r statistics ggplot2


    【解决方案1】:

    首先,您不需要在数据帧input_ddg 中将 TRUE 和 FALSE 值替换为 T 和 F。接下来,pg9_seq_bool 列可以直接在geom_point()aes() 中使用。这将根据 TRUE/FALSE 值产生两种类型的点。然后使用scale_size_manual() 设置大小 0 为 FALSE,6 为 TRUE。如果此磅值不应出现在图例中,则在 scale_size_maual() 中添加参数 guide="none"

    ggplot(input_ddg, aes(residue_id,residue_num,fill=per_ddg) ) +                            
      theme_bw() +                                                                
      geom_tile() +                  
      geom_point(aes(size=pg9_seq_bool)) +
      scale_size_manual(values=c(0,6),guide="none")
    

    【讨论】:

    • 是的,抱歉,我今天必须去上班以确保它确实有效:)
    猜你喜欢
    • 2012-08-21
    • 1970-01-01
    • 2012-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-25
    相关资源
    最近更新 更多