1

I am producing a heatmap via cooccur package but I am getting overlapping species names. How to solve it? The plot was produced by the following codes:

M <- cooccur(mat = M, type = "spp_site", thresh = T, spp_names = TRUE, prob = "hyper")
plot(M, plotrand = TRUE)

enter image description here

Richard Telford
  • 9,558
  • 6
  • 38
  • 51
  • I have 1000+ species in that dataset. – Subrata Gayen Jun 18 '22 at 17:15
  • The usual solutions to overlapping labels are to reduce the font size, make abbreviated names, and find some way to offset them, but with 1000 species, none of these will do much. Maybe remove the rarest taxa - they won't show anything anyway – Richard Telford Jun 18 '22 at 20:33
  • How can I reduce the font size in that case? Thanks for the suggestions. @Richard Telford – Subrata Gayen Jun 19 '22 at 11:36

2 Answers2

0

Unfortunately, the author didn't use defined themes inside the function. In this post How to change default font size in R chart @Gregor Thomas give a nice answer. What you can do is create your own theme like in ggplot. Here I use the finches dataset as an example:

library(cooccur)
data("finches")
cooccur.finches <- cooccur(mat=finches,
               type="spp_site",
               thresh=TRUE,
               spp_names=TRUE)
summary(cooccur.finches)
plot(cooccur.finches,cex.sub = 0.1)

p <- plot(cooccur.finches)
p + theme_bw(base_size = 28) +
  theme(axis.text = element_blank(), 
        axis.ticks = element_blank(), 
        plot.title = element_text(vjust = -4, face = "bold"), 
        panel.background = element_rect(fill = "white", colour = "white"), 
        panel.grid = element_blank(),
        legend.position = c(0.9, 0.5))

Output:

enter image description here

I would suggest playing around with the theme options from ggplot. Here is a good post which can help you for sure: Changing font size and direction of axes text in ggplot2

Quinten
  • 35,235
  • 5
  • 20
  • 53
0

Before you start fiddling with font sizes, you should check whether this is just an artificial problem caused by R incorrectly guessing the device size. I have noticed that this regularly occurs when a plot is saved to PDF with dev.copy and the following workaround always solved the problem for me:

  1. Resize the plotting window on screen.
  2. Redraw the plot by calling the plot command again.
cdalitz
  • 1,019
  • 1
  • 6
  • 7