Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output Plots Font #222

Closed
icer182 opened this issue May 3, 2020 · 33 comments
Closed

Output Plots Font #222

icer182 opened this issue May 3, 2020 · 33 comments

Comments

@icer182
Copy link

icer182 commented May 3, 2020

Hi Brian,

I am trying to publish some MixSIAR figures for my dissertation and one of my committee members has a problem with the font size for the isospace plot and density distribution plots. I am using 2 tracers and have dug into the code for 2 tracers and the posterior plot, but am unsure where to add the pointsize variable. Can you please provide some insights about how I can quickly increase font size of the output plots? I am currently running MixSIAR 3.1.10 on Windows. I was unable to ascertain the answer from the previously asked questions.

Thank you,

Dustin

@ericward-noaa
Copy link
Collaborator

Dustin -- for the isospace plot, check out #220 -- you should be able to modify the ggplot object and adjust the font to whatever you want

#220

@icer182
Copy link
Author

icer182 commented May 3, 2020

Hi @ericward-noaa! Thanks so much for pointing me to this issue number. I am modifying the code within the "R" folder that comes inside of the "MixSIAR-master" folder that I downloaded from Github. How do I direct R to read these specific code files? Sorry, I'm semi new to R and am still figuring out package structures and how RStudio is reading packages. It seems like RStudio is reading from GitHub instead of the MixSIAR folder sitting on my desktop.

Also, am I correct in assuming I will have to add a text size variable inside of the geom_text function on lines 113, 137, 163, 185, and 207 of the plot_data_two_iso file? Additionally, which R file controls the scaled density plots?

@icer182
Copy link
Author

icer182 commented May 4, 2020

P.S. I’ve been playing with the text code within my own forked repository but haven’t had any luck getting the GUI to produce an isospace plot with text change. I have reinstalled MixSIAR several times from my own repository. Any advice you have would be much appreciated. Thank you.

@brianstock
Copy link
Owner

Hi Dustin,

All you should need to do is follow Eric's code in #220 to get the ggplot object g, and then modify using ggplot2 commands:

devtools::install_github("brianstock/MixSIAR", dependencies = T, build_vignettes = F)
library(MixSIAR)
mixsiar.dir <- find.package("MixSIAR")

# replace with path where you want to save plot files
setwd("/home/bstock/Documents/mixsiar_help/issue_222")

# replace with path to your mix file
mix.filename <- system.file("extdata", "killerwhale_consumer.csv", package = "MixSIAR")
mix <- MixSIAR::load_mix_data(filename=mix.filename,
iso_names=c("d13C","d15N"),
factors=NULL,
fac_random=NULL,
fac_nested=NULL,
cont_effects=NULL)

# replace with path to your source file
source.filename <- system.file("extdata", "killerwhale_sources.csv", package = "MixSIAR")
source <- load_source_data(filename=source.filename,
source_factors=NULL,
conc_dep=FALSE,
data_type="means",
mix)

# replace with path to your TDF file
discr.filename <- system.file("extdata", "killerwhale_discrimination.csv", package = "MixSIAR")
discr <- load_discr_data(filename=discr.filename, mix)

# make original plot, save as png
plot_data(filename="my_old_plot", plot_save_pdf=F, plot_save_png=T, mix,source,discr, return_obj=F)

isospace_plot_1_2

# new, returns ggplot object
g = plot_data(filename="isospace_plot", plot_save_pdf=F, plot_save_png=F, mix,source,discr, return_obj=T)

# now modify plot using ggplot2 commands
library(ggplot2)
png("my_new_plot.png", width=7, height=7, units="in", res=300)
g + theme(panel.border = element_blank(), panel.background = element_blank(),
    panel.grid.major = element_blank(), panel.grid.minor = element_blank(), 
    axis.line = element_line(colour = "black"),
    axis.title=element_text(size=20), axis.text=element_text(size=14),
    legend.text=element_text(size=12), legend.title=element_text(size=14))
dev.off()

my_new_plot

Not sure exactly what you want to modify... the above covers several. Also, the original png was the default low res, this is 300 dpi.

@icer182
Copy link
Author

icer182 commented May 4, 2020

Hi @brianstock. Thanks so much for the clarification. This is exactly what I was wanting to do. I'm assuming if I add text = element_text(size = 15) to the ggplot2 call, it will increase the text of the prey item types within the isospace plot. Is this true? My final question is how to do this same editing on the density distribution plots that are produced after running the model? Is there a similar type of walk through that results in a ggplot call? Thank you again for all of your help.

@jrfrun
Copy link

jrfrun commented May 4, 2020

unable to get your code to work for this operation where I can modify

