4

I need to use and show stars for significances within my pheatmp, I have utilised the approach below. As you can see the stars reported by the figure cross the cell border. Is there a way to centre it within the cell?

test_vals <- matrix(rnorm(20), 5, 4)
test_labels <- matrix(1:20, 5, 4) 
test_labels[test_labels<=10] <- "**"
pheatmap(test_vals, display_numbers = test_labels, fontsize_number=40, cellheight=20)
Al14
  • 1,734
  • 6
  • 32
  • 55
  • Have you looked at the answer to this post? https://stackoverflow.com/questions/44701207/column-labels-cropped-when-using-pheatmap – TabsNotSpaces Feb 08 '19 at 16:35

1 Answers1

4

I did not find a straight way to solve your task, so I can suggest a little dirty hack. You can use a different asterisk symbol from Unicode (U+2217 ASTERISK OPERATOR). So try this:

UPDATE: it is possible to pass Unicode strings into plotting function without previous parsing. Therefore I have updated the code and removed stringi library requirement.

library(pheatmap)

test_vals <- matrix(rnorm(20), 5, 4)
test_labels <- matrix(1:20, 5, 4) 
test_labels[test_labels <= 10] <- "\u2217\u2217"
pheatmap(test_vals, display_numbers = test_labels, fontsize_number=20, cellheight=20)

Here is a result: Example result of pheatmap with the different Unicode character

Also, you can try other variants. Next two are slightly bigger the common asterisk.

# Heavy asterisk
#test_labels[test_labels<=10] <- "\u2731\u2731"
# Full width asterisk
#test_labels[test_labels<=10] <- "\uFF0A\uFF0A"
Istrel
  • 2,508
  • 16
  • 22
  • I am having a problem in the visualisation of the asterisks. Heatmap reports indeed an empty centred box instead of the asterisks – Al14 Feb 11 '19 at 11:36
  • Can you run this code in R console `stri_unescape_unicode("\u2217")` – Istrel Feb 11 '19 at 11:51
  • Yes, I got this `"∗"` – Al14 Feb 11 '19 at 12:23
  • It could be a problem with a graphics device on some systems (Windows, MacOS). Just for a test, can you save a plot with `cairo_pdf` function? – Istrel Feb 11 '19 at 12:30
  • I tried `cairo_pdf` and `CairoPDF` but it does still show a square instead of the asterisk – Al14 Feb 11 '19 at 14:54
  • Maybe your font doesn't contain additional symbols. Try a different font. Look at `showtext` package. Here is a good tutorial https://cran.rstudio.com/web/packages/showtext/vignettes/introduction.html – Istrel Feb 11 '19 at 15:38