I am trying to plot some data in a plot where I leave a big margin free to add other information, namely text and points.
I am now struggling with keeping the size of the margin, text and points in a fixed ratio. I want this so that the layout of the figure does not change every time I plot new data.
I have:
a<-8
counter<-1
spacing<-a/(3*a)
adding<-a/(3*a)
start<-a*(a/3)
alphabet<-c("A","A","A","A","A","A","A","A")
x<-c(1,2,3,4,5,6,7,8)
y<-c(10,20,30,40,50,60,70,80)
png(file="TESTING.png", units="in", width=a, height=a, res=a*100)
par(xpd=NA,mar=c(0,0,0,0),oma=c(0,0,0,(3*a))) #bottom, left,top, right
plot.new()
plot(x,y)
points(pch=20,10, 10, cex=5)
text(10,10, alphabet, cex=5, col="blue")
this creates the image below.
What I do not understand is why the size of the point and the text is not the same and why the margin can be "bigger" than the width of the figure.
BASICALLY, the units of the margins, the points and the text are not the same...
What I need is a way to make the size of the point and text AND the margin independent of the data I plot so that the figure always looks the same although there is more data in it in some cases (for example 10 or 20 points with text in the margin).
This could be done by setting the units of points, text and margin to inches so that a is the same for all of them...
Or to know the ratio between the different units used by R for margin, points and text...
Any ideas on how to solve that?
Please let me know if clarifications are needed!
Related
I have a plot with 50 categories(states) that show on my X axis, but in my output they are on top of each other. I want my plot to be spread out engough/large enough that there is no overlap and you could determine the state value from the next.
NOTE: i used the coord_flip command, so I know that my X-axis is actually my Y in image and vice versa. I am just wondering what function I would use to fix problem.
You can always change the size of the text via themes(axis.text.x=element_text(size=...))...
But the easy answer here is that your plot will change appearance based on the aspect ratio. When you view in Rstudio, you can adjust the size of your plot and you'll see the rearrangement. Additionally, when you save, the plot, play around in particular to the height and width to get the ratio you want. ggsave('filename.png', width=??, height=??).
I want to have a multiplot in scilab with a separate legend in each subplot. What I get so far is this:
I get that the Legend entity is a child of the axis entity of the figure entity. What I don't know is how to adjust the size so that all plots and all legends are the same width. I only see the entries for position etc. if I go for figure.children(1).children(1). How do I access the legend size? Thanks!
I don't know either how to change directly the size of the legend: it seems to me, that it is always automatically calculated based on the length of the text. But there is a solution to get equally sized plots: you can set the size of the plot by the margins property of the axes. The second number adjusts the size of the "empty" space on the right hand side:
x=1:0.1:6; //generate some data
y=[sin(x);sin(2*x)];
scf(0); clf(0);
subplot(2,1,1);
plot2d(x',y');
a=gca(); //get the current axes
a.margins=[0.05,0.2,0.125,0.125]; //set the margins
legend("y1","y2",-1,%T);
subplot(2,1,2);
plot2d(x',y');
a=gca(); //get the current axes
a.margins=[0.05,0.2,0.125,0.125]; //set the same margins to get equally sized plots
legend("y___1","y____2",-1,%T);
The help says:
A vector [margin_left,margin_right,margin_top,margin_bottom] specifying the margins portion for this axes. This vector is composed of numbers between [0 1] with default: [0.125 0.125 0.125 0.125]. These numbers are ratios relative to associated values of the axes_bounds property, which are width for margin_left and margin_right, and height for margin_top and margin_bottom.
I am experimenting with the investigate_var_importance in package of bartMachine
investigate_var_importance(bart_machine_cv, num_replicates_for_avg = 20)
It turns out that the generated graph is so big, especially the text label along with the x-axis. The default [R Graphics: Device 2(Active) cannot even hold the whole picture. How to change the font size and margin of this plot?
margin can be set by par(mar=c(bottomMargin, left, up, right))
see par to set that parameter
c(0,0,0,0) will not leave any space. You might not want this, as there wouldn't be any space for the axis.
par(oma=c(bottomMargin, left, up, right))
sets the outer margins of the plot
if you send the plot to a pdf, you can increase the size of the plot, which will be able to hold the whole plot i.e,
pdf('nameOfplot.pdf', 20, 6) ## opens a device, and produces a file much wider than longer
plot whater you want
dev.off() ## closes the device you have opened with pdf
if you play with those parameters you might be able to fit your plot
I want to create a plot with magnified axis labels using cex.lab=2 but the label exceeds the plot region. Any ideas on how can I solve this?
Here is an example of the issue:
plot(1:10,1:10,ylab=~gamma,cex.lab=2)
Which produces a graph with a beheaded $\gamma$
I have done some search before asking the question both in google and in this site but my google foo betrayed me this time.
You have to set larger margin of your plot window. That can be achieved with function par() and argument mar=. Numbers correspond to margin starting with bottom, then left margin, upper and right margin.
par(mar=c(5,5,1,1))
plot(1:10,1:10,ylab=~gamma,cex.lab=2)
I'm working on visualizing a matrix in R (almost exactly like http://reference.wolfram.com/mathematica/ref/MatrixPlot.html), and I've been using
image(<matrix>,axes=FALSE)
to draw the picture. However, I noticed that with the y-axis turned off, the plot isn't centered--the space is still there for the axis ticks + label. I can finagle some centering with
par(oma=c(0,0,0,2.5))
but this seems inefficient and error-prone (if my matrix were to change dimensions/become non-square). Is there a better way to force the graphic to center?
Reference image http://img694.imageshack.us/img694/9891/metropolis.png
The right hand margin is significantly smaller than the left.
Does
par(mar=c(5,2,4,2))+0.1
help?