Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

row_side_colors interferes with renaming colorbar legend tick text #205

Closed
gtollefson opened this issue Jan 24, 2019 · 9 comments
Closed

Comments

@gtollefson
Copy link

gtollefson commented Jan 24, 2019

I'm renaming the legend colorbar tick text using h[['x']][['data']][[length(h[['x']][['data']])]][['marker']][['colorbar']][['ticktext']] <- genotypes , the solution @alanocallaghan suggested in #199. However, when I use the option row_side_colors, this code does not work. I've included reprexes below. The only difference between the two examples is row_side_colors and row_side_palette are set in the problem example(#2). As an aside, if I set plot_method="plotly" without row_side_colors, it also does not work but this isn't as much of a problem for me.

Working example:

h <-heatmaply(gt_num_array_1, col_side_colors = pheno_data, col_side_palette = c("1" = "mediumpurple2", "0"="steelblue2"), Rowv=NULL,Colv=NULL,dend=FALSE)

h[['x']][['data']][[length(h[['x']][['data']])]][['marker']][['colorbar']][['ticktext']] <- genotypes

h

produces
screen shot 2019-01-24 at 12 34 28 pm

Problem example:

library(heatmaply)

pheno_data=read.table("pheno_data2.txt", header=TRUE, stringsAsFactors=FALSE)
gt_num_array_1 <- read.csv("example_input_matrix.csv")  
chrom_label_array <- read.csv("chrom_label_array.csv",header=TRUE) 

genotypes <- c('no call', 'homozygous reference',
    'heterozygous variant', 'homozygous variant')

h <- heatmaply(gt_num_array_1, col_side_colors = pheno_data, col_side_palette = c("1" = "mediumpurple2", "0"="steelblue2"), row_side_colors= chrom_label_array, row_side_palette = c(
'1'= '#d3d7cf',
'2'='#babdb6',
'3'='#fce94f',
'4'='#edd400',
'5'='#c4a000',
'6'='#8ae234',
'7'='#4e9a06',
'8'='#fcaf3e',
'9'='#f57900',
'10'='#ce5c00',
'11'='#e9b96e',
'12'='#c17d11',
'13'='#8f5902',
'14'='#729fcf',
'15'='#3465a4',
'16'='#204a87',
'17'='#ad7fa8',
'18'='#75507b',
'19'='#5c3566',
'20'='#888a85',
'21'='#555753',
'22'='#2e3436',
'X'='#ef2929',
'Y'='#cc0000',
'M'='#a40000'),Rowv=NULL,Colv=NULL,dend=FALSE)

h[['x']][['data']][[length(h[['x']][['data']])]][['marker']][['colorbar']][['ticktext']] <- genotypes

h

produces

screen shot 2019-01-24 at 12 39 26 pm

@gtollefson gtollefson changed the title row_side_colors interferes with renaming tick labels row_side_colors interferes with renaming colorbar legend tick text Jan 24, 2019
@gtollefson
Copy link
Author

gtollefson commented Jan 24, 2019

Ah ha. I see here #95 that ggplot2 objects are converted to plotly objects. I'm guessing that, because this doesn't work when plot_method="plotly", the custom legend ticktext causes an issue when it's converted.

@gtollefson
Copy link
Author

This is a little confusing, because I imagine the ggplot2 plot object is converted to a plotly object when row_side_colors is not set and this doesn't cause any issues.

It only causes issues when the ggplot2 object is converted to plotly and there is a row_side_colors colorbar + colorbar legend to convert as well. I imagine this is due to the complicated history of col_side_color legends.

This feature the last obstacle in a tool dev project, so if it is possible to work around it, we would be very appreciative!

@alanocallaghan
Copy link
Collaborator

I imagine what's happening here is that the order of subplots is different, so the call

h[['x']][['data']][[length(h[['x']][['data']])]]...

Needs to be changed. Specifically length(h[['x']][['data']]), which is the number of the last element in the h$x$data list (thus selecting it). You might want to play around with that value - you can replace length(h[['x']][['data']]) with a number or with length(h[['x']][['data']]) - 1 etc until you find a value that works for the situation in question (this might involve checking which arguments have been supplied to ensure the right element is selected)

@alanocallaghan
Copy link
Collaborator

PS, if you happen to publish any work relating to this, please cite us

@gtollefson
Copy link
Author

@alanocallaghan ah ha! That makes sense. I'll try this.

@gtollefson
Copy link
Author

PS, if you happen to publish any work relating to this, please cite us

We've written our manuscript and have cited your paper. We also would like to acknowledge you personally @alanocallaghan for all of the help you've given me during dev. If this is amenable to you please let me know how you'd like your name to appear and your affiliations.

@alanocallaghan
Copy link
Collaborator

Thanks @gtollefson, that's very generous! My name is Alan O'Callaghan and affiliation is MRC Human Genetics Unit, University of Edinburgh. Let me know if you have any further issues

@talgalili
Copy link
Owner

Can we close this issue?

@alanocallaghan
Copy link
Collaborator

Unless @gtollefson has any further problems with this, yep (if so re-open)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants