Highlight tiles with ggplot2 geom_tile() + geom_point()

I have the following plot that looks like:

I'm trying to add points in another layer using according to the following code found here

My data frame i'm importing looks like this:

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

and uses the following code to generate the plot:

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()

I'm getting an error:

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

I have a feeling its to due with my parsing of the TRUE and FALSE with ifelse, but I followed the post exactly.

Answers


First, you don't need to replace TRUE and FALSE values with T and F in your data fram input_ddg. Next, column pg9_seq_bool can be used directly in aes() of geom_point(). This will produce two types of points according to TRUE/FALSE values. Then with scale_size_manual() set size 0 for FALSE and 6 for TRUE. If this point size shouldn't appear in legend then add argument guide="none" in scale_size_maual().

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")


Need Your Help

Using KendoUI Pie Chart, How do you remove white space?

javascript jquery asp.net telerik kendo-ui

I'm using the KendoUI pie chart and I have a lot off white space. What is the best way to remove it. See the image below:

Is SuspendLayout/ResumeLayout worthless or am I going about it wrong?

c# winforms dynamic tabs tablelayoutpanel

I have two tab pages hosting TableLayoutPanels that I dynamically populate with labels and textboxes. The first one gets 96 labels and 96 textboxes, and its flicker is acceptable/tolerable, so I di...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.