I even updated to R to version 4.0.0 but still has problems with your first line of code
devtools::install_github("brianstock/MixSIAR", dependencies = T, build_vignettes = F)

in both version 3.5.3 and 4.0.0

under version 3.5.3 the error is
WARNING: Rtools is required to build R packages, but the version of Rtools previously installed in C:/rtools40 has been deleted.

Please download and install Rtools custom from http://cran.r-project.org/bin/windows/Rtools/.
Downloading GitHub repo brianstock/MixSIAR@master
Error: Failed to install 'MixSIAR' from GitHub:
Dependencies must be a boolean or a character vector

under version 4.0.0 the error is
Error: package ‘rlang’ does not have a namespace

i'm not sure what to do now

@icer182
Copy link
Author

icer182 commented May 4, 2020

That error was resolved for me when I installed Rtools. It is a necessary install for some R packages. You should visit the cran link that R has provided to install the software, then run writeLines('PATH="${RTOOLS40_HOME}\usr\bin;${PATH}"', con = "~/.Renviron") in RStudio.

@jrfrun
Copy link

jrfrun commented May 4, 2020

thanks icer182 this is not clear to me, specially since I dont use Rstudio
I tried installing Rtools but all i got was
Warning message:
package ‘Rtools’ is not available (for R version 3.5.3)

@icer182
Copy link
Author

icer182 commented May 4, 2020

@jrfrun no worries. I would recommend upgrading your R to version 4.0 and then run Rtools40. Rtools is R package specific. If you don't feel like doing this, there should be an older version of Rtools that you can download for R 3.5.3 https://cran.r-project.org/bin/windows/Rtools/history.html.

@jrfrun
Copy link

jrfrun commented May 4, 2020

I appreciate your help, but I already had version 4.0 and under that version I did not have the Rtools issue, the issue I had under 4.0 was
Error: package ‘rlang’ does not have a namespace

regards

@icer182
Copy link
Author

icer182 commented May 4, 2020

@jrfrun it looks like you have both R 3.5.3 and 4.0.0 installed. Try uninstalling R 3.5.3 and then run an update on rlang in RStudio. You can do this in the screen on the lower right hand side of RStudio. Select the packages tab and then click update. If nothing else, just remove rlang and reinstall it.

@icer182
Copy link
Author

icer182 commented May 4, 2020

We will stay tuned to hear back from @brianstock about modifying the density distribution plots. @jrfrun, I hope you have been able to fix your issue.

@brianstock
Copy link
Owner

@icer182
The source labels and locations are defined in lines 85-87 of plot_data_two_iso.R. You can search for source.labels to see it is used by ggplot2::geom_text.

For the posterior density plots, no, there isn't a similar function argument to return the ggplot2 object. It's easier to return the object for the isospace plot because there's (typically) only one, but there are several posterior density plots. Rather than have the functions return the plot object, you can download or fork the repository and modify the plotting code so it works for you. The R file is output_JAGS.R.

@jrfrun
install_github() is in the remotes/devtools package (that's what the :: means). Make sure you can run library(remotes) without error. If not, for install help see https://github.com/r-lib/remotes.

@icer182
Copy link
Author

icer182 commented May 4, 2020

@brianstock, thank you for the advice. If I download the repository, how do I then point RStudio to read the modified output_Jags.R file instead of the one originally installed using the install_github(brianstock/MixSIAR) command?

@brianstock
Copy link
Owner

You can run source("your_modified_output_JAGS.R") after library(MixSIAR), and your version will be loaded on top of the Github-installed version.

@icer182
Copy link
Author

icer182 commented May 4, 2020

@brianstock Thanks for the explanation! I am still learning R, so this has taught me something new. I appreciate your help.

@jrfrun
Copy link

jrfrun commented May 4, 2020

@brianstock yes I am able in R 4.0.0 to run library(remote) with no problem

icer182 I appreciate your suggestion of uninstalling my other R version 3.5.3,
I havent done that yet, so I hope that addressess the error of rlang

regards

@jrfrun
Copy link

jrfrun commented May 4, 2020

icer182 I went in and uninstalled R 3.5.3 since I had it in addition to R4.0.0 and you had suggest I was getting an error with rlang because of the presence of both versions, but now having only R4.0.0
I still get

devtools::install_github("brianstock/MixSIAR", dependencies = T, build_vignettes = F)
Error: package ‘rlang’ does not have a namespace

@jrfrun
Copy link

jrfrun commented May 4, 2020

I reinstalled rlang and I got past that error :)

but the next error in that code that brian provided is

