2626# ' @param export.format "png" or "pdf" format.
2727# ' @param lon.points vector of longitudes for grid points to be marked in the map.
2828# ' @param lat.points vector of latitudes for grid points to be marked in the map.
29- # ' @export plot.Grid
29+ # ' @export plotFun.grid
3030# ' @details Packages classInt and maps needed.
3131# ' @import classInt maps
3232# ' @author Ana Casanueva (24.05.2017)
3636# ' y <- seq(35,55); n=length(y)
3737# ' tas <- array(runif(n*m*6, -5, 30), dim=c(6,m,n)) # time, lon lat.
3838# ' # Single plot
39- # ' plot.Grid (tas[1,,], lon=x, lat = y, lonLims = c(-10,30), latLims = c(35,65), width.cbar = 0.2,
39+ # ' plotFun.grid (tas[1,,], lon=x, lat = y, lonLims = c(-10,30), latLims = c(35,65), width.cbar = 0.2,
4040# ' breaks = seq(10,20), title.main = "Mean Temp.", unit.text = "degC", cex.main=1.5)
4141# ' # Multi-plots
42- # ' plot.Grid (list(tas[1,,], tas[2,,], tas[3,,], tas[4,,], tas[5,,], tas[6,,]),
42+ # ' plotFun.grid (list(tas[1,,], tas[2,,], tas[3,,], tas[4,,], tas[5,,], tas[6,,]),
4343# ' lon=x, lat = y, lonLims = c(-10,30), latLims = c(35,65), lattice=c(2,3), width.cbar = 0.1,
4444# ' breaks = seq(10,20), window.height = 8, window.width = 12,
4545# ' title.single = c("Temp1","Temp2","Temp3","Temp4","Temp5","Temp6"), cex.single = 1.3,
4848
4949
5050
51- plot.Grid <- function (data , lon , lat , lonLims = c(min(lon ),max(lon )), latLims = c(min(lat ),max(lat )), lattice = NULL , breaks = NULL , palette = rainbow(10 ), window.width = 8 , window.height = 6 , title.main = NULL , title.single = NULL , unit.text = NULL , cex.main = 1 , cex.single = 1 , cex.unit = 1 , cex.textcbar = 1 , width.cbar = 0.1 , disp.warnings = FALSE , export = FALSE , export.format = NULL , export.path = NULL , lon.points = NA , lat.points = NA ){
51+ plotFun.grid <- function (data , lon , lat , lonLims = c(min(lon ),max(lon )), latLims = c(min(lat ),max(lat )), lattice = NULL , breaks = NULL , palette = rainbow(10 ), window.width = 8 , window.height = 6 , title.main = NULL , title.single = NULL , unit.text = NULL , cex.main = 1 , cex.single = 1 , cex.unit = 1 , cex.textcbar = 1 , width.cbar = 0.1 , disp.warnings = FALSE , export = FALSE , export.format = NULL , export.path = NULL , lon.points = NA , lat.points = NA ){
5252
5353 # Verification checks
5454 try(if (export & is.null(export.format )) stop(" Cannot save plot: missing export.format" ))
@@ -72,11 +72,11 @@ plot.Grid <- function(data, lon, lat, lonLims=c(min(lon),max(lon)), latLims=c(mi
7272 if (is.null(breaks )) breaks <- set.Breaks(data )
7373
7474 # Plot
75- plot.Grid1 (data , lon , lat , lonLims , latLims , breaks , palette , cex.main , title.main , lon.points = lon.points , lat.points = lat.points )
75+ plotFun.grid1 (data , lon , lat , lonLims , latLims , breaks , palette , cex.main , title.main , lon.points = lon.points , lat.points = lat.points )
7676
7777 # Include colorbar
7878 par(mar = c(3 ,0.6 ,3 ,5 ))
79- plot .colorbar(breaks , palette , unit.text , cex.unit , cex.textcbar )
79+ plotFun .colorbar(breaks , palette , unit.text , cex.unit , cex.textcbar )
8080
8181 } else {
8282 # Number of real plots to make
@@ -110,7 +110,7 @@ plot.Grid <- function(data, lon, lat, lonLims=c(min(lon),max(lon)), latLims=c(mi
110110
111111 # Plot subplots
112112 for (i in 1 : n ){
113- plot.Grid1 (data [[i ]], lon , lat , lonLims , latLims , breaks , palette , cex.single , title.single [i ], lon.points = lon.points , lat.points = lat.points )
113+ plotFun.grid1 (data [[i ]], lon , lat , lonLims , latLims , breaks , palette , cex.single , title.single [i ], lon.points = lon.points , lat.points = lat.points )
114114 }
115115
116116 # Fill with empty plots when necessary (i.e. to fill the matrix)
@@ -124,60 +124,11 @@ plot.Grid <- function(data, lon, lat, lonLims=c(min(lon),max(lon)), latLims=c(mi
124124
125125 # Include colorbar
126126 par(mar = c(3 ,0.6 ,3 ,4 ))
127- plot .colorbar(breaks , palette , unit.text , cex.unit , cex.textcbar )
127+ plotFun .colorbar(breaks , palette , unit.text , cex.unit , cex.textcbar )
128128 # Plot title
129129 mtext(title.main , outer = TRUE , cex = cex.main )
130130 }
131131
132132 if (export & ! is.null(export.format ) & ! is.null(export.path )) dev.off()
133133}
134134
135- # ' Plot grid (single plot).
136- # '
137- # ' Plot a figure based on a regular grid, for a single plot.
138- # '
139- # ' @param x matrix to be plotted.
140- # ' @param lon array of longitudes
141- # ' @param lat array of latitudes
142- # ' @param lonLims 2-elemtent vector with the range of longitudes to be plotted. By default all the data is plotted.
143- # ' @param latLims 2-elemtent vector with the range of latitudes to be plotted. By default all the data is plotted.
144- # ' @param breaks vector of values defining the intervals to be used in the colorbar.
145- # ' @param palette character vector with the colors for the plot. They will be interpolated to match the number of intervals defined by breaks.
146- # ' @param title.main character string with the title.
147- # ' @param cex.main numeric value giving the title expansion factor. Default: 1.
148- # ' @param lon.points vector of longitudes for grid points to be marked in the map.
149- # ' @param lat.points vector of latitudes for grid points to be marked in the map.
150- # '
151- # ' @author Ana Casanueva (16.02.2017)
152- # '
153-
154- plot.Grid1 <- function (x , lon , lat , lonLims ,latLims , breaks = breaks , palette = palette , cex.main , title.main , lon.points = lon.points , lat.points = lat.points ) {
155-
156- # Plot subregion or not
157- ind.x <- which(lon > = lonLims [1 ] & lon < = lonLims [2 ])
158- ind.y <- which(lat > = latLims [1 ] & lat < = latLims [2 ])
159- lon <- lon [ind.x ]
160- lat <- lat [ind.y ]
161- x <- x [ind.x , ind.y ]
162-
163- # Number of intervals to plot
164- lev <- length(breaks )- 1 ;
165-
166- # Interpolate palette to the number of levels
167- cols <- colorRampPalette(palette )(lev )
168-
169- # set values above and below the break to the maximum and minimum for plotting.
170- x [which(x < min(breaks ))] <- min(breaks )
171- x [which(x > max(breaks ))] <- max(breaks )
172- if (! is.null(which(x < min(breaks ))) | ! is.null(which(x > max(breaks )))) print(" Warning: values out of the range have been set to maximum or minimum of the colorbar" )
173-
174- # plot map
175- par(mar = c(0.3 ,0.3 ,2 ,0 )) # reduce space around plot
176- image(lon , lat , x , breaks = breaks , col = cols , main = title.main , cex.main = cex.main , xaxt = " n" , yaxt = " n" , xlab = NA , ylab = NA )
177- points(lon.points , lat.points , lwd = 2 , cex = 1.5 )
178- map(add = T )
179- }
180-
181-
182-
183-
0 commit comments