Skip to content

Plotting Very Large lat-lon data in x-y axes graph

5 messages · Jim Lemon, Ogbos Okike

#
Hi Ogbos,
I have been off the air for a couple of days. Look at the color.legend
function in the plotrix package.

Jim
On Tue, Dec 11, 2018 at 12:39 PM Ogbos Okike <giftedlife2014 at gmail.com> wrote:
#
Dear All,

Thank you for your advice.

I have looked at the plotrix package and with what I gathered, I
tinkered with the code below and obtain the attached graph:
oolt<-read.table("QUERY2",col.names=c("Lat","Lon"))
 latlim<-c(20,45)
lonlim<-c(-180,180)
latbreaks<-seq(latlim[1],latlim[2],by=5)
lonbreaks<-seq(lonlim[1],lonlim[2],by=10)

mids<-function(x) {
 lenx<-length(x)
 return((x[1:(lenx-1)]+x[2:lenx])/2)
}
lonmids<-mids(lonbreaks)
latmids<-mids(latbreaks)
oolt$loncuts<-cut(oolt$Lon,lonbreaks)
oolt$latcuts<-cut(oolt$Lat,latbreaks)
counts<-table(oolt$latcuts,oolt$loncuts)
png("test.png")
library(plotrix)
countcol<-color.scale(counts,extremes=c("blue","red"))
library(maps)
map("world",xlim=c(-180,180),ylim=c(20,45))
w = map("world")
for(lon in 1:length(lonmids)) {
 for(lat in 1:length(latmids)) {
  if(counts[lat,lon] > 0)
   draw.circle(lonmids[lon],latmids[lat],radius=sqrt(counts[lat,lon]),
    border=countcol[lat,lon],col=countcol[lat,lon])
 }
}
box()
axis(1)
axis(2)
 x<-seq(-180,180,30)
 y<-seq(-90,90,30)
nx = 12
 ny = 6
grid(nx,ny,col = "red",lty="dotted",lwd=par("lwd"),equilogs=TRUE)
testcol<-color.gradient(c(10,30),0,c(30,10),nslices=5)
color.legend(-180,-130,100,-150,countcol,testcol,gradient="x")

I now have the horizontal color legend.

But I have two major problems still.
(1) The black line on top of the color bar is meaningless and I want it go.
(2) I want the numerical values plotted to appear on the color bar
(see the color.legend.png attached please) such that it can be used to
interpret the map.

I would be most grateful for any further assistance.

Very best wishes
Ogbos
On Tue, Dec 11, 2018 at 11:14 AM Jim Lemon <drjimlemon at gmail.com> wrote:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.png
Type: image/png
Size: 54480 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20181211/787cd39d/attachment.png>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: color.legend.png
Type: image/png
Size: 11630 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20181211/787cd39d/attachment-0001.png>
2 days later
#
Hi Ogbos,
Back on the air after a few days off. I don't have your data ("QUERY
2"), but I think this will fix your problem.

library(maps)
map("world")
box()
library(plotrix)
color.legend(-180,-150,100,-130,legend=c(0,25000,50000,75000,100000),
 rect.col=color.scale(1:5,extremes=c("blue","red")),gradient="x")

Notice that I have swapped the "yb" and "yt" values so that they are
in increasing order. If they are reversed, the numbers will appear
within the color bar. Also you don't need to call color.gradient, just
pass the output of a five increment color scale from blue to red (or
whatever you like) to the rect.col argument.

Jim
#
Dear Jim,
Good news to me!! Welcome.

I am fine. The code elegantly displayed the color.

I also tried to adjust the line:
draw.circle(lonmids[lon],latmids[lat],radius=sqrt(counts[lat,lon])/100,
    border=countcol[lat,lon],col=countcol[lat,lon]) in order to reduce
the radius of the circle in order to plot the whole data.

I am really really grateful. I will immediately include the result in
a draft manuscript to Astrophysical Journal.

With the warmest regards
Ogbos
On Thu, Dec 13, 2018 at 9:04 PM Jim Lemon <drjimlemon at gmail.com> wrote:
#
Dear Jim,
Attached is a plot generated by the code for one year lightning data.

