0

I've been using the R package "cooccur" to measure co-occurrence among bird species, a package that produces its own R objects. I am not very familiar on this and want to make changes to the sizes of its x or y labels. (similar question for another plot asked here: Modify GGplot2 Object)

I'm trying to adjust the size of the font of the plot but using theme(), I've been successful in changing the angle of the plot but have not had any success with adjusting font size for both. This only changes the position of the graph for some reason.

Note: These graphs are created as ggplot2 objects from the specific package I am using for this analysis.

(I'm not sure if this belongs to this community specifically though, I'm just curious also if others have used this package).

help please :/

library(devtools)
#install_github("griffithdan/cooccur")
library(cooccur)

options(stringsAsFactors = FALSE)

data(finches)
cooccur.finches <- cooccur(mat=finches,
               type="spp_site",
               thresh=TRUE,
               spp_names=TRUE)
summary(cooccur.finches)
plot(cooccur.finches)
p <- obs.v.exp(cooccur.finches)

# the ggplot2 object can be edited directly and then replotted
p

# alternatively, use base graphics, This is what I am currently doing but it is not correct
cooc.exp <- cooccur.finches$results$exp_cooccur
cooc.obs <- cooccur.finches$results$obs_cooccur
sp1 <- cooccur.finches$results$sp1_name
sp2 <- cooccur.finches$results$sp2_name

plot(cooc.obs ~ cooc.exp)
  text(x = cooc.exp[1], y = cooc.obs[1], labels = sp1[1]) # plot one name

#CoOccurrence Plot
p <- plot(cooccur.finches) 
p  + ggtitle("GCF Co-Occurrence Matrix")#+
  theme(axis.text.y = element_text(size = 20), axis.text.x = element_text(size = 50)) 

Original Plot Produced

enter image description here

Modified Attempt of Plot

enter image description here

  • I'm still confused about which font size you wanna adjust. The size of x axis, y axis, diagonal text, title, or legend?? – Darren Tsai Apr 03 '20 at 15:28
  • The diagonal text, I was just showing an exapmle.. I found this post thought that was very similar question, https://stackoverflow.com/questions/27871157/how-to-change-default-font-size-in-r-chart – bioinformatics_student Apr 03 '20 at 15:31
  • Can you share the actual code that resulted in that actual plot? Am I correct that you are applying another `theme(...)` element to the `p` `ggplot` object that arises from `obs.v.exp(...)` call? You mention you are able to change the text to be on a diagonal - I'd like to see what the original looks like (with the code) and the one that makes it diagonal (with the code). The two lines of code at the end give you the strange plot you are showing because you are mixing base graphics (`plot()`) with `ggplot2` commands: (`ggtitle(...)`). – chemdork123 Apr 03 '20 at 18:50
  • Wait - now i see. I was able to install the package and for the plot you show, that comes from `plot(cooccur.finches)`, which is plotting in base graphics, not `ggplot2`. `obs.v.exp(cooccur.finches)` produces another plot (scatter plot with an `abline()`). You can change the `obs.v.exp()` plot output with `theme()`, but for the cooccurence plot you show, it's base graphics and cannot be changed with `theme()` calls. I've been totally unsuccessful trying `cex`, `ps`, or any variant to change size of anything in that call to `plot(cooccur.finches)`, sorry to say. – chemdork123 Apr 03 '20 at 19:12
  • Hey @chemdork123 so I was able to modify this plot, I went directly into the script and did my modifications here, I found it in a similar post to what I was trying to do. Thanks for your help though on this. You can check it out if you are interested :) – bioinformatics_student Apr 06 '20 at 09:02
  • https://stackoverflow.com/questions/27871157/how-to-change-default-font-size-in-r-chart – bioinformatics_student Apr 06 '20 at 09:03
  • 1
    Ah, interesting. Good detective work and good luck. – chemdork123 Apr 06 '20 at 12:13

0 Answers0