JFreechart get grid display dimension - grid

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

Related

Decorana on R and using xlim

So I've been running a DCA analysis on a species/site count spreadsheet (DCA file made using Vegan and decorana command). I'm having a bit of overlap with my points, so I'm trying to extend DCA 1 axis. I keep trying to use the xlim value to narrow it down to -2,2, but it just won't do it. For some reason, it seems tied to the ylim value. If I drop the ylim to -1,1, that will force the xlim to -2,2, but I can't actually have the ylim that small.
> plot(DCA, type = "n", xlim = c(-2,2))1
First plot shows result of this command. Trying to include a ylim of (-2,2) didn't change it either. Second plot shows result of this command:
> plot(DCA, type = "n", xlim = c(-2,2)), ylim = c(-2,2)2
I'm not exactly an expert at this, and I feel like I might be making a stupid mistake. Anyone got any ideas?
The plot is enforcing equal aspect ratio, and if you insist on having full range on y-axis (you do not set ylim), the x-axis will be set to accommodate the range you want to show on y-axis. You must either change the shape of your graphics display for a shorter x-axis, or then you also must set the range on y-axis with ylim Your choice. If you draw on square graphics window, the output will be square and it will be taken care that both the x and y scale (xlim, ylim) will fit the square. Changing the shape of the graphics window or setting both limits will help. Function locator() can be used to query coordinates in an existing plot, and these can be used to set up the new limits.
It is better to start again from a clean table. My intention was not to be rude, but trying to complement the answer in comments leads into terse messages where details and special cases are hard to handle. So I try to explain here how you can control the display and the axis limits in vegan ordination graphics. This answer has two main parts: (1) why we insist on equal aspect ratio, and (2) how to survive with equal aspect ratio. The latter can indeed be tricky, but we have not made it tricky because we are evil, but it is necessarily tricky.
First about the equal aspect ratio. This means that the numeric scales is equal on vertical (y) and horizontal (x) axes. In ordination the "importance" of an axis is normally reflected by its length: important axes are long, minor axes are short. In eigenvector methods this is determined by eigenvalues (which actually define the scatter of points along axes). In DCA (decorana) it should be the SD scaling so that one unit is equal to average width of species responses. We pay great attention in scaling axes accordingly, and we want to show this in the plot so that long x axis remains long and short y axis remains short even when the graph is designed for a portrait printer page shape. In this way the axis scaling (tic values) are equally spaced on both axes, and distances in the graph are equal horizontally, vertically or diagonally. Also if you draw a circle in the plot, it will remain a circle and not flattened or elongated to an ellipse. So this is something that we insist as a necessary feature of an ordination graph.
Insistence on equal scaling of equal axes comes with a price. One obvious price is that the ordination plot may not fill the graph area, but there can be a plenty of empty space in the graph for shorter axes. You can get rid of this adjusting graph shape – typically making it flatter. Another price that must be paid is the one that bit you: setting axis limits is tricky. However, this is not a vegan invention, but we use base R plot command with option asp = 1 for equal aspect ratio of axes.
To see how we can set axis limits with equal ratio, let us generate a regular rectangular grid and plot it:
x <- seq(-2, 2, by=0.2)
xy <- expand.grid(x, x)
plot(xy, asp=1)
This is a square grid on a square plot and nothing very special. However, if we plot the same grid on rectangle the aspect ratio remains equal, numeric scales are equal and the points remain equidistant on a square, but there is a lot of empty space and x-axis has longer numeric scale (but the points have unchanged numeric scale). If we try reduce only the x-scale, we face a disappointment:
plot(xy, asp=1, xlim=c(-1,1), main="xlim=c(-1,1)")
The graph is essentially similar as the first unlimited case with unchanged x. Setting xlim does not remove any points, but it only tells plot that do not reserve space but for that range on x-axis. However, y-scale is still longer and with equal aspect ratio it will also set the scale for x-axis and since there is empty space in the graph, the points are plotted there (this is analogous to having empty space even when there is nothing to plot there). To really limit the x-axis, you must simultaneously limit the y-axis accordingly:
plot(xy, asp=1, xlim=c(-1,1), ylim=c(-1,1), main="xlim=c(-1,1), ylim=c(-1,1)")
This give the desired x-limits .
Like I wrote, we did not invent that nastiness, but this is base R plot(..., asp=1) behaviour. I know this can be tricky (I have used that myself and sometimes I get irritated). I have been thinking could we be more user-friendly and by-pass base R. It is pretty easy to do this in a way that works in many normal use cases, but it is much harder to do this so that it works in most cases, and I don't know how to do this in all possible cases. If anybody knows, pull requests are welcome in vegan.
Finally, there is one tool that may help: vegan has an interactive dynamic plotting tool orditkplot where you can zoom into a plot by selecting a rectangle with left mouse button. However, this function may not work in all R systems, but if it works it gives an easy way of studying details of the plot (but if you have Mac with one-button mouse, don't ask me how it works: I don't know). You can start this with
orditkplot(mod, display="sites") # or "species", but only one
Even without orditkplot you can use base R function locator(): click the diagonally opposite corners of the rectangle you want to focus on, and this give you the xlim and ylim you need to set to zoom into this rectangle.

Scilab: same legend size in multiple subplots

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.

ggplot - specify coordinate in middle of plot, regardless of scale

I would like to add a rectangle to my scatter plot to specify a region. I know I can do this by calling geom_polygon and specifying the X- and Y-coordinates of the corners. However, I would like to make sure the rectangle is always half (or another fraction) of the height of the plot, regardless of what the scale of the points on the plot is.
Is there any way I can specify the coordinates of the corners with something like "fraction of plotting region" as the unit?
The only other option I see is to try to predict the scale of the plot by looking at the min() and max() of the points that I am plotting and then calculating the coordinates for the box based on that, but that becomes a lot more complicated once you start faceting and so on...

Line Chart leaving gaps in data

I have a Flex line chart where I allow the user to change the y axis ranges. When a data point falls outside the ranges, the chart drops the line segments on either side of the out of range point leaving a gap in the data line.
I'm currently using the data function to clamp the values out of range to the y axis min/max, but this displays misleading data.
Is there a way to make it draw the lines to the y axis max/min point, making it look like the line goes off the plot?
There is a parameter filterDataValues in LineSeries - set it to "none" and it should do the trick.

How can one create a double horizontal axis for a plot in ggplot2?

I need to show the values on the horizontal axis (aka abscissa, aka x-axis) converted into other units. Hence the need for a second axis.
It is not currently possible. Hopefully after this summer.

Resources