I cannot somehow figure out how to resize the R graph, I am getting in my JupyterNotebook. No matter what I put in width or hight in options, it still remains this same.
The value of jobmemberid is a numeric data that I had to turn into a character. I feel like the bars are also of a different size, so it would be great to know if I can keep them constant.
Any hints how to go about it would be highly appreciated.
Related
I'm making a gif using Julia Plots, however, as the frames progress the grid autoscales making it seem very jittery, if anyone knows if I can simply set the exact size of the grid such that it remains stagnant that would be a great help.
scatter(planex, planey, markersize=1.2, aspect_ratio=:equal, xlims=(-2.5,2.5))
^ this is the line that plots x and y the values (planex and planey)
I tried setting the x-limits and aspect ratio expecting it to keep the frames from resizing.
What resulted is that after a large amount of frames the image stops deforming but in earlier parts it still jitters.
Have you tried also setting ylims?
I am not sure if this is possible, but I was wondering if I could expand the parameters of a base R plot. I am aware you can change the resolution/sizing of the graphs when you go to save them, but this isn't what I want to do. I was wondering if there is a command to stretch out the x/y-axis without increasing the range. I attached a picture of the graph I produced, which I feel is quite cramped and small. Below is also my code, which I don't think is an issue but wanted to attach anyways just to be safe. I'd appreciate any help, thank you so much!
plot(O2water, -1*O2rate,xlim=c(19,21.25))
abline(v=20.1)
I am trying to create a figure of a map of a continuous trait onto a phylogenetic tree using the ape and phytools packages in R for a publication. An example code of what I am trying to produce is as follows:
library("ape")
library("phytools")
orig_tree<-rtree(n=350)
plot(orig_tree)
values<-data.frame("residuals"=runif(350,min=-1,max=1),row.names=orig_tree$tip.label)
values<-setNames(values$residuals,rownames(values))
residualsignalfit<-fastAnc(orig_tree,values,vars=TRUE,CI=TRUE)
obj<-contMap(orig_tree,values,plot=FALSE)
plot(obj,type="fan",fsize=.1,lwd=0.5)
The only difference is the terminal of the branches are all the same length because they are all living taxa, but this works well enough to illustrate the problem I am having. I have a large number of taxa in this tree, and as a result I have to shrink the text down fairly small using the fsize= argument to make them legible. However, as you can see from the example code, doing so causes the ends of each species name to be obscured by the outline for the phylogenetic tree. I have tried removing the outline but it makes the heatmap of the phylogeny very hard to read. I have been unable to find any way to reduce the thickness of the outline, it seems to be automatically generated.
I also tried adding the cex command to plot(obj...), but it has no effect on the produced tree at all.
What I am trying to figure out how to do is how to position the tip labels in order to make them more legible and not covered up by the outline for the tree. I cannot simply add a space in front of each terminal using the dplyr mutate function or something like that because the position of the taxon name is not always consistent, sometimes the left side of the name is attached to the tip and other times it is the right side. I have tried not plotting the data as a fan, but this ends up creating a figure with a huge amount of dead space due to the fact I have some very deep splits within the tree (basically plotting the figure as a right-facing tree results in half of the figure being dead space because my taxa diverged in the Mesozoic but only speciated after the K-T boundary).
Instead of shrinking the text down, you can scale the tree up. You can export the plot as image with a specific width and height. Setting both to 20 should make all tip labels legible.
Something like
setEPS()
postscript("output.eps", width = 20, height = 20)
plot(obj,type="fan",lwd=0.5)
dev.off()
This saves the plot to output.eps instead of showing it in the default viewer. So it is not restricted by the screen size. You still need to fiddle around with the best values of lwd and fsize, but in my experience it is much easier, when you have a big canvas.
Edit: Sorry, the unit of width and height is inches not pixels. So rather set it to 10 or 20.
This is a question that has me banging my head against a wall for a while now. Much of R coding produces consistent results when used for analysis, in a sense that sometimes there are more than one ways to achieve something but your output would be something shareable and consistent. Let's say a dataframe or a datatable and so on and so forth.
However, I'm finding myself struggling to understand how can I achieve a mainstreamed process when generating plots. Font size, margin size, height, width and resolution. All those influence each other.
You change your resolution and suddenly your font size changes drastically when saving with png(). You go back and you change the dimensions and there you are with extremely small font size or with a pixeled chart looking at you.
So, because I still trust in the ggplot and png() process and believe that it must be me that messes up or doesn't do the correct steps in his workflow the question is:
What is the sweet point between all those factors that makes plotting with R easy, consistent and high-quality?
I understand that some of these factors cannot be standardised since it depends on the amount of information and how complex a chart is. But how do others ensure consistent font size against changes in resolution, height, width and plot margins?
I've came across some useful resources such as:
[https://blog.revolutionanalytics.com/2009/01/10-tips-for-making-your-r-graphics-look-their-best.html][1]
[https://support.rstudio.com/hc/en-us/articles/200488548-Problem-with-Plots-or-Graphics-Device][1]
But none really speaks to how you mainstream a visualization process in R. Still great tips though.
Any advice or ideas are honestly appreciated. Thank you.
This may sound weird, or impossible but I can say the scale of the output plot when you compile inside R and view it without zooming or exporting works great for me. However, when I export to pdf, the plot becomes outrageously large and I never manage to scale it to what I see inside R. Am I being silly, or there is actually a difference and there is a way to get what I see inside that bottom-left-corner box of the R.
use ggsaves width and length arguments to get the desired size.
ggsave('name.pdf', width =14, height = 8)