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

[FEATURE] Possible to have axis text in multiple colors? #264

Open
mcsimenc opened this issue Jun 17, 2021 · 6 comments
Open

[FEATURE] Possible to have axis text in multiple colors? #264

mcsimenc opened this issue Jun 17, 2021 · 6 comments

Comments

@mcsimenc
Copy link

mcsimenc commented Jun 17, 2021

In ggplot2 I can pass a vector of colors through theme(axis.text.x), and while it gives the warning

Vectorized input to `element_text()` is not officially supported.
Results may be unexpected or may change in future versions of ggplot2.

it still works. I see this warning when passing the ggplot2 theme axis text colors through heatmap_layers but it doesn't seem to change the colors. A single color passed this way works.

Is this possible?

Screenshot from 2021-06-17 14-58-52

Thanks!

@alanocallaghan
Copy link
Collaborator

Could you use reprex::reprex to post the code you used here?

@alanocallaghan
Copy link
Collaborator

Sorry I nuked your code somehow lol

library(heatmaply) 
     
# generate data 
datMat = matrix(runif(100), nrow = 10, ncol = 10) 
    
# try a single color 
heatmaply(datMat, heatmap_layers = theme(axis.text.y = element_text(colour = "blue")), main = "A sin
gle axis text color passed using theme() works") 
    
# try multiple colors 
axisColors = rep(c("red", "black"), 5) 
heatmaply(datMat, heatmap_layers = theme(axis.text.y = element_text(color = axisColors)), main = "Mu
ltiple colors passed to theme doesn't work") 
    
library(reshape2) 
# multiple colors works in ggplot2 
    
datMelt = melt(datMat) 
ggplot(datMelt, aes(x = Var1, y = Var2, fill = value)) +  
    geom_tile() +  
    theme(axis.text.y = element_text(color = c("black", "red", "black", "red", "blue"))) +  
    ggtitle("Multiple axis colors works for ggplot()")

@alanocallaghan
Copy link
Collaborator

I think the short answer is no, if ggplotly() called on the last plot doesn't work (it doesn't for me). Would be worth flagging this up in the plotly repo

@mcsimenc
Copy link
Author

No, that was me lol. When I first read reprex::reprex it somehow didn't register. I deleted it and started looking into reprex

@alanocallaghan
Copy link
Collaborator

Ah fair dues. Turns out it doesn't really like HTML output anyway so I was pointing you in the wrong direction for github issues with HTMLwidgets.

@mcsimenc
Copy link
Author

mcsimenc commented Jun 17, 2021

The only way I know how do it with plot_ly is to add multiple overlapping axes of different ranges and colors. It works for me for more than two colors too. Here is my attempt with heatmaply and the resulting error. Any suggestions? EDIT: I guess I should try installing PhantomJS...

library(heatmaply)
#> Loading required package: plotly
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
#> Loading required package: viridis
#> Loading required package: viridisLite
#> 
#> ======================
#> Welcome to heatmaply version 1.2.1
#> 
#> Type citation('heatmaply') for how to cite the package.
#> Type ?heatmaply for the main documentation.
#> 
#> The github page is: https://github.com/talgalili/heatmaply/
#> Please submit your suggestions and bug-reports at: https://github.com/talgalili/heatmaply/issues
#> Or contact: <tal.galili@gmail.com>
#> ======================
library(reprex)


# generate data
datMat = matrix(runif(100), nrow = 10, ncol = 10)

# multiple colors using plot_ly() method
heatmaply(datMat) %>%
  add_trace(yaxis = "y2", showscale = F) %>%
  layout(yaxis = list(range = list(1, 10),
                      tickfont = list(color = "red"),
                      tickvals = as.list(1:5)),
         yaxis2 = list(range = list(1, 10),
                       overlaying = 'y',
                       tickfont = list(color = "blue"),
                       tickvals = as.list(6:10)))
#> PhantomJS not found. You can install it with webshot::install_phantomjs(). If it is installed, please make sure the phantomjs executable can be found via the PATH variable.
#> No scatter mode specifed:
#>   Setting the mode to markers
#>   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
#> Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...): 'x' must be atomic

Created on 2021-06-17 by the reprex package (v2.0.0)

EDIT: Same scatter mode error after PhantomJS was installed.

library(heatmaply)
#> Loading required package: plotly
#> Loading required package: ggplot2
#> 
#> Attaching package: 'plotly'
#> The following object is masked from 'package:ggplot2':
#> 
#>     last_plot
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following object is masked from 'package:graphics':
#> 
#>     layout
#> Loading required package: viridis
#> Loading required package: viridisLite
#> 
#> ======================
#> Welcome to heatmaply version 1.2.1
#> 
#> Type citation('heatmaply') for how to cite the package.
#> Type ?heatmaply for the main documentation.
#> 
#> The github page is: https://github.com/talgalili/heatmaply/
#> Please submit your suggestions and bug-reports at: https://github.com/talgalili/heatmaply/issues
#> Or contact: <tal.galili@gmail.com>
#> ======================
library(reprex)


# generate data
datMat = matrix(runif(100), nrow = 10, ncol = 10)

# multiple colors using plot_ly() method
heatmaply(datMat) %>%
  add_trace(yaxis = "y2", showscale = F) %>%
  layout(yaxis = list(range = list(1, 10),
                      tickfont = list(color = "red"),
                      tickvals = as.list(1:5)),
         yaxis2 = list(range = list(1, 10),
                       overlaying = 'y',
                       tickfont = list(color = "blue"),
                       tickvals = as.list(6:10)))
#> No scatter mode specifed:
#>   Setting the mode to markers
#>   Read more about this attribute -> https://plotly.com/r/reference/#scatter-mode
#> Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...): 'x' must be atomic

Created on 2021-06-17 by the reprex package (v2.0.0)

@mcsimenc mcsimenc reopened this Jun 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants