Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

Annotated heatmap subplot

How do I annotate heat maps in plotly?

Code:qtr1 = yq(“2006q1”)
qtr2 = yq(“2007q1”)

qtrs= seq(qtr1,qtr2,by=“quarter”)

tester=indflows$new(j2jod,ind1,ind2,geo1,geo2,qtr1)

tester2=indflows$new(j2jod,ind1,ind2,geo1,geo2,qtr2)

tester3=indflowsdiff$new(tester,tester2)

plotflow = function(flowobj,varname){
p=plot_ly(type=“heatmap”,
colors = colorRamp(c(“red”, “blue”)),
z=eval(parse(text=paste(“flowobj$vardata”,"$",varname,sep=""))),
x=factor(flowobj$alldata[[1]]$industry),
y=factor(flowobj$alldata[[1]]$industry_orig)) %>%
layout(title=“Title”,
showlegend = FALSE,
xaxis=list(title=“x-axis”),
yaxis=list(title=“y-axis”))
y = flowobj$qtr
return§
}

plotflowqtrs = function(df,ind1,ind2,geo1,geo2,qtrs){

Get Data

data=lapply(qtrs,indflows$new,df=df,inddest=ind1,indorig=ind2,geodest=geo1,geoorig=geo2)
p=lapply(data,plotflow,varname=“ee”)
subplot(p,nrows = round(length(qtrs)/3, digits=0), margin = 0.025)
}

pfqvsbase = function(df,ind1,ind2,geo1,geo2,qtrbase,qtrs){

Get Data

base=indflows$new(df,ind1,ind2,geo1,geo2,qtrbase)
data=lapply(qtrs,indflows$new,df=j2jod,inddest=ind1,indorig=ind2,geodest=geo1,geoorig=geo2)
diff=lapply(data,indflowsdiff$new,x=base)
p=lapply(diff,plotflow,varname=“ee”)
subplot(p,nrows = round(length(qtrs)/3, digits=0), margin = 0.025)
}

qtrbase = yq(“2006q1”)
pfqvsbase(j2jod,ind1,ind2,geo1,geo2,qtrbase,qtrs)
base=indflows$new(j2jod,ind1,ind2,geo1,geo2,qtrbase)

pfqdelta = function(df,ind1,ind2,geo1,geo2,qtrs){
}

image of my plot:

Hi @mjb22932,

you can use annotations (like below) and for subplots follow this tutorial (https://plot.ly/r/text-and-annotations/#subplot-annotations):

library(plotly)

p <- plot_ly(
    x = c("Team A", "Team B"), 
    y = c("Game Three", "Game Two"), 
    z = matrix(c(0.1, 0.3, 0.5, 1), nrow=2, ncol=2), 
    colorscale = "Viridis", 
    showscale = FALSE, 
    type = "heatmap", 
    zauto = TRUE, 
    zmax = 1, 
    zmin = 0.1, 
  ) %>%
  layout(
    xaxis = list(
      autorange = TRUE, 
      dtick = 1, 
      gridcolor = "rgb(0, 0, 0)", 
      range = c(-0.5, 2.5), 
      side = "top", 
      ticks = "", 
      type = "category"
    ), 
    yaxis = list(
      autorange = TRUE, 
      dtick = 1, 
      range = c(-0.5, 2.5), 
      ticks = "", 
      ticksuffix = "  ", 
      type = "category"
    ),
    annotations = list(
      list(
        x = "Team A", 
        y = "Game Three", 
        font = list(color = "#FFFFFF"), 
        showarrow = FALSE, 
        text = "Win", 
        xref = "x", 
        yref = "y"
      ), 
      list(
        x = "Team B", 
        y = "Game Three", 
        font = list(color = "#FFFFFF"), 
        showarrow = FALSE, 
        text = "Lose", 
        xref = "x", 
        yref = "y"
      ),
      list(
        x = "Team A", 
        y = "Game Two", 
        font = list(color = "#000000"), 
        showarrow = FALSE, 
        text = "Lose", 
        xref = "x", 
        yref = "y"
      ), 
      list(
        x = "Team B", 
        y = "Game Two", 
        font = list(color = "#000000"), 
        showarrow = FALSE, 
        text = "Lose", 
        xref = "x", 
        yref = "y"
      )
    )
  )