Skip to content
Prev 377715 / 398502 Next

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

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>