Instead of lightning flashes happening randomly at all points over the
globe, there is a kind of constraint making lightning to be aligned
straight on the longitudes.

I suspect the problem is coming from seq function in the code:
latbreaks<-seq(latlim[1],latlim[2],by=2)
lonbreaks<-seq(lonlim[1],lonlim[2],by=10).

I tried to remove them but found it difficult.

Part of the data (see below) shows that lightning happens at all
latitudes and longitudes and as such, cannot be plotted to appear only
on straight lines:
0.8312   95.2156
 -3.3851  -65.3236
 -3.2696  -65.2364
 -3.2679  -65.2349
-17.6404  164.7025
 -4.8285  148.8214
  2.6477  -67.6568
 -0.2350  -73.4833
-16.8655   40.9587
  8.1179  -61.6474
 -0.2755   93.3401
-17.1733  119.9011
  1.1245  -69.7640
-20.0035 -149.3088
 -3.4200  177.8753
  3.0133  -67.5590
 15.4684  -21.9331
-17.6166  120.2656
-17.3888  165.9368
-17.6953  164.7335
 -1.8623  -74.0017
 -3.3562  -71.1195
-11.5775  130.1496
-11.5720  130.4004
 18.7159  -21.0251
 -9.3788  -75.0815
 -2.8341  -71.9095
 -2.8276  -71.9380
-19.0845  166.5715
  1.3692  -69.8615
  1.0989  -69.8881
  1.0351  -69.9390
  1.3306  -69.9484
 13.4238  -83.6240
-18.2490  165.4406
  2.8831  -67.6648
  3.0405  -67.4912
  1.2068  -70.0177
-34.6024  -67.2998
 -8.6378  -46.0881
-17.7834  119.7202
  2.5582  -69.4447
 -6.8894  -47.9581
-16.6939   40.7143
  1.4648  -69.7636
  4.5290  -62.5343
  4.6965  -62.6023
-18.9731  166.2414
 -3.6024  173.9586
 -3.4901  173.8333
 -3.8061 -176.4053
-16.7814  -53.0986
 -0.6284  -70.7341
 -3.1878  -71.8722
 -4.3205  176.7693
 -4.3616  176.8269
-16.8295  119.7462
  2.1829  -62.9190
-16.6656   42.0181
  3.5589  -61.7756
  1.3026  -69.9409
 33.3995   13.4344
  3.0125  -67.6869
  3.0155  -67.7028
 -7.3156  -48.0353
-17.5709  164.6291
 33.0699   14.3376
 -5.6291  -48.6772
 -2.8796  -71.8747
 -2.6448  -71.5548
 -3.0977  -71.5027
  1.1513  -69.8094
  1.1024  -69.8070
 -3.6739  -65.2433
 25.9860  -51.3312
 26.0156  -51.4377
 -6.1894  -56.5574
  3.2794   95.4703
 18.6850  -20.8606
  2.8957  -68.6864
  1.0930  -69.7733
  1.4467  -69.7631
-17.8441   27.0904
  1.4039  -69.9049
  0.9384  -69.8649
 -2.2356  170.8400
  2.7273  -67.6561
  5.2676  -62.7957
-16.9645  119.2204
 33.2544   13.6508
 -6.8735  -48.0914
-17.5725  120.1941
 10.8718  -59.0204
  1.9115  -62.8357
  2.4337   -4.8253
-17.2323  119.7706
 -7.4806  -47.9645
-13.0036  166.4029
-16.6861  -53.0932
-17.5506  164.3730
  2.2578  158.9620
 -2.9222  177.1345
  5.2906  -62.6111
  5.0903  -62.5855
  2.2920   91.7130
 -6.2985  -55.5143
  2.9048  -67.6558
  3.0313  -67.6569
 -1.5240  -71.0068
  1.4910  -69.3833
  3.0779  -67.7509
  2.8380  -67.7203
Thanks for more inputs.
Ogbos
On Thu, Dec 13, 2018 at 9:04 PM Jim Lemon <drjimlemon at gmail.com> wrote:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: testB2.png
Type: image/png
Size: 107473 bytes
Desc: not available
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20181214/c584bd3d/attachment.png>