plot_data(filename="my_old_plot", plot_save_pdf=F, plot_save_png=T, mix,source,discr, return_obj=F)
Error in plot_data(filename = "my_old_plot", plot_save_pdf = F, plot_save_png = T, :
unused argument (return_obj = F)

@icer182
Copy link
Author

icer182 commented May 4, 2020

Interesting. I'm not getting that error and instead receiving this one.

file("") only supports open = "w+" and open = "w+b": using the formerError in read.table(file = file, header = header, sep = sep, quote = quote, :
no lines available in input

@jrfrun
Copy link

jrfrun commented May 4, 2020

interesting, seems this code that will enable mixsiar is not sufficiently stable or robust enough

@icer182
Copy link
Author

icer182 commented May 4, 2020

I don't think that is the case. We are just missing some declaration or have incorrectly stated a variable. I am replacing code with my actual csv files.

@jrfrun
Copy link

jrfrun commented May 4, 2020

maybe, but I am not replacing anything just yet, I am trying to run exactly what Brian provided

@icer182
Copy link
Author

icer182 commented May 4, 2020

I'm not sure why it isn't working for you. The default code above worked for me

@jrfrun
Copy link

jrfrun commented May 4, 2020

icer182 just weird I just tried it now and it worked

@icer182
Copy link
Author

icer182 commented May 4, 2020

I solved the above issue by modifying this line "mix.filename <- system.file("extdata", "killerwhale_consumer.csv", package = "MixSIAR")" to read "mix.filename <- "yourfile.csv""

@icer182
Copy link
Author

icer182 commented May 4, 2020

The source labels and locations are defined in lines 85-87 of plot_data_two_iso.R. You can search for source.labels to see it is used by ggplot2::geom_text.

Hi @brianstock. I've finally had success with generating the new isospace plot, but can't figure out how to control for size of the source.labels. I have found the geom_text relating to those labels, but that line of code will not allow me to insert any size based information within the aes. Should this be going outside of the aes instead? or what would you recommend for controlling the font size for the source labels?

@icer182
Copy link
Author

icer182 commented May 5, 2020

Similarly, in the output_jags.R file under each ggplot there is a labs() function. would labs(title = my.title, text(my.title, cex = 1.5)) increase the text of the title? Please clarify @brianstock. Thank you!

@jrfrun
Copy link

jrfrun commented May 5, 2020

well I am making progress, I was able to use code to generate my isoplot but seem to have trouble storing it in g and applying modifications. it plots on the screen but does not save it to g where it can be manipulated by later commands

g=plot_data(filename="orig_plot",

  • plot_save_pdf=TRUE,
  • plot_save_png=T,
  • mix,source,discr,return_obj=T)
    Error in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
    Metric information not available for this family/device

library(ggplot2)
RStudio Community is a great place to get help: https://community.rstudio.com/c/tidyverse
png("my_new_plot.png", width=7, height=7, units="in", res=300)
g + theme(panel.border = element_blank(), panel.background = element_blank(),

  • panel.grid.major = element_blank(), panel.grid.minor = element_blank(), 
    
  • axis.line = element_line(colour = "black"),
    
  • axis.title=element_text(size=20), axis.text=element_text(size=14),
    
  • legend.text=element_text(size=12), legend.title=element_text(size=14))
    

Error: object 'g' not found

dev.off()
windows
2
g
Error: object 'g' not found

@icer182
Copy link
Author

icer182 commented May 5, 2020

Hi @jrfrun. Your feature to store g should not be manipulated because you provide the statement to store the type of font in the png function below. Make sure your original declaration of g still looks like this: g = plot_data(filename="isospace_plot", plot_save_pdf=F, plot_save_png=F, mix,source,discr, return_obj=T). Try changing "orig_plot" back to "isospace_plot" and see if that helps.

@jrfrun
Copy link

jrfrun commented May 5, 2020

icer182 thanks for the input, i'll try that but all this seems a little unclear

@icer182
Copy link
Author

icer182 commented May 6, 2020

Hi @brianstock. I just wanted to check in again about the function needed to adjust the size of the source label text in the isospace plot and the title (in my case groups small medium large) of the posterior density plots. I found the code for each, but am having a difficult time determining what function is needed and how that function should be implemented. Please let me know. Thank you.

@brianstock
Copy link
Owner

I don't want to discourage you from using the MixSIAR Issues page... but this is a relatively straightforward ggplot2 question, not specific to MixSIAR.

In ggplot functions, stuff inside aes() is for "mapping" aesthetics to variables, and stuff outside aes() affects all instances.
https://www.google.com/search?q=ggplot2+geom_text+size
https://ggplot2.tidyverse.org/reference/geom_text.html
https://stackoverflow.com/questions/25061822/ggplot-geom-text-font-size-control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants