title: add multiple legends to a heatmap in R
body: <p>My question is that I want to add the categorical variables' legends onto the graph but somehow when I used "topright", it did not work for me (see the image below). Basically my idea is to fill the blank area with the legends for my categorical variables on the side of the heatmap. My codes look like </p>
  
  <pre><code>heatmap.3(performance, Colv =NA,RowSideColors=row_annotation,col=my_palette)
  
  par(lend = 1)           # square line ends for the color legend
  legend("topright",      # location of the legend on the heatmap plot
         legend = c("category1", "category2", "category3"), # category labels
         col = c("gray", "blue", "black"),  # color key
         lty= 1,             # line style
         lwd = 10            # line width
        )
  </code></pre>
  
  <p>Also I want to put multiple legend onto the plot but don't know how to specify their positions using x and y as there are no coordinates in my plot.</p>
  
  <p>Thank you so much!
  <img src="https://i.stack.imgur.com/i7C0p.png" alt="enter image description here"></p>