Scilab: same legend size in multiple subplots - scilab

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.

Related

How to expand your plot so all labels can be seen without overlapping in R

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=??).

R core: legend surfaces horizontal boxes / labels only on large device dimensions, but truncates on smaller device sizes

I am using R core for plotting a grid of bar graphs. I use legend() to draw a horizontally adjacent sequence of four filled rectangles with associated labels (drawn to the right of said rectangles). When a new device / window is first created, legend() renders the two innermost elements (ie, 2 filled rectangles and associated labels) of the legend, while the left and right elements are truncated from the device view.
If I maximize the size of the device / window to fill my laptop screen, and then re-run the rendering / plotting logic from R, the legend then is properly surfaced -- comprising four columns and each element (ie, filled rectangle with label) is apportioned an equal swath of device space along the horizontal direction of the plot.
Why should device dimensions matter as to whether the legend() contains all elements on the device / window? Is there a way to fix this?
Here is the exact call I make:
legend("bottom", legendLabels, fill=c(colors), xpd=NA, horiz=TRUE, bty="n", cex=1.0, inset=c(0, -0.5), xjust=0)
I set xpd=NA because we are rendering the legend in the outer margins of the device view.
There are several adjustments in the horizontal direction that can be made in the call to legend. For compacting or expanding the allocated width for each label in the legend, I found the text.width parameter to be most effective. Again, there are other horizontal adjustments you can make, but for me, the one with the most notable impact for overall legend width was text.width:
legend(x='bottom', inset=c(0, -yInset), legend=abbrevLabels, fill=c(colors), xpd=NA, horiz=TRUE, bty="n", cex=1.0, adj=0.035, text.width=rep(meanLabelLen/7.5, length(legendLabels)))
See this related article concerning vertical adjustments.

R units of margins, text and points in a figure

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!

R-Heatmap.2 Remove huge space left between title and actual heatmap after disabling column dendrogram

I am plotting a 759*12 double matrix twoway.expr.005 using heatmap.2()
library(gplots)
dist2 <- function(x, ...){as.dist(1-cor(t(x), method="pearson"))}
heatmap.2(x=twoway.expr.005,col=bluered(75), main="Heatmap:759 genes\nTwosided Pval<0.05",tracecol= NULL, cexCol=0.8,cexRow=0.5,labCol=labs,distfun=dist2,scale="row",key=F,dendrogram='row',Colv=F)
But because I am setting dendrogram='row' (column dendrogram turned off) and key=F, my heatmap is leaving a huge whitespace between the title of the plot and the actual plot when I try to save it as a PDF.
I tried setting lhei as per the suggestion. I have used lhei=c(1,4) but it still shows me a LOT of space between the title and the plot:
heatmap.2(x=twoway.expr.005,col=bluered(75), main="Heatmap:759 genes\nTwosided Pval<0.05",tracecol= NULL, cexCol=0.8,cexRow=0.5,labCol=labs,distfun=dist2,scale="row",key=F,dendrogram='row',Colv=F,lhei=c(1,4))
Setting lhei=c(1,5) completely throws away the title:
heatmap.2(x=twoway.expr.005,col=bluered(75), main="Heatmap:759 genes\nTwosided Pval<0.05",tracecol= NULL, cexCol=0.8,cexRow=0.5,labCol=labs,distfun=dist2,scale="row",key=F,dendrogram='row',Colv=F,lhei=c(1,5))
I think Heatmap.2 is designed in such a way that the title is always placed above the column dendrogram. So if the column dendrogram is disabled, it leaves an empty space but the position of the title is still above the "disabled" column dendrogram. Is there any way to hack the code so that the title is not placed above the column dendrogram (which may be the solution to this problem)? What else can be done to remove the space between the title & the actual plot?
The lhei argument to heatmap.2 can be used to fix this. It takes a vector of length 2 that represent the relative heights of the rows of the layout of the plot.
Heatmap.2 divides the plot area in to a four blocks using the layout function. Essentially, you want to control the height of the first one relative to the second. To do this, set lhei to something like c(1, 10). This will make the bottom row, which is where the heatmap is, 10 times as tall as the top row which normally has the dendogram for the rows and the color key.
The documentation for layout has more details.
You can use title instead of setting main from within heatmap.2
title("Your title", line= -2).
You can adjust the distance by changing the value of line.
Doesn't help with left to right centering, which is still off without both dendrograms, but you'll be closer.

JFreechart get grid display dimension

How can I get the DISPLAY dimensions of my grid squares in an XY plot. I can get the tick unit, but because the plot axis is adjusted to fit the dataset, equal tick units on both axis do not always look equal, maybe because one of the axis have a larger range of values.
Is there any way to get the displayed dimensions of the grids, and not the tick unit.
Thanks
You might be able to infer something useful from getBounds() on the ChartPanel and getInsets() on the Plot. Alternatively, specify a square container and setResizable(false).

Resources