0

I have a NetCDF file of salinity in Indonesia water with 4 dimensions (lon, lat, depth and time), download data here: https://onedrive.live.com/redir?resid=6FFDD661570C7D0A%21177

I would like plot salinity data with the same range (minimum - maximum) values using levelplot (rastesVis package). Unfortunately, I get different range of value for each of my plot. The at=seq(20, 35, 2) did not define the same range in my plot?

This is my script:
# Note: Work perfectly after update 'rasterVis package'
# import data
sal <- brick('data.nc', level=1, varname = "salinity")
sal[sal == -32767] <- NA

# colorramp
jet.colors <- colorRampPalette(c('#00007F', 'blue', '#007FFF', 
                                 'cyan','#7FFF7F', 'yellow', '#FF7F00', 
                                 'red', '#7F0000'))

# create levelplot
for (i in 1:5) { # 5 different time in the same depth/level
  png = paste0('D:/sal_',i,'.png')

  png(png, width=2200, height=2200, res=300)
  print(levelplot(subset(sal,i), 
                  col.regions = jet.colors(255),
                  at=seq(20, 34, 1),
                  yscale.components=yscale.raster.subticks,
                  xscale.components=xscale.raster.subticks,
                  margin=FALSE, ylab='latitude', xlab='longitude',
                  main='salinity (psu)'))
  dev.off()
}
www
  • 38,575
  • 12
  • 48
  • 84
Eko Susilo
  • 250
  • 2
  • 15
  • It's working correctly for me. I get five different plots with exactly the same legend. – Oscar Perpiñán Apr 23 '15 at 15:00
  • On the other hand, as I suggest in the help page of `levelplot`, you may use the `layout` argument instead of the `for` loop and `subset` to get the same result: `levelplot(sal, layout = c(1, 1))`. – Oscar Perpiñán Apr 23 '15 at 15:03
  • @Oscar This is result using my script , show that the range value is have not same legend (minimum is 20 and maximum is 35) as i want. Download here https://onedrive.live.com/redir?resid=6ffdd661570c7d0a%21179 https://onedrive.live.com/redir?resid=6ffdd661570c7d0a%21181 – Eko Susilo Apr 23 '15 at 16:24
  • I think you are using an old version of `rasterVis`. Try to update the package. On the other hand, if you use `at` to define the breaks, you shouldn't use `cuts`. – Oscar Perpiñán Apr 23 '15 at 17:28
  • @Oscar Perpiñán, work perfectly after i update the **rasterVis** and remove **cuts**. Thanks you – Eko Susilo Apr 24 '15 at 13:29

0 Answers0