plotting degrees in IDL - plot

I'm using IDL 8.2
I have a list of positions (RA and Dec) of stars and i want to plot them on a figure, eg.
37.9 ~ 37 54' 0"
37.7 ~ 37 42' 0"
I read in the positions (degrees) in as strings and extract the degrees, minutes and seconds into separate arrays. These are then used to convert the values to decimal degrees for plotting here.
I would like to also have the alternate axis labelled with degrees. i.e.
37.9 ~ 37 54' 0"
37.6 ~ 37 42' 0"
Is there a way to do this other than using something like power point to do it?
Also is there a better way, than having the axis scaled the same, to force the plot to be a square plot using the plot procedure?

A good solution was posted here.
https://groups.google.com/forum/#!starred/comp.lang.idl-pvwave/EsbGiqZnhRw
Effectively, writing a function to perform write user defined tick marks.

Related

gnuplot with 2 x axis from data points

I have a data file, the data for y axis are in the third column. I would like to have the scale given by the first column on the x1 and by the second column on the x2. The standard way would be to:
plot data u 1:2 axes x1y1, data u 1:3 x2y1
But that creates two plots which is something I want to avoid. Of course one could make the above work with colours or with some other dirty tricks. It makes the whole plot code very cumbersome. Another nice way is to use multiplot as suggested here. But this is not really my goal, as I want to have the the real x2 axis.
Another way that came to my mind was to set x2range but that means going to the source file and figuring out the min and max or using some statistics in gnuplot (which feels like a waste of time for such a simple thing).
Is there any more simple and elegant way than the above ones? (I am especially concerned about the solution to be short to write, the plot can consist of several (>5) datasets and doing and I want to avoid plotting each dataset twice.
This can be done in this way, by telling gnuplot to re-scan file with 2nd column as x2 values but only invalid y-values for this second plot:
set xtics nomirror
set xrange [:] noextend
set x2tics
set x2range [:] noextend
plot '/tmp/f.gdat' u 1:3 w l, '' u 2:(1/0) ax x2y1
As an example, you can plot this data with Celsius on x and Fahrenheit on x2:
0 32 0
30 86 1
60 140 2
90 194 3
Note that this will only be sensible if column 2 is affinely linked with column 1. If you know the affine relation, using set link is much better.

Labelling issue after using gap.plot to create an axis break

I've been struggling to get a plot that shows my data accurately, and spent a while getting gap.plot up and running. After doing so, I have an issue with labelling the points.
Just plotting my data ends up with this:
Plot of abundance data, basically two different tiers of data at ~38,000, and between 1 - 50
As you can see, that doesn't clearly show either the top or the bottom sections of my plots well enough to distinguish anything.
Using gap plot, I managed to get:
gap.plot of abundance data, 100 - 37000 missed, labels only appearing on the lower tier
The code for my two plots is pretty simple:
plot(counts.abund1,pch=".",main= "Repeat 1")
text(counts.abund1, labels=row.names(counts.abund1), cex= 1.5)
gap.plot(counts.abund1[,1],counts.abund1[,2],gap=c(100,38000),gap.axis="y",xlim=c(0,60),ylim=c(0,39000))
text(counts.abund1, labels=row.names(counts.abund1), cex= 1.5)
But I don't know why/can't figure out why the labels (which are just the letters that the points denote) are not being applied the same in the two plots.
I'm kind of out of my depth trying this bit, very little idea how to plot things like this nicely, never had data like it when learning.
The data this comes from is originally a large (10,000 x 10,000 matrix) that contains a random assortment of letters a to z, then has replacements and "speciation" or "immigration" which results in the first lot of letters at ~38,000, and the second lot normally below 50.
The code I run after getting that matrix to get the rank abundance is:
##Abundance 1
counts1 <- as.data.frame(as.list(table(neutral.v1)))
counts.abund1<-rankabundance(counts1)
With neutral.v1 being the matrix.
The data frame for counts.abund1 looks like (extremely poorly formatted, sorry):
rank abundance proportion plower pupper accumfreq logabun rankfreq
a 1 38795 3.9 NaN NaN 3.9 4.6 1.9
x 2 38759 3.9 NaN NaN 7.8 4.6 3.8
j 3 38649 3.9 NaN NaN 11.6 4.6 5.7
m 4 38639 3.9 NaN NaN 15.5 4.6 7.5
and continues for all the variables. I only use Rank and Abundance right now, with the a,x,j,m just the variable that applies to, and what I want to use as the labels on the plot.
Any advice would be really appreciated. I can't really shorten the code too much or provide the matrix because the type of data is quite specific, as are the quantities in a sense.
As I mentioned, I've been using gap.plot to just create a break in the axis, but if there are better solutions to plotting this type of data I'd be absolutely all ears.
Really sorry that this is a mess of a question, bit frazzled on the whole thing right now.
gap.plot() doesn't draw two plots but one plot by decreasing upper section's value, drawing additional box and rewriting axis tick labels. So, the upper region's y-coordinate is neither equivalent to original value nor axis tick labels. The real y-coordinate in upper region is "original value" - diff(gap).
gap.plot(counts.abund1[,1], counts.abund1[,2], gap=c(100,38000), gap.axis="y",
xlim=c(0,60), ylim=c(0,39000))
text(counts.abund1, labels=row.names(counts.abund1), cex= 1.5)
text(counts.abund1[,1], counts.abund1[,2] - diff(c(100, 38000)), labels=row.names(counts.abund1), cex=1.5)
# the example data I used
set.seed(1)
counts.abund1 <- data.frame(rank = 1:50,
abundance = c(rnorm(25, 38500, 100), rnorm(25, 30, 20)))

Identifying points in a curve

I feel like this is an easy question...
How do you identify coordinates in a figure? I plotted some data, used unireg (the uniReg package) to make a spline curve, and want to pull out the data from a point.
library(uniReg)
P0mM <- read.table(text="
Time FeuM
0.04 138.8181818
7 1258.636364
14 1320.545455
21 2110.37037
28 13730.37037
35 1550.909091",header=TRUE)
z=seq(min(P0mM$Time),max(P0mM$Time),length=201)
uf=with(P0mM,unireg(Time,FeuM,g=5,sigma=1))
plot(FeuM~Time,P0mM,ylim=c(0,16000),ylab="Fe2+ uM", xlab="Time", main="0mM P")
lines(z,uf$unimod.func(z))
I was able to find the max y value of the curve (which is 14444)
max((uf$unimod.func(z)))
I want to identify where on the x axis this happens. (Should be around 30, but I want to be exact).
How do you do this?
Thanks!
Seems like a case for optimise or optimize (depending on your affinity with British or American English):
optimise(uf$unimod.func, maximum=TRUE, interval=range(P0mM$Time))
#$maximum
#[1] 29.27168
#
#$objective
# [,1]
#[1,] 14444.85

Plot from two files with errorbars for Gnuplot

I am thinking which way to do the addition of errorbars better by thinking the format of data.
The standard way of adding errors bars is discussed here, for instance.
My original data is in ranges
Model Decreasing Constant Increasing
2025 73-78 80-85 87-92
2035 63-68 80-85 97-107
2050 42-57 75-90 104.5-119.5
where the values are ranges.
I cannot plot directly in Gnuplot so I have to split it to averages and to error values in two files:
Averages:
Model Decreasing Constant Increasing
2025 75.5 82.5 89.5
2035 65.5 82.5 102
2050 49.5 82.5 112
and error configuration in ybar
Model Decreasing Constant Increasing
2025 2.5 2.5 2.5
2035 2.5 2.5 5
2050 7.5 7.5 7.5
I normally plot data like this as a one file
plot for [i=2:4] 'data.dat' using 1:i w linespoints
but now I should go through two files at the same time while doing the plot.
The normal syntax of plotting errorbars is
plot 'data' using 1:2:0:($1+$3):4:5 with yerrorlines
and manual here.
How can you plot from two files with errorbars in Gnuplot?
Feel free to propose if you know better way to do the addition of these errorbars in gnuplot.
Output to Cristoph's answer
where error bars missing in the first and third points.
Gnuplot 5 supports that you specify several characters as data file separators.
So, if you are sure you'll never get negative values (which I hopen given the format of your data), then you can use your original data file and set both white space and hyphen as datafile separator:
set datafile separator " -"
plot for [i=2:6:2] "data" using 1:(0.5*(column(i)+column(i+1))):(0.5*(column(i+1)-column(i))) with yerrorlines
First of all, I wonder about your columns used for plotting with yerrorlines. If your first data for 2025 is 75.5+/-2.5, you usually plot it with
plot "datafile" using <xcolum>:<ycolum>:<yerrorcolumn>
Your six columns are for the case of xy errorbars and specify the point itself and the lower and upper absolute values in x and y. But may be you are just doing it as you need it...
Now back to your question:
Gnuplot can not handle data from two files simultaneously, i.e. it can not take xy-values from one file and y-errors from another.
If you're running linux, the command line tool join can help.
Your averages stored in file A and the errors in file B, join A B will concatenate lines with the same value in the first colum like this:
2025 75.5 82.5 89.5 2.5 2.5 2.5
So,
plot "<join A B" using 1:2:5 with yerrorlines
should do the job. ("<join A B" will call the join command in the background and read its output like a data file)

Plotting of coordinates in R

I have a number of coordinates and I want to plot them in a gridded interface by using R.
The problem is that the relative distance between observations is large. Coordinates are in a geographic coordinate system and the study area is Switzerland. Moreover, id of the points is required to be plotted.
The problem is that two clusters of the points are dense and some other points are separated with a large distance. How I can plot them in a proper way to have readable presentation? Any suggestion for plotting the data?
Preferably, do not use ggplot as I used it before and it did not present proper results.
Data:
id x y
2 7.1735 45.86880001
3 7.17254 45.86887001
4 7.171636 45.86923601
5 7.18018 45.87158001
6 7.17807 45.87014001
7 7.177229 45.86923001
8 7.17524 45.86808001
9 7.181409 45.87177001
10 7.179299 45.87020001
11 7.178359 45.87070001
12 7.175189 45.86974001
13 7.179379 45.87081001
14 7.175509 45.86932001
15 7.176839 45.86939001
17 7.18099 45.87262001
18 7.18015 45.87248001
19 7.18122 45.87355001
20 7.17491 45.86922001
25 7.15497 45.87058001
28 7.153399 45.86954001
29 7.152649 45.86992001
31 7.154419 45.87004001
32 7.156099 45.86983001
GSBi_1 7.184 45.896
GSBi__1 7.36 45.901
GSBj__1 7.268 45.961
GSBj_1 7.276 45.836
GSB 7.272 45.899
GSB_r 7.166667 45.866667
Location of points:
As you can see in the plot, the points' ids are not readable both for the dense parts and others.
Practically, it is not always possible to ensure that all points are visually separable on the screen when plotting a set of points that contains very close and very far points at the same time.
Think of a 1000x800 pixel screen. Let's say we have three points A, B and C that are located respectively on the same horizontal line such that: the distance between A and B is 1 unit and the distance between A and C is 4000 unit.
If you map this maximum distance (4000 unit) to the width of the screen (1000px). Then a pixel will correspond to 4 units in horizontal. That means A and B will fit into one pixel since the distance between them is only 1 unit. So, they will not be visually separable on the screen.
Your points are far too close to really do too much with, but an idea might be spread.labels from plotrix:
opar <- par()
par(xpd=TRUE)
plot(dat$x, dat$y)
spread.labels(dat$x,dat$y,dat$id)
par(opar)
You may want to consider omitting all the numerical labels and placing them in a different graph.

Resources