Coloring the axis tick text by multiple colors

你说的曾经没有我的故事 提交于 2019-12-06 14:54:26

A similar question with a different setup has been asked and answered for Python here: Setting a different font color for specific x axis ticks. Below is my best attempt with your setup for R.

Plot:

Code:

library(plotly)
library(dplyr)

# data
set.seed(1)
df <- reshape2::melt(matrix(rnorm(100),10,10,dimnames = list(paste0("G",1:10),paste0("S",1:10))))

# plotly setup
p1 <- plot_ly(z=c(df$value),x=df$Var2,y=df$Var1,colors=grDevices::colorRamp(c("darkblue","gray","darkred")),
              type="heatmap",colorbar=list(title="Scaled Value",len=0.4)) 

p2 <- p1 %>% add_trace(xaxis='x2', showscale=FALSE)

p3 <- p2  %>% layout(xaxis=list(range=list(0,9),
                                tickvals=list(0,1,2,3,4),
                                tickfont=list(color='red')),
                     xaxis2=list(range=list(0,9), overlaying='x',
                                 ticktext = list('s9', 's10'),
                                 tickvals=list(5, 6, 7, 8, 9),
                                 tickfont=list(color='blue')))
# plot it
p3
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!