help alter output of gl.pcoa.plot() using dartRverse

37 views
Skip to first unread message

Paige M.

unread,
Nov 19, 2024, 9:25:13 PM11/19/24
to dartR
Hello,
I am working on a Macbook in Rstudio Version 2024.09.1+394.  I am using dartRverse v 1.0.2 and dartR.base v 0.98.  Everything works beautifully. My problem is that I really need to change part of the layout for the output of gl.pcoa.plot() to alter the background color of the plot as I really need to have a white background with gray lines only to mark the grid and I also want to put the axes outside the graph. 

I read through the old posts and I see in the past there was a way use the save2tmp() command and then alter parameters -
conversation "Adjusting 'NA' points in gl.pcoa.plot output" started Feb 26,2024 by tork...@umn.edu
In this conversation luis.m suggested a workaround using the dev version (install_github("green-striped-gecko/dartR@dev") but that no longer works:
Downloading GitHub repo green-striped-gecko/dartR@dev Error in utils::download.file(url, path, method = method, quiet = quiet, : download from 'https://api.github.com/repos/green-striped-gecko/dartR/tarball/dev' failed

I tried to find the correct URL but I could not. Perhaps there is a simpler way to do this anyway. I'm not great with writing anything in R (part of why I love using dartR and now dartRverse.).

Thank you for any suggestions you may have.


Best, Paige

Jose Luis Mijangos

unread,
Nov 19, 2024, 9:59:58 PM11/19/24
to dartR
Hi Paige,

See code below.

Cheers,
Luis

library(dartRverse)
t1 <- platypus.gl
pca <- gl.pcoa(t1)
gl.pcoa.plot(pca,
             t1,
             plot.dir = getwd(),
             plot.file = "test"
             )
p1 <- readRDS("test.RDS")
p2 <- p1 + theme_bw() +
  theme(axis.title.x=element_blank(),
           axis.text.x=element_blank(),
           axis.ticks.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        legend.position = "none")
print(p2)
# Examples of other themes that can be used can be consulted in
# https://ggplot2.tidyverse.org/reference/ggtheme.html and
# https://yutannihilation.github.io/allYourFigureAreBelongToUs/ggthemes/
 

Paige M.

unread,
Nov 20, 2024, 5:41:48 PM11/20/24
to dartR
Hello Luis,
Thank you for this helpful code.  I have been able to make all the changes I would want to the plot, except I can't seem to actually remove the original lines for the axes.  I think after exploring this it is set with this code in dartR (I looked at https://github.com/green-striped-gecko/dartR.base/blob/main/R/gl.pcoa.plot.r):

plott <-
                plott + geom_hline(yintercept = 0) +
                geom_vline(xintercept = 0)

Perhaps that is not the right snippet, but I do know that I can add intercept lines using this code at the positions where I want them .

plot3 =  plot2 + geom_hline(yintercept = -3) +
                geom_vline(xintercept = -3)

I just can't figure out how to get rid of the existing ones plotted at 0.  Is there any way to do that, or is it just something I will have to live with?  I basically just want to have the graph have outside lines.

Thank you very much!!

Best,

Jose Luis Mijangos

unread,
Nov 25, 2024, 1:34:53 AM11/25/24
to dartR
Hi Paige,

You can try the code below.

Cheers,
Luis 

p2 <- p1 + theme_void() +

  theme(axis.title.x=element_blank(),
           axis.text.x=element_blank(),
           axis.ticks.x=element_blank(),
        axis.title.y=element_blank(),
        axis.text.y=element_blank(),
        axis.ticks.y=element_blank(),
        legend.position = "none") +
  geom_hline(yintercept = 0,color = "white",size =2) +
  geom_vline(xintercept = 0,color = "white",size =2)

Paige M.

unread,
Jun 11, 2025, 12:57:09 PMJun 11
to da...@googlegroups.com
Hi Luis,
It's very late to answer and say this, but in case it helps anyone else - this did not work for me! I just could not get the original plot from gl.plot.pcoa to stop putting in the lines (though it put them in as white lines after I followed the command above they were still visible against the data.

I finally just exported the pcoa data to a data.table and formatted it properly and just plotted using a theme in ggplot2.  

Thank you for the assistance though.

ps I did complete the survey for the Eureka Prize in Research Software.  I definitely think dartR is great.

Associate Project Scientist 
UC Santa Barbara 
Marine Science Institute


--
You received this message because you are subscribed to a topic in the Google Groups "dartR" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/dartr/7WiJiFWlufc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to dartr+un...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/dartr/162f14b7-4fb2-4912-9f4b-db451272b78bn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages