Subscribe to R-sig-geo feed
This is an archive for R-sig-geo, not a forum. It is not possible to post through Nabble - you may not start a new thread nor follow up an existing thread. If you wish to post, but are not subscribed to the list through the list homepage, subscribe first (through the list homepage, not via Nabble) and post from your subscribed email address. Until 2015-06-20, subscribers could post through Nabble, but policy has been changed as too many non-subscribers misunderstood the interface.
Updated: 38 min 49 sec ago

Re: Strange spatial reference system netCDF

Fri, 05/03/2019 - 09:58
Dear Maurizio,

an attempt to do something along this line is:

f = "tas_rcp85_land-rcm_eur_12km_01_mon_198012-208011.nc"
library(stars)
r = read_ncdf(f, ncsub = cbind(start = c(1, 1, 1, 1), count = c(418,
406, 3, 1)), eps=1e-3)
rx = read_stars(f, proxy = TRUE) # only for the crs!
st_crs(r) = st_crs(rx)
r0 = stars:::st_transform_proj.stars(r, 4326)
png("x.png")
plot(r0[,,,1], border = NA, axes = TRUE, reset = FALSE)
library(rnaturalearth)
plot(ne_coastline(returnclass = "sf"), add = TRUE, col = 'orange')

Note that the output object time stamps respect the 360-day calendar
(using pkg PCICt).

You'll find some discussion, and the output image, here:
https://github.com/r-spatial/stars/issues/175

Feel free to post follow-up questions here, or to github.

On 5/2/19 6:49 PM, Maurizio Marchi wrote:
> Dear list,
> I'm working with large netCDF files from the UK Climate Projections portal (
> https://www.metoffice.gov.uk/research/collaboration/ukcp). More in detail
> I'm reading with the ncdf4 library this
> <http://data.ceda.ac.uk/badc/ukcp18/data/land-rcm/eur/12km/rcp85/01/tas/mon/latest/>
> file. Once loaded O can easily handle it but it is a strange reference
> system as follow:
> rotated_latitude_longitude[]
>             grid_mapping_name: rotated_latitude_longitude
>             longitude_of_prime_meridian: 0
>             earth_radius: *6371229*
>             grid_north_pole_latitude: 39.25
>             grid_north_pole_longitude: 198
>             north_pole_grid_longitude: 0
> If I load the .nc file in QGIS I see that the SR is "+proj=longlat
> +a=6371229 +b=6371229 +no_defs" where the values associated to *a* and
> *b* variables
> are the earth radius. Even if QGIS can read it, the raw file isn't
> projected properly (it seems tha QGIS is not able to handle such
> projection).
> Finally, using the ncdf4+raster libraries, I can easily generate e raster
> image but then I'm not able to understand I could I re project this raster
> in WGS84 reference system.
> Any helps?
> Cheers
>
> --
> Maurizio Marchi,
> PhD Forest Science - Ecological Mathematics
> Skype ID: maurizioxyz
> linux user 552742
> #EUFGIS national Focal point for Italy
> #Annals of Silvicultural Research Associated Editor
> https://scholar.google.it/citations?hl=en&user=_2X6fu8AAAAJ
> <https://scholar.google.it/citations?hl=en&user=_2X6fu8AAAAJ*>
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> --
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48151 Muenster, Germany
Phone: +49 251 8333081

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

pEpkey.asc (2K) Download Attachment

Strange spatial reference system netCDF

Thu, 05/02/2019 - 11:49
Dear list,
I'm working with large netCDF files from the UK Climate Projections portal (
https://www.metoffice.gov.uk/research/collaboration/ukcp). More in detail
I'm reading with the ncdf4 library this
<http://data.ceda.ac.uk/badc/ukcp18/data/land-rcm/eur/12km/rcp85/01/tas/mon/latest/>
file. Once loaded O can easily handle it but it is a strange reference
system as follow:
rotated_latitude_longitude[]
            grid_mapping_name: rotated_latitude_longitude
            longitude_of_prime_meridian: 0
            earth_radius: *6371229*
            grid_north_pole_latitude: 39.25
            grid_north_pole_longitude: 198
            north_pole_grid_longitude: 0
If I load the .nc file in QGIS I see that the SR is "+proj=longlat
+a=6371229 +b=6371229 +no_defs" where the values associated to *a* and
*b* variables
are the earth radius. Even if QGIS can read it, the raw file isn't
projected properly (it seems tha QGIS is not able to handle such
projection).
Finally, using the ncdf4+raster libraries, I can easily generate e raster
image but then I'm not able to understand I could I re project this raster
in WGS84 reference system.
Any helps?
Cheers

--
Maurizio Marchi,
PhD Forest Science - Ecological Mathematics
Skype ID: maurizioxyz
linux user 552742
#EUFGIS national Focal point for Italy
#Annals of Silvicultural Research Associated Editor
https://scholar.google.it/citations?hl=en&user=_2X6fu8AAAAJ
<https://scholar.google.it/citations?hl=en&user=_2X6fu8AAAAJ*>

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Spatial join/intersection in R

Wed, 05/01/2019 - 00:15
Roozbeh--
What do you want to have happen with those points? Given the units in your figure, you could unambiguously assign them to the upper-right by adding a small value (0.000001) to both the X and Y coordinates of your points.  Whether that is a sensible thing to do depends on what your data are.
How or why do the points fall exactly on your polygon boundaries?  What process puts them exactly on the polygon (grid cell) boundaries?  It appears your polygon boundaries are a grid at multiples of 0.05, although not all potential cells in a rectangle are shown.  Are there many other points not on polygon boundaries not shown in your figure, or are points only along grid lines?  If the latter, does it make sense to assign them to _polygons_ rather than line segments?
If you're doing a sample draw or measuring locations with only a few decimal points of accuracy, and generating your polygon boundaries at exact multiples of 0.05, then it might make sense to shift all of your points + 1/10th of your point location resolution so that their coordinates never fall on polygon boundaries.  There _might_ be situations where instead of always adding (shifting up and right), you should randomly add or subtract in each direction for each point, but I'm stuck viewing this as points in sTomample units so I can't think of such a case.
Tom.  
On Tue, Apr 30, 2019 at 7:18 PM Roozbeh Valavi <[hidden email]> wrote:
Dear members,

I want to do a spatial join/intersection in R. The problem is that some of my points are lying exactly at the border of the adjacent polygons (see the figure attached). So these points are either falling in both or none of the polygons! Is there any way to avoid this?
Thanks in advance.Roozbeh





--
Roozbeh ValaviPhD Candidate
The Quantitative & Applied Ecology Group
School of BioSciences | Faculty of ScienceThe University of Melbourne, VIC 3010, AustraliaMobile: +61 423 283 238
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Spatial join/intersection in R

Tue, 04/30/2019 - 21:18
Dear members,

I want to do a spatial join/intersection in R. The problem is that some of my points are lying exactly at the border of the adjacent polygons (see the figure attached). So these points are either falling in both or none of the polygons! Is there any way to avoid this?
Thanks in advance.Roozbeh





--
Roozbeh ValaviPhD Candidate
The Quantitative & Applied Ecology Group
School of BioSciences | Faculty of ScienceThe University of Melbourne, VIC 3010, AustraliaMobile: +61 423 283 238

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: raster - units assignment error in reading NetCDF4

Tue, 04/30/2019 - 07:28
It looks like this is a curvilinear grid; you could read & plot it with

library(stars)
r = read_stars("L8_OLI_2017_03_18_00_09_19_093086_L2R.nc", curvilinear =
c("lon", "lat"))
plot(r[1], border = NA)

Printing r shows the units of each of the variables. The plotting takes
a while because the data grid is not aligned with the pixel grid of the
plotting device.


On 4/30/19 12:43 PM, Alexandre Castagna wrote:
> Hi group,
>
> I'm trying to read a NetCDF4 file, but I get the following error message:
>
> fl <- 'L8_OLI_2017_03_18_00_09_19_093086_L2R.nc'
> r <- raster(fl, varname = 'rhos_443')
>
> Error in (function (cl, name, valueClass)  :
>   assignment of an object of class “numeric” is not valid for @‘unit’ in an
> object of class “.SingleLayerData”; is(value, "character") is not TRUE
>
> This data is OLI Landsat 8 atmospheric 'corrected' imagery with the ACOLITE
> software (link <https://github.com/acolite/acolite>).
> In a previous version of the software, exploring the file after nc_open
> function revealed that units was numeric ('num' qualifier was shown in R
> object print); but since, the developer has committed a change for all
> units to be written as characters. The unit in question is '1' (unitless,
> for bihemispherical reflectance). A new exploration after the update to
> check the units type does not show the qualifier 'num' anymore, but the
> error keep the same. Maybe R is translating '1' to 1 automatically?
>
> I can go around and create a raster directly from data read with ncdf4
> package, like:
>
> ncfl <- nc_open(fl)
> r     <- raster(t(ncvar_get(ncfl, 'rhos_443')))
>
> But for a number of reasons that is less ideal. A temporary link to
> download the example data file is: https://we.tl/t-nENAV7tmBg
>
> Kind regards,
>
> Alexandre Castagna Mourão e Lima
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
> --
Edzer Pebesma
Institute for Geoinformatics
Heisenbergstrasse 2, 48151 Muenster, Germany
Phone: +49 251 8333081

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

pEpkey.asc (2K) Download Attachment

raster - units assignment error in reading NetCDF4

Tue, 04/30/2019 - 05:43
Hi group,

I'm trying to read a NetCDF4 file, but I get the following error message:

fl <- 'L8_OLI_2017_03_18_00_09_19_093086_L2R.nc'
r <- raster(fl, varname = 'rhos_443')

Error in (function (cl, name, valueClass)  :
  assignment of an object of class “numeric” is not valid for @‘unit’ in an
object of class “.SingleLayerData”; is(value, "character") is not TRUE

This data is OLI Landsat 8 atmospheric 'corrected' imagery with the ACOLITE
software (link <https://github.com/acolite/acolite>).
In a previous version of the software, exploring the file after nc_open
function revealed that units was numeric ('num' qualifier was shown in R
object print); but since, the developer has committed a change for all
units to be written as characters. The unit in question is '1' (unitless,
for bihemispherical reflectance). A new exploration after the update to
check the units type does not show the qualifier 'num' anymore, but the
error keep the same. Maybe R is translating '1' to 1 automatically?

I can go around and create a raster directly from data read with ncdf4
package, like:

ncfl <- nc_open(fl)
r     <- raster(t(ncvar_get(ncfl, 'rhos_443')))

But for a number of reasons that is less ideal. A temporary link to
download the example data file is: https://we.tl/t-nENAV7tmBg

Kind regards,

Alexandre Castagna Mourão e Lima

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Possible proj.4-related error coming when specifying CRS for raster

Fri, 04/26/2019 - 14:55
> -----Original Message-----
> From: Roger Bivand <[hidden email]>
> Sent: Friday, April 26, 2019 15:00
> To: Alex Zvoleff <[hidden email]>
> Cc: 'R-sig-Geo' <[hidden email]>
> Subject: Re: [R-sig-Geo] Possible proj.4-related error coming when specifying
> CRS for raster
>
> CAUTION: External Email
>
>
>
> On Fri, 26 Apr 2019, Alex Zvoleff via R-sig-Geo wrote:
>
> >
> > Hi all,
> >
> >
> >
> > Recently the glcm package I maintain has started throwing errors on
> > all of the Linux-based CRAN test servers. The errors come when
> > checking the examples included in the package. I have not been able to
> > reproduce these errors locally on Linux (Ubuntu 18.04 running
> > r-release and r-devel) or on Windows 10 (r-release and r-devel). The
> > errors also don’t come up on any of the r-hub servers.
> >
> >
> >
> > Here is an example error from the CRAN test server:
> >
> >
> >
> > > require(raster)
> >
> > Loading required package: raster
> >
> > Loading required package: sp
> >
> > > set.seed(0)
> >
> > > test_matrix <- matrix(runif(100)*32, nrow=10)
> >
> > > test_raster <- raster(test_matrix, crs='+init=EPSG:4326')
>
> "EPSG" must be "epsg"; after making two such changes, I see:
Yep, that looks like it. I've fixed the example CRS strings and the CRS of the stored data and will upload the new version. Thank you for the quick response and help in fixing this!

>
> * checking examples ... OK
> * checking for unstated dependencies in ‘tests’ ... OK
> * checking tests ...
>    Running ‘test-all.R’
>   ERROR
> Running the tests in ‘tests/test-all.R’ failed.
> Last 13 lines of output:
>           crs = crs, ...)
>    12: raster(xmn = x@xmin, xmx = x@xmax, ymn = x@ymin, ymx = x@ymax,
> ncols = ncols, nrows = nrows,
>           crs = crs, ...)
>    13: .local(...)
>    14: CRS(as.character(projection(crs)))
>    15: stop(res[[2]])
>
>    ══ testthat results
> ══════════════════════════════════════════════
> ═════════════
>    OK: 1 SKIPPED: 0 WARNINGS: 0 FAILED: 3
>    1. Error: glcm on 3x3 window with 1x1 shift works (@test-glcm.R#21)
>    2. Error: glcm on 5x7 window with 2x3 shift works (@test-glcm.R#48)
>    3. Error: (unknown) (@test-glcm.R#113)
>
>    Error: testthat unit tests failed
>    Execution halted
>
> but myself never use testthat because it always hides the actual errors.
> Your use of roxygen may well also be concealing verbatim "EPSG", which may
> be in the stored data objects in glcm/data:
>
> > crs(get(load(list.files()[5]))
> CRS arguments: +init=EPSG:4326
>
> So a leftover from the previously tolerated use of "EPSG" for "epsg", I think.
>
> crs(test_raster) <- "+init=epsg:4326"
> save(test_raster, file="test_raster.RData")
>
> gives:
>
> * checking examples ... OK
> * checking for unstated dependencies in ‘tests’ ... OK
> * checking tests ...
>    Running ‘test-all.R’
>   OK
>
> Roger
>
> >
> > Error in CRS(as.character(projection(crs))) :
> >
> >   no arguments in initialization list
> >
> > Calls: raster ... raster -> .local -> raster -> raster -> .local ->
> > CRS
> >
> > Execution halted
> >
> >
> >
> > (full output
> > here:https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-debi
> > an-clang/g
> > lcm-00check.html)
> >
> >
> >
> > The CRAN maintainers suggested I run R CMD check with
> > _R_CHECK_SUGGESTS_ONLY_=FALSE, but that hasn’t worked – even when
> the
> > env variable is set I still don’t see the error on my end. Given that,
> > they suggested I reach out here. From the error message I assume the
> > error is something related to proj.4 not being able to interpret the
> > EPSG code (though this would seem odd for 4326). I have tested this
> > locally on proj.4 versions 4.9.3 and 5.2.0, but I can’t reproduce the
> > error I am getting from the CRAN server on either version. Has anyone
> > else encountered something like this? If not, any idea whether I am on the
> right track?
> >
> >
> >
> > Thanks,
> >
> > Alex
> >
> >
> > --
> >
> > Alex Zvoleff, PhD
> > Senior Director, Resilience Science
> > Betty and Gordon Moore Center for Science Conservation International
> > 2011 Crystal Dr. Suite 500, Arlington, Virginia 22202, USA
> > Tel: +1-703-341-2749, Skype: azvoleff
> >
> >
>
> --
> Roger Bivand
> Department of Economics, Norwegian School of Economics, Helleveien 30, N-
> 5045 Bergen, Norway.
> voice: +47 55 95 93 55; e-mail: [hidden email] _______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Possible proj.4-related error coming when specifying CRS for raster

Fri, 04/26/2019 - 08:00
On Fri, 26 Apr 2019, Alex Zvoleff via R-sig-Geo wrote:

>
> Hi all,
>
>  
>
> Recently the glcm package I maintain has started throwing errors on all of
> the Linux-based CRAN test servers. The errors come when checking the
> examples included in the package. I have not been able to reproduce these
> errors locally on Linux (Ubuntu 18.04 running r-release and r-devel) or on
> Windows 10 (r-release and r-devel). The errors also don’t come up on any of
> the r-hub servers.
>
>  
>
> Here is an example error from the CRAN test server:
>
>  
>
> > require(raster)
>
> Loading required package: raster
>
> Loading required package: sp
>
> > set.seed(0)
>
> > test_matrix <- matrix(runif(100)*32, nrow=10)
>
> > test_raster <- raster(test_matrix, crs='+init=EPSG:4326') "EPSG" must be "epsg"; after making two such changes, I see:

* checking examples ... OK
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
   Running ‘test-all.R’
  ERROR
Running the tests in ‘tests/test-all.R’ failed.
Last 13 lines of output:
          crs = crs, ...)
   12: raster(xmn = x@xmin, xmx = x@xmax, ymn = x@ymin, ymx = x@ymax, ncols
= ncols, nrows = nrows,
          crs = crs, ...)
   13: .local(...)
   14: CRS(as.character(projection(crs)))
   15: stop(res[[2]])

   ══ testthat results
═══════════════════════════════════════════════════════════
   OK: 1 SKIPPED: 0 WARNINGS: 0 FAILED: 3
   1. Error: glcm on 3x3 window with 1x1 shift works (@test-glcm.R#21)
   2. Error: glcm on 5x7 window with 2x3 shift works (@test-glcm.R#48)
   3. Error: (unknown) (@test-glcm.R#113)

   Error: testthat unit tests failed
   Execution halted

but myself never use testthat because it always hides the actual errors.
Your use of roxygen may well also be concealing verbatim "EPSG", which may
be in the stored data objects in glcm/data:

> crs(get(load(list.files()[5]))
CRS arguments: +init=EPSG:4326

So a leftover from the previously tolerated use of "EPSG" for "epsg", I
think.

crs(test_raster) <- "+init=epsg:4326"
save(test_raster, file="test_raster.RData")

gives:

* checking examples ... OK
* checking for unstated dependencies in ‘tests’ ... OK
* checking tests ...
   Running ‘test-all.R’
  OK

Roger

>
> Error in CRS(as.character(projection(crs))) :
>
>   no arguments in initialization list
>
> Calls: raster ... raster -> .local -> raster -> raster -> .local -> CRS
>
> Execution halted
>
>  
>
> (full output here:https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-debian-clang/g
> lcm-00check.html)
>
>  
>
> The CRAN maintainers suggested I run R CMD check with
> _R_CHECK_SUGGESTS_ONLY_=FALSE, but that hasn’t worked – even when the env
> variable is set I still don’t see the error on my end. Given that, they
> suggested I reach out here. From the error message I assume the error is
> something related to proj.4 not being able to interpret the EPSG code
> (though this would seem odd for 4326). I have tested this locally on proj.4
> versions 4.9.3 and 5.2.0, but I can’t reproduce the error I am getting from
> the CRAN server on either version. Has anyone else encountered something
> like this? If not, any idea whether I am on the right track?
>
>  
>
> Thanks,
>
> Alex
>
>  
>
> --
>
> Alex Zvoleff, PhD
> Senior Director, Resilience Science
> Betty and Gordon Moore Center for Science
> Conservation International
> 2011 Crystal Dr. Suite 500, Arlington, Virginia 22202, USA
> Tel: +1-703-341-2749, Skype: azvoleff, http://www.conservation.org
>
>  
>
>
> --
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Possible proj.4-related error coming when specifying CRS for raster

Fri, 04/26/2019 - 07:37
Hi all,

Recently the glcm package I maintain has started throwing errors on all of the Linux-based CRAN test servers. The errors come when checking the examples included in the package. I have not been able to reproduce these errors locally on Linux (Ubuntu 18.04 running r-release and r-devel) or on Windows 10 (r-release and r-devel). The errors also don't come up on any of the r-hub servers.

Here is an example error from the CRAN test server:

> require(raster)
Loading required package: raster
Loading required package: sp
> set.seed(0)
> test_matrix <- matrix(runif(100)*32, nrow=10)
> test_raster <- raster(test_matrix, crs='+init=EPSG:4326')
Error in CRS(as.character(projection(crs))) :
  no arguments in initialization list
Calls: raster ... raster -> .local -> raster -> raster -> .local -> CRS
Execution halted

(full output here: https://www.r-project.org/nosvn/R.check/r-devel-linux-x86_64-debian-clang/glcm-00check.html)

The CRAN maintainers suggested I run R CMD check with _R_CHECK_SUGGESTS_ONLY_=FALSE, but that hasn't worked - even when the env variable is set I still don't see the error on my end. Given that, they suggested I reach out here. From the error message I assume the error is something related to proj.4 not being able to interpret the EPSG code (though this would seem odd for 4326). I have tested this locally on proj.4 versions 4.9.3 and 5.2.0, but I can't reproduce the error I am getting from the CRAN server on either version. Has anyone else encountered something like this? If not, any idea whether I am on the right track?

Thanks,
Alex

--
Alex Zvoleff, PhD
Senior Director, Resilience Science
Betty and Gordon Moore Center for Science
Conservation International
2011 Crystal Dr. Suite 500, Arlington, Virginia 22202, USA
Tel: +1-703-341-2749, Skype: azvoleff, http://www.conservation.org<http://www.conservation.org/>


_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

winmail.dat (19K) Download Attachment

(no subject)

Thu, 04/25/2019 - 06:01
I have drawn a map for significant NDVI trends but I don't know how to
explain it. What is the meaning of "significant NDVI trends?"

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Selecting a range of longitudes and latitudes for plotting

Wed, 04/24/2019 - 11:15
Hi Kay (and everyone),

Thank you very much for your reply! I tried your suggestion, but, unfortunately, the error persists when trying to plot the 140 data points (coming from the individual averages of each layer across each of the, in this case, 196 grid cells selected - i.e. the average of layer 1 across all grid cells, then the average of layer 2 across all grid cells, then the average of layer 3 across all grid cells.....all the way to the average of layer 140 across all grid cells - so, effectively, 140 values):
>plot(RCP1pctCO2cumulative,lonlat, type="l",col="green", lwd="3", xlab="Cumulative emissions (TtC)", ylab="One-day maximum precipitation (mm/day)", main="CanESM2")

"RCP1pctCO2cumulative" was created like this:
>RCP1pctCO2cumulative <- rowMeans(cbind(get, IPSL, IPSLMR, IPSL5, MIROC, HadGEM, MPI, MPI5, GFDL, GFDL5)) #To get means of each element of x-variables (Ttc carbon)

For example, "get" and the other x variables listed there, look like this:
>get
  [1] 0.00000000 0.00644777 0.01250601 0.01746194 0.02656210 0.03360072 0.04399755 0.05404601 0.06154399 0.07105423
 [11] 0.08315538 0.08925389 0.10060635 0.10833009 0.12196157 0.13730928 0.14890850 0.16087072 0.17361501 0.18310140
 [21] 0.19810085 0.21316248 0.22423607 0.23529990 0.24695577 0.26119599 0.27643532 0.28517213 0.29978970 0.31870887
 [31] 0.33418021 0.34585044 0.36071229 0.37379062 0.39324498 0.41099992 0.42437476 0.43643925 0.44687960 0.45864752
 [41] 0.48055932 0.49634662 0.50779009 0.52861303 0.54971600 0.56138206 0.57472491 0.59202033 0.60975420 0.63057494
 [51] 0.64653736 0.66088217 0.68168259 0.69649595 0.71363837 0.72988760 0.75010443 0.76776582 0.78613955 0.81099886
 [61] 0.82979667 0.84431553 0.86824787 0.88447672 0.89909577 0.92162514 0.94854647 0.96631038 0.98120815 1.00357985
 [71] 1.02769291 1.04733002 1.06585240 1.09083056 1.11592567 1.13627303 1.15866983 1.17941856 1.19748724 1.22012913
 [81] 1.24142718 1.26937973 1.29283488 1.31011736 1.33134723 1.36014366 1.38395822 1.40615380 1.42895305 1.45046842
 [91] 1.47504234 1.49920797 1.52142668 1.54559219 1.57354927 1.60000896 1.62449229 1.64506662 1.67100036 1.70185161
[101] 1.72964287 1.75235510 1.77455521 1.80183053 1.83121216 1.85619974 1.88188243 1.91002214 1.93333006 1.96133912
[111] 1.98944890 2.01225924 2.03804183 2.06614304 2.09558916 2.12400699 2.14846969 2.18011498 2.20532560 2.23031592
[121] 2.26106715 2.28796983 2.31954741 2.35274339 2.37794161 2.40643740 2.43963051 2.46948838 2.49733877 2.53035021
[131] 2.56229091 2.59265327 2.61934137 2.64592481 2.67754769 2.70779777 2.73824191 2.76880598 2.80077982 2.83057237 
Thanks, and I look forward to your response!

-----Original Message-----
From: Kilpatrick, Katherine A <[hidden email]>
To: [hidden email] <[hidden email]>
Cc: [hidden email] <[hidden email]>
Sent: Wed, Apr 24, 2019 10:59 am
Subject: Re: [R-sig-Geo] Selecting a range of longitudes and latitudes for plotting

Hi;
The reason you are getting that error message is you are trying to plot a 1 dimension array by a 2 dimensional array.
I think simply adding the argument  fun = mean to your extraction of the RCP1pctCO2Mean brick will solve the confusion. As you have it written you are extracting 196 grid cells  for all 140 layers ending up with a 2d array   latlon <- extract(RCP1pctCO2Mean, expansion, fun=mean) Should  give you 140 values in a 1d array that represent the average of the cells in the grid subset for each of the 140 layers in the brick.
Assuming of course that this is what you were after. I had to read between the lines a bit not knowing really how RCP1pctCO2cumulative was created -- other than it was precomputed and had a length of 140.
btw: Cellstats would give you the average of the nlayers at each of the 196 grid cells  eg. a 1 d array of 196.
Kay


On Apr 23, 2019, at 10:08 PM, rain1290--- via R-sig-Geo <[hidden email]> wrote:
Hi there,
I am trying to select a range of latitude and longitudes (and all grid cells within that range) to plot y-axis values (precipitation) as a function of x-axis values (emissions) based on aggregating (averaging) each of those grid cells. Thus, let's say that I wanted to aggregate/average each of the values of these grid cells and plot this as a function x-axis values. The values already computed for each grid cell for the y-axis correspond to average precipitation and consist of 140 values per grid cell. So, the idea would be the average the first value of each grid cell, then the second value of each grid cell, then the third value of each grid cell.....all the way to value #140 of each grid cell. This would yield 140 values that would be plotted as a single line plot.  The variable containing these y-axis values is called "RCP1pctCO2Mean", which is 3-dimensional and has the following attributes:    class: RasterBrick
dimensions  : 64, 128, 8192, 140  (nrow, ncol, ncell, nlayers)
resolution  : 2.8125, 2.789327  (x, y)
extent      : -181.4062, 178.5938, -89.25846, 89.25846  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names       :   layer.1,   layer.2,   layer.3,   layer.4,   layer.5,    
layer.6,   layer.7,   layer.8,   layer.9,  layer.10,  layer.11,  layer.12, 
layer.13,  layer.14,  layer.15, ...
min values  : 0.5261063, 0.5625295, 0.5301681, 0.6019284, 0.5177065, 
0.6775601, 0.5336965, 0.5213086, 0.5971723, 0.5305891, 0.5514522,  
0.5481200, 0.4681806, 0.5437223, 0.5988844, ...
max values  : 113.13776, 114.50780,  94.93643, 100.35409, 102.65459,
101.80622, 104.95480,  99.17839, 104.68667, 119.48342, 100.60391,
108.91896, 104.38969,  99.35735,  99.30752, ...     >dput(head(RCP1pctCO2ModelMean,5))
    structure(c(8.06056747436523, 7.75062637329102, 7.73271865844727,
    7.65678634643555, 7.75580596923828, 8.74016799926758, 8.28938064575195,
    8.10810775756836, 8.10339508056641, 7.86748199462891, 10.6165672302246,
    11.057600402832, 11.9450210571289, 12.3012786865234, 12.1853874206543,
    8.51755447387695, 9.16703491210938, 7.79627380371094, 7.53922271728516,
    8.14367599487305, 7.83845596313477, 8.22455596923828, 8.21650848388672,
    8.186181640625, 8.34122924804688, 9.1652702331543, 9.03225784301758,
    9.04341430664062, 8.98676376342774, 9.0090087890625, 10.5393569946289,
    11.1039672851562, 11.2379959106445, 11.333048248291, 12.0459312438965,
    10.0039085388184, 9.90224914550781, 9.24856033325195, 9.26007308959961,
    9.17901306152344, 9.55168991088867, 10.1229606628418, 10.4827072143555,
    11.0505676269531, 12.1166931152344, 9.01049194335937, 9.39016952514648,
    10.1307640075684, 9.67219467163086, 9.63750610351562, 8.14553070068359,
    8.06989059448242, 7.88368453979492, 7.78139190673828, 7.76021575927734,
    8.09026031494141, 8.47544021606445, 8.53607864379883, 9.07613296508789,
    8.45474319458008, 9.91985092163086, 10.0807098388672, 9.90288009643555,
    10.3433769226074, 10.349861907959, 11.2688484191895, 11.9406700134277,
    12.0929878234863, 11.8347038269043, 10.4144630432129, 12.5179420471191,
    13.8380874633789, 14.6360946655273, 14.0480010986328, 13.3910736083984,
    9.96924514770508, 10.3363311767578, 10.7060684204102, 10.889599609375,
    10.6653129577637, 10.5626991271973, 10.047868347168, 10.2751319885254,
    10.8663063049316, 11.7612907409668, 8.94287414550781, 9.23690567016602,
    8.96449661254883, 8.62908248901367, 8.30552215576172, 8.18369979858398,
    7.69772872924805, 7.5989143371582, 7.7111930847168, 7.66501693725586,
    10.2653533935547, 9.95307464599609, 9.71684875488281, 9.06423645019531,
    9.75586776733399, 9.83898010253906, 9.89386901855469, 9.82217864990234,
    9.5716667175293, 9.0698844909668, 9.32229309082031, 9.11556243896484,
    8.89283828735352, 9.28563232421875, 9.30773696899414, 7.3968879699707,
    7.93817901611328, 7.98456954956055, 7.95158386230469, 8.098583984375,
    8.80923156738281, 8.49755935668945, 8.15531387329102, 8.46451263427734,
    8.68563690185547, 8.89066619873047, 9.1489013671875, 9.33551254272461,
    10.1721000671387, 11.0765029907227, 8.04215698242188, 8.19046478271484,
    8.40826110839844, 8.67290573120117, 9.18575973510742, 8.3109245300293,
    9.11093368530273, 9.81162109375, 9.86040802001953, 9.50505447387695,
    10.5363166809082, 9.481689453125, 9.08926620483398, 9.52505798339844,
    8.68244476318359, 8.98393630981445, 10.1831520080566, 10.5507629394531,
    10.1666023254395, 9.69676284790039, 8.34152221679688, 8.42654571533203,
    8.35252838134766, 8.00343780517578, 7.82494201660156, 9.53874359130859,
    9.61768341064453, 9.41213912963867, 9.64521713256836, 10.2018295288086,
    10.4372673034668, 10.2102493286133, 11.5178192138672, 10.6066253662109,
    8.7693229675293, 10.0142112731934, 10.0218872070313, 9.85999298095703,
    9.61988754272461, 9.6459342956543, 8.68394012451172, 8.94484100341797,
    8.99103088378906, 9.28208084106445, 9.25485153198242, 9.43952713012695,
    9.46648941040039, 9.29736251831055, 9.17809677124023, 9.15292205810547,
    9.86052169799805, 9.73173980712891, 9.56215209960937, 9.07076568603516,
    8.6406623840332, 9.93644332885742, 10.4607345581055, 10.7315849304199,
    10.8101539611816, 10.7245536804199, 8.11333770751953, 8.19898986816406,
    9.07229690551758, 8.52103500366211, 8.86794967651367, 13.8089904785156,
    14.1628616333008, 14.1612731933594, 13.8391723632812, 13.4812423706055,
    10.3034606933594, 10.3893714904785, 10.6155006408691, 10.7073356628418,
    10.2250640869141, 10.7160522460937, 10.9937141418457, 11.4714202880859,
    11.451326751709, 11.2873542785645, 10.1245864868164, 10.7054138183594,
    11.2963111877441, 11.2652069091797, 11.1456642150879, 10.2463417053223,
    10.7579162597656, 10.9033828735352, 10.8239326477051, 10.9808113098145,
    9.11014785766602, 9.57601928710938, 9.13134765625, 8.95542297363281,
    9.004345703125, 10.011986541748, 10.4038223266602, 10.7760765075684,
    10.8257308959961, 11.1445190429687, 10.5380798339844, 10.2488784790039,
    10.957502746582, 10.7088333129883, 10.6826118469238, 8.83894119262695,
    9.23114776611328, 8.83077545166016, 8.79364471435547, 9.5740608215332,
    9.49266204833984, 9.36201629638672, 8.86088562011719, 8.70853042602539,
    8.84630584716797, 8.54691619873047, 9.06980133056641, 9.68758087158203,
    10.2382141113281, 11.163306427002, 8.64593887329102, 8.68509368896484,
    9.1695442199707, 9.96113128662109, 10.5646827697754, 10.6185249328613,
    11.3931076049805, 11.984349822998, 12.3294868469238, 12.6237396240234,
    9.07107849121094, 8.50119094848633, 8.165673828125, 8.46488571166992,
    8.7583610534668, 9.64865646362305, 11.1105819702148, 11.4002655029297,
    10.5027854919434, 10.1196365356445, 9.72924041748047, 10.009349822998,
    10.326407623291, 9.36514053344727, 7.79587249755859, 9.68682708740234,
    9.97370910644531, 10.053092956543, 10.0790946960449, 9.88732604980469,
    8.5629150390625, 8.67814178466797, 8.62764282226562, 8.40693130493164,
    8.43646850585938, 8.18491287231445, 8.28544006347656, 8.32042083740234,
    8.37117156982422, 8.74075393676758, 10.0410667419434, 9.86564865112305,
    9.83465423583984, 10.2372169494629, 10.6772819519043, 10.7158340454102,
    11.1418548583984, 11.3801231384277, 12.3574913024902, 12.7044395446777,
    10.933625793457, 10.1660957336426, 8.9215690612793, 9.42180328369141,
    10.0563125610352, 10.6793243408203, 10.605298614502, 10.532593536377,
    10.4527519226074, 10.4930633544922, 9.60543518066406, 9.36136474609375,
    9.02150115966797, 8.90760498046875, 9.39027709960937, 11.475407409668,
    11.8939018249512, 12.2665367126465, 12.3773796081543, 12.2639549255371,
    12.1986907958984, 12.9296035766602, 14.6138290405273, 12.5118690490723,
    11.1584533691406, 11.6089347839355, 12.184122467041, 12.7126617431641,
    12.8846618652344, 12.7170280456543, 10.4427520751953, 11.0104148864746,
    11.0574317932129, 10.7889305114746, 11.428002166748, 12.8730773925781,
    13.0610855102539, 13.9772033691406, 14.7699234008789, 15.2759140014648,
    11.0441619873047, 12.8132598876953, 13.1194686889648, 13.3944534301758,
    13.439665222168, 11.8274314880371, 12.5198951721191, 13.1492401123047,
    13.310026550293, 13.7720932006836, 10.7566696166992, 11.1153205871582,
    10.8651023864746, 10.8898574829102, 11.1934638977051, 10.3416526794434,
    10.3679290771484, 10.5599853515625, 10.4897705078125, 10.3551536560059,
    10.7984680175781, 9.9300895690918, 9.24563140869141, 8.82577590942383,
    8.11003036499023, 9.96226196289063, 10.2302505493164, 10.1707107543945,
    9.78019790649414, 9.43962249755859, 11.1743797302246, 11.4034492492676,
    10.9475212097168, 11.3065505981445, 11.3690071105957, 9.07691192626953,
    8.84776763916016, 8.99648666381836, 9.46799697875977, 10.1394309997559,
    9.5390739440918, 9.72808990478516, 10.1971199035645, 10.3575813293457,
    10.6958648681641, 12.1900230407715, 11.986629486084, 12.139289855957,
    12.308757019043, 12.2176116943359, 10.5569931030273, 10.2808883666992,
    9.90982055664062, 9.57319793701172, 9.34677658081055, 9.55350112915039,
    9.78641738891602, 10.0147956848145, 10.3079559326172, 10.7283164978027,
    8.64087753295899, 8.30433197021484, 8.60956497192383, 8.60016937255859,
    8.54900741577148, 9.71597595214844, 8.8296272277832, 8.63880462646484,
    8.47726745605469, 8.84029846191406, 10.1157096862793, 9.88607330322266,
    9.32783508300781, 9.36255416870117, 10.1161201477051, 11.8296203613281,
    12.8728881835937, 13.2580642700195, 13.5822448730469, 14.2079498291016,
    8.7088752746582, 8.82841796875, 9.62056427001953, 9.44509429931641,
    8.63022689819336, 10.438533782959, 10.7936264038086, 11.1668098449707,
    11.4698097229004, 11.6895088195801, 10.657413482666, 10.6490295410156,
    10.6090156555176, 10.7308578491211, 10.2125785827637, 8.9413688659668,
    8.8182373046875, 8.83381042480469, 8.8937255859375, 8.81535415649414,
    9.55851669311523, 9.21836166381836, 9.18197784423828, 9.25029678344726,
    9.27070083618164, 8.93240661621094, 8.90249099731445, 9.04313659667969,
    9.20108184814453, 9.35103607177734, 10.5618942260742, 11.06572265625,
    11.445832824707, 11.9180442810059, 11.9453758239746, 12.2584243774414,
    11.9192649841309, 11.7775825500488, 11.8008255004883, 12.2185432434082,
    9.08272094726562, 9.66560821533203, 9.48288192749023, 9.70498886108398,
    9.56975555419922, 10.349006652832, 10.0300796508789, 9.5968864440918,
    9.54965896606445, 9.00812759399414, 10.6454582214355, 10.7713653564453,
    11.4645782470703, 11.8325187683105, 10.4740211486816, 9.41022796630859,
    9.07474822998047, 8.61860656738281, 8.40045318603516, 8.653662109375,
    9.65197830200195, 9.63723449707031, 9.51137924194336, 9.57775497436523,
    9.69926528930664, 8.98936157226563, 9.40332794189453, 9.6757568359375,
    9.79740600585938, 9.78034057617188, 10.2542152404785, 10.1619010925293,
    10.3302688598633, 10.5525291442871, 10.7628135681152, 10.2399101257324,
    10.7667839050293, 10.9936302185059, 10.8458152770996, 10.6235733032227,
    9.24678955078125, 9.91125411987305, 9.86469879150391, 10.2658912658691,
    10.1045028686523, 8.5959098815918, 8.49214401245117, 8.39304656982422,
    8.6228157043457, 8.61747360229492, 8.91071395874024, 8.69116439819336,
    8.56472625732422, 8.52434997558594, 8.64141616821289, 11.7017639160156,
    12.3285125732422, 12.0996276855469, 11.056103515625, 10.7624618530273,
    11.0327911376953, 12.0061622619629, 11.4006072998047, 10.8051193237305,
    9.97594757080078, 10.138427734375, 10.6871589660645, 11.5516906738281,
    12.4771171569824, 12.7644668579102, 9.02487182617188, 8.8429817199707,
    9.50254135131836, 9.22763977050781, 8.60505981445312, 9.68806610107422,
    9.77085647583008, 9.95944061279297, 10.3024574279785, 10.7512054443359,
    8.78317031860352, 8.94360504150391, 9.19855346679688, 9.44350967407227,
    10.2734016418457, 11.8314613342285, 12.4076805114746, 12.5829055786133,
    12.3372856140137, 11.6992652893066, 8.82733459472656, 8.83338012695313,
    9.01612014770508, 9.31243057250976, 9.52871017456055, 9.1939811706543,
    9.20086669921875, 9.17466049194336, 9.3692512512207, 9.51042022705078,
    9.55322723388672, 9.08766632080078, 9.01230697631836, 9.08840942382812,
    8.89073867797851, 10.0157516479492, 9.88614654541016, 9.88927917480469,
    9.89448471069336, 9.81435546875, 10.0982810974121, 10.8838890075684,
    12.3737106323242, 12.0203163146973, 12.3476577758789, 8.12273559570312,
    8.38578720092773, 8.5104736328125, 8.67580947875977, 8.8884521484375,
    11.280297088623, 9.81758041381836, 9.12517623901367, 9.57337417602539,
    9.93379745483398, 9.97190170288086, 9.9986442565918, 10.1007339477539,
    10.368416595459, 10.8695823669434, 10.6418167114258, 10.1072540283203,
    9.56202163696289, 10.1464050292969, 11.0315299987793, 15.5208480834961,
    16.458154296875, 16.6033325195312, 16.9603851318359, 17.5446258544922,
    11.6627197265625, 11.2967132568359, 11.0439735412598, 10.7337928771973,
    10.724112701416, 10.414665222168, 10.1816375732422, 10.0053001403809,
    10.0604530334473, 10.3831871032715, 12.5386772155762, 12.61123046875,
    11.556861114502, 10.815104675293, 10.3798713684082, 12.8164276123047,
    12.5301361083984, 12.1416007995605, 11.1006622314453, 10.5525985717773,
    12.7033218383789, 13.5069030761719, 14.3273956298828, 14.1952850341797,
    13.8862731933594, 11.5364295959473, 11.4725784301758, 11.4327659606934,
    11.6338516235352, 11.9929733276367, 10.9388458251953, 10.3944259643555,
    10.7864356994629, 10.4639877319336, 10.4192794799805, 10.584090423584,
    11.0457565307617, 11.1049293518066, 11.2156471252441, 11.2940994262695,
    11.5789703369141, 11.3852058410645, 11.312281036377, 10.8983863830566,
    10.7498306274414, 11.648999786377, 12.1443000793457, 12.3075752258301,
    12.4243774414062, 12.5793846130371, 9.53582992553711, 10.3421630859375,
    10.6005973815918, 10.7018409729004, 10.1489151000977, 15.3236968994141,
    16.6732727050781, 17.0259368896484, 16.9183380126953, 18.6379180908203,
    11.5663963317871, 13.1421661376953, 15.772624206543, 15.2286743164063,
    14.1305938720703, 10.4395881652832, 10.3302070617676, 10.3431907653809,
    10.6234725952148, 10.6850440979004, 10.1355682373047, 10.7770133972168,
    11.2220344543457, 11.121208190918, 10.9759727478027, 10.4280487060547,
    11.4163436889648, 11.5880157470703, 11.367276763916, 11.7584564208984,
    12.3622993469238, 12.8618209838867, 13.0096267700195, 12.7293991088867,
    12.3698738098145, 13.4502487182617, 13.9361175537109, 14.3981384277344,
    14.8455154418945, 14.7898071289063, 10.8285942077637, 11.0353393554688,
    13.0554183959961, 11.4933654785156, 10.6509674072266, 12.3171768188477,
    11.9701278686523, 11.7984405517578, 11.3652336120605, 11.2212104797363,
    11.7747032165527, 12.0631629943848, 11.609635925293, 12.5300575256348,
    12.5889640808105, 14.9442291259766, 15.244026184082, 15.1138778686523,
    14.8327117919922, 14.0672607421875, 13.8624649047852, 14.0361633300781,
    13.746142578125, 13.3890182495117, 12.7229309082031, 11.7338531494141,
    12.4392601013184, 12.6126739501953, 12.3359680175781, 12.0300300598145,
    13.0475494384766, 13.4870010375977, 13.1330673217773, 12.8889770507812,
    11.5218353271484, 12.9545684814453, 12.6848930358887, 12.5185249328613,
    12.1927146911621, 12.1243927001953, 13.6282653808594, 13.0329132080078,
    14.021321105957, 12.7892906188965, 11.5679710388184, 12.4451988220215,
    12.6035362243652, 12.8059692382812, 13.2598541259766, 14.1865646362305,
    11.4154563903809, 12.0055801391602, 12.315015411377, 12.8833023071289,
    13.0320266723633, 11.3923133850098, 12.2035797119141, 12.3115371704102,
    12.4416717529297, 12.8906295776367, 11.4880004882812, 11.4702560424805,
    11.063402557373, 11.520093536377, 11.4941116333008, 10.2884147644043,
    10.4248268127441, 10.2943084716797, 10.4938522338867, 10.171199798584,
    10.8181655883789, 10.7096382141113, 10.3980682373047, 9.85380783081055,
    9.06302337646484, 11.087833404541, 11.297770690918, 11.4384208679199,
    11.8333045959473, 12.6423866271973, 11.0677742004395, 11.1663566589355,
    14.6535186767578, 12.696688079834, 11.9809646606445, 12.5395179748535,
    13.5047088623047, 13.6589874267578, 13.3168762207031, 13.8064010620117,
    13.2664398193359, 12.1466331481934, 11.7755020141602, 11.2214569091797,
    11.967204284668, 13.3286544799805, 13.0230804443359, 12.4111663818359,
    11.5664184570313, 11.507154083252, 10.7482841491699, 10.2523262023926,
    10.5137763977051, 10.6416915893555, 10.925708770752, 12.1461143493652,
    12.5572776794434, 13.0962661743164, 14.0371612548828, 15.6014785766602,
    12.1392105102539, 12.4931434631348, 12.5056259155273, 12.1932655334473,
    12.1573226928711, 12.3337669372559, 12.2943237304688, 12.3938110351563,
    12.3535987854004, 12.2837997436523, 11.199015045166, 11.0299026489258,
    11.4233680725098, 11.3639068603516, 10.776929473877, 15.9578018188477,
    18.5940185546875, 16.6747985839844, 12.2459892272949, 11.7588233947754,
    10.8550109863281, 9.30074844360352, 9.1522102355957, 9.23973083496094,
    9.94997406005859, 21.4329086303711, 20.6476043701172, 20.4366928100586,
    19.5227752685547, 18.6518371582031, 13.4605987548828, 13.7962448120117,
    14.7393859863281, 14.0098480224609, 13.7022705078125, 13.8268768310547,
    13.9131362915039, 14.1420150756836, 14.5985153198242, 15.3337585449219,
    10.2976509094238, 10.6874450683594, 10.6152442932129, 10.3048629760742,
    10.0026962280273, 10.8500930786133, 12.313077545166, 12.8156112670898,
    12.4003845214844, 12.062833404541, 11.8806510925293, 11.9595237731934,
    12.7401191711426, 13.2080368041992, 12.648217010498, 14.9934814453125,
    16.2576446533203, 16.2247314453125, 15.6419891357422, 14.6681213378906,
    10.2608001708984, 10.204532623291, 10.8466209411621, 10.8580635070801,
    10.5870002746582, 12.5249855041504, 13.235661315918, 13.3415161132812,
    13.2680938720703, 13.6001312255859, 10.9847831726074, 10.9526977539062,
    12.1701835632324, 10.9867134094238, 9.62559356689453, 14.671305847168,
    15.7670822143555, 16.5200897216797, 17.2838760375977, 18.5971923828125,
    12.4218063354492, 11.5890487670898, 11.3723731994629, 11.5280731201172,
    12.0742370605469, 11.0745147705078, 10.6635795593262, 10.507258605957,
    10.358984375, 10.2047622680664, 11.231372833252, 11.1456260681152,
    10.8480117797852, 10.3289199829102, 9.81418380737305, 13.1054672241211,
    13.3634078979492, 13.6211837768555, 14.0335067749023, 13.8940582275391,
    11.4586517333984, 11.3107444763184, 12.1839057922363, 11.6442543029785,
    10.0313461303711, 11.5685440063477, 13.461506652832, 13.9238220214844,
    12.9616546630859, 12.0961059570313, 15.3089569091797, 14.529133605957,
    12.9434677124023, 11.6556198120117, 10.7868843078613, 13.7810775756836,
    14.6285568237305, 14.3505905151367, 12.6306495666504, 11.0644081115723,
    13.6406951904297, 13.0658325195313, 11.6025444030762, 10.8227111816406,
    10.6873641967773, 14.1373397827148, 15.3703903198242, 16.4337646484375,
    16.3727081298828, 16.0835571289062, 9.32263946533203, 9.81831588745117,
    10.2201850891113, 10.4734298706055, 10.432006072998, 9.83030319213867,
    9.97000503540039, 10.0799949645996, 10.1364440917969, 10.2572006225586, 
    ...
     .Dim = c(10L, 140L), .Dimnames = list(NULL,
    c("layer.1", "layer.2", "layer.3", "layer.4", "layer.5",
    "layer.6", "layer.7", "layer.8", "layer.9", "layer.10", "layer.11",
    "layer.12", "layer.13", "layer.14", "layer.15", "layer.16",
    "layer.17", "layer.18", "layer.19", "layer.20", "layer.21",
    "layer.22", "layer.23", "layer.24", "layer.25", "layer.26",
    "layer.27", "layer.28", "layer.29", "layer.30", "layer.31",
    "layer.32", "layer.33", "layer.34", "layer.35", "layer.36",
    "layer.37", "layer.38", "layer.39", "layer.40", "layer.41",
    "layer.42", "layer.43", "layer.44", "layer.45", "layer.46",
    "layer.47", "layer.48", "layer.49", "layer.50", "layer.51",
    "layer.52", "layer.53", "layer.54", "layer.55", "layer.56",
    "layer.57", "layer.58", "layer.59", "layer.60", "layer.61",
    "layer.62", "layer.63", "layer.64", "layer.65", "layer.66",
    "layer.67", "layer.68", "layer.69", "layer.70", "layer.71",
    "layer.72", "layer.73", "layer.74", "layer.75", "layer.76",
    "layer.77", "layer.78", "layer.79", "layer.80", "layer.81",
    "layer.82", "layer.83", "layer.84", "layer.85", "layer.86",
    "layer.87", "layer.88", "layer.89", "layer.90", "layer.91",
    "layer.92", "layer.93", "layer.94", "layer.95", "layer.96",
    "layer.97", "layer.98", "layer.99", "layer.100", "layer.101",
    "layer.102", "layer.103", "layer.104", "layer.105", "layer.106",
    "layer.107", "layer.108", "layer.109", "layer.110", "layer.111",
    "layer.112", "layer.113", "layer.114", "layer.115", "layer.116",
    "layer.117", "layer.118", "layer.119", "layer.120", "layer.121",
    "layer.122", "layer.123", "layer.124", "layer.125", "layer.126",
    "layer.127", "layer.128", "layer.129", "layer.130", "layer.131",
    "layer.132", "layer.133", "layer.134", "layer.135", "layer.136",
    "layer.137", "layer.138", "layer.139", "layer.140")))
For the x-axis, I already have 140 values to be plotted. The x variable is called "RCP1pctCO2cumulative" and is 1-dimensional. Here are the values:

dput(RCP1pctCO2cumulative)

    c(0, 0.00697490638121963, 0.0139075990766287, 0.021697436273098,
    0.0302329704165459, 0.0389980841428041, 0.0486239280551672,
    0.0591636016964912, 0.0698652867227793, 0.0806971430778503, 0.0917696304619312,
    0.102874741703272, 0.115288959443569, 0.127942492067814, 0.140930585563183, 0.154951927065849,
    0.169483987987041, 0.18332038372755, 0.197460225224495, 0.211912712454796,
    0.227608525753021, 0.243575794994831, 0.257900005578995, 0.273098181188107,
    0.288984017074108, 0.305822652578354, 0.321933174133301, 0.338437202572823,
    0.356079193949699, 0.373604437708855, 0.389580103754997, 0.406976979970932,
    0.423514771461487, 0.440741804242134, 0.459019854664803, 0.477243804931641,
    0.494844323396683, 0.511731442809105, 0.529583910107613, 0.54879242181778,
    0.568029862642288, 0.587030050158501, 0.606201952695847, 0.626413214206696,
    0.645859175920486, 0.66550235748291, 0.685490393638611, 0.705517685413361,
    0.725719237327576, 0.74520371556282, 0.764879602193832, 0.78538470864296,
    0.806885379552841, 0.827258145809174, 0.847640424966812, 0.869502395391464,
    0.891108268499374, 0.912525850534439, 0.934271132946014, 0.956432664394379,
    0.977902102470398, 0.999574398994446, 1.02313443422317, 1.0449088037014,
    1.06765602231026, 1.09229186177254, 1.11614397168159, 1.13850414156914,
    1.16062269210815, 1.18386173844337, 1.2078672170639, 1.23217906951904,
    1.25505521297455, 1.27949770689011, 1.30394254922867, 1.32788743972778,
    1.35124933719635, 1.37474408149719, 1.39838930368423, 1.42129179239273,
    1.44566521644592, 1.47075144052506, 1.49397988319397, 1.51616193056107,
    1.54051134586334, 1.56606665849686, 1.59053231477737, 1.61592463254929,
    1.64096541404724, 1.66613935232162, 1.69049085378647, 1.71510955095291,
    1.73991868495941, 1.76491104364395, 1.79114699363708, 1.81589571237564,
    1.84101955890656, 1.864857172966, 1.8899533867836, 1.91575677394867,
    1.9422261595726, 1.96840007305145, 1.99298502206802, 2.01899757385254,
    2.04547454118729, 2.07122528553009, 2.09852977991104, 2.12717348337173,
    2.15352830886841, 2.17984690666199, 2.20684263706207, 2.23266286849976,
    2.25915194749832, 2.28647100925446, 2.31463184356689, 2.34280925989151,
    2.36965861320496, 2.39779574871063, 2.42558825016022, 2.45266799926758,
    2.48168079853058, 2.50962221622467, 2.53702754974365, 2.56574511528015,
    2.59377150535583, 2.62192821502686, 2.6505597114563, 2.68051118850708,
    2.70983340740204, 2.73927145004272, 2.76805067062378, 2.79780313968658,
    2.8272668838501, 2.85747616291046, 2.88714888095856, 2.91689431667328,
    2.94743349552155, 2.97868416309357, 3.00965495109558, 3.03861720561981
I tried doing something like this to start:

expansion <- expand.grid(103:116, 3:16) #to specify a range of longitudes  and latitudes

    >lonlat <- extract(RCP1pctCO2Mean, expansion)   >plot(RCP1pctCO2cumulative, lonlat, type="l",col="green", lwd="3", 
    xlab="Cumulative emissions (TtC)", ylab="One-day maximum precipitation 
    (mm/day)", main="Test model")
 
But this yields the error:
    Error in xy.coords(x, y, xlabel, ylabel, log) :
    'x' and 'y' lengths differ
If it helps, here are the dimensions of the new variables created:
   

dim(lonlat)

    [1] 196   140
   

dim(expansion)

   
    [1] 196   2

What could I be doing wrong (the lengths appear to be the same)? Ultimately, the goal would be to plot the 140 values as a function of emissions (i.e. "RCP1pctCO2Mean" as a function of "RCP1pctCO2cumulative" once each of those selected grid cells are aggregated). The above works absolutely fine when just selecting "one" specific grid cell, but not an aggregate of grid cells. Is this possible to do for an aggregate of grid cells?
Thanks, and any assistance would be greatly appreciated!
[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&data=02%7C01%7Ckkilpatrick%40rsmas.miami.edu%7C59333f2be1214c2ef12f08d6c859dc6e%7C2a144b72f23942d48c0e6f0f17c48e33%7C0%7C0%7C636916685638215109&sdata=myKpQUhzVczqH4E4fXt%2FBOr6rPWjOW9rpdsy6RXLq%2Bc%3D&reserved=0



        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Selecting a range of longitudes and latitudes for plotting

Wed, 04/24/2019 - 09:58
Hi;

The reason you are getting that error message is you are trying to plot a 1 dimension array by a 2 dimensional array.

I think simply adding the argument  fun = mean to your extraction of the RCP1pctCO2Mean brick will solve the confusion.
As you have it written you are extracting 196 grid cells  for all 140 layers ending up with a 2d array

 latlon <- extract(RCP1pctCO2Mean, expansion, fun=mean)
Should  give you 140 values in a 1d array that represent the average of the cells in the grid subset for each of the 140 layers in the brick.

Assuming of course that this is what you were after.
 I had to read between the lines a bit not knowing really how RCP1pctCO2cumulative was created -- other than it was precomputed and had a length of 140.

btw: Cellstats would give you the average of the nlayers at each of the 196 grid cells  eg. a 1 d array of 196.

Kay


On Apr 23, 2019, at 10:08 PM, rain1290--- via R-sig-Geo <[hidden email]<mailto:[hidden email]>> wrote:

Hi there,
I am trying to select a range of latitude and longitudes (and all grid cells within that range) to plot y-axis values (precipitation) as a function of x-axis values (emissions) based on aggregating (averaging) each of those grid cells. Thus, let's say that I wanted to aggregate/average each of the values of these grid cells and plot this as a function x-axis values. The values already computed for each grid cell for the y-axis correspond to average precipitation and consist of 140 values per grid cell. So, the idea would be the average the first value of each grid cell, then the second value of each grid cell, then the third value of each grid cell.....all the way to value #140 of each grid cell. This would yield 140 values that would be plotted as a single line plot.  The variable containing these y-axis values is called "RCP1pctCO2Mean", which is 3-dimensional and has the following attributes:    class: RasterBrick
dimensions  : 64, 128, 8192, 140  (nrow, ncol, ncell, nlayers)
resolution  : 2.8125, 2.789327  (x, y)
extent      : -181.4062, 178.5938, -89.25846, 89.25846  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names       :   layer.1,   layer.2,   layer.3,   layer.4,   layer.5,
layer.6,   layer.7,   layer.8,   layer.9,  layer.10,  layer.11,  layer.12,
layer.13,  layer.14,  layer.15, ...
min values  : 0.5261063, 0.5625295, 0.5301681, 0.6019284, 0.5177065,
0.6775601, 0.5336965, 0.5213086, 0.5971723, 0.5305891, 0.5514522,
0.5481200, 0.4681806, 0.5437223, 0.5988844, ...
max values  : 113.13776, 114.50780,  94.93643, 100.35409, 102.65459,
101.80622, 104.95480,  99.17839, 104.68667, 119.48342, 100.60391,
108.91896, 104.38969,  99.35735,  99.30752, ...     >dput(head(RCP1pctCO2ModelMean,5))
    structure(c(8.06056747436523, 7.75062637329102, 7.73271865844727,
    7.65678634643555, 7.75580596923828, 8.74016799926758, 8.28938064575195,
    8.10810775756836, 8.10339508056641, 7.86748199462891, 10.6165672302246,
    11.057600402832, 11.9450210571289, 12.3012786865234, 12.1853874206543,
    8.51755447387695, 9.16703491210938, 7.79627380371094, 7.53922271728516,
    8.14367599487305, 7.83845596313477, 8.22455596923828, 8.21650848388672,
    8.186181640625, 8.34122924804688, 9.1652702331543, 9.03225784301758,
    9.04341430664062, 8.98676376342774, 9.0090087890625, 10.5393569946289,
    11.1039672851562, 11.2379959106445, 11.333048248291, 12.0459312438965,
    10.0039085388184, 9.90224914550781, 9.24856033325195, 9.26007308959961,
    9.17901306152344, 9.55168991088867, 10.1229606628418, 10.4827072143555,
    11.0505676269531, 12.1166931152344, 9.01049194335937, 9.39016952514648,
    10.1307640075684, 9.67219467163086, 9.63750610351562, 8.14553070068359,
    8.06989059448242, 7.88368453979492, 7.78139190673828, 7.76021575927734,
    8.09026031494141, 8.47544021606445, 8.53607864379883, 9.07613296508789,
    8.45474319458008, 9.91985092163086, 10.0807098388672, 9.90288009643555,
    10.3433769226074, 10.349861907959, 11.2688484191895, 11.9406700134277,
    12.0929878234863, 11.8347038269043, 10.4144630432129, 12.5179420471191,
    13.8380874633789, 14.6360946655273, 14.0480010986328, 13.3910736083984,
    9.96924514770508, 10.3363311767578, 10.7060684204102, 10.889599609375,
    10.6653129577637, 10.5626991271973, 10.047868347168, 10.2751319885254,
    10.8663063049316, 11.7612907409668, 8.94287414550781, 9.23690567016602,
    8.96449661254883, 8.62908248901367, 8.30552215576172, 8.18369979858398,
    7.69772872924805, 7.5989143371582, 7.7111930847168, 7.66501693725586,
    10.2653533935547, 9.95307464599609, 9.71684875488281, 9.06423645019531,
    9.75586776733399, 9.83898010253906, 9.89386901855469, 9.82217864990234,
    9.5716667175293, 9.0698844909668, 9.32229309082031, 9.11556243896484,
    8.89283828735352, 9.28563232421875, 9.30773696899414, 7.3968879699707,
    7.93817901611328, 7.98456954956055, 7.95158386230469, 8.098583984375,
    8.80923156738281, 8.49755935668945, 8.15531387329102, 8.46451263427734,
    8.68563690185547, 8.89066619873047, 9.1489013671875, 9.33551254272461,
    10.1721000671387, 11.0765029907227, 8.04215698242188, 8.19046478271484,
    8.40826110839844, 8.67290573120117, 9.18575973510742, 8.3109245300293,
    9.11093368530273, 9.81162109375, 9.86040802001953, 9.50505447387695,
    10.5363166809082, 9.481689453125, 9.08926620483398, 9.52505798339844,
    8.68244476318359, 8.98393630981445, 10.1831520080566, 10.5507629394531,
    10.1666023254395, 9.69676284790039, 8.34152221679688, 8.42654571533203,
    8.35252838134766, 8.00343780517578, 7.82494201660156, 9.53874359130859,
    9.61768341064453, 9.41213912963867, 9.64521713256836, 10.2018295288086,
    10.4372673034668, 10.2102493286133, 11.5178192138672, 10.6066253662109,
    8.7693229675293, 10.0142112731934, 10.0218872070313, 9.85999298095703,
    9.61988754272461, 9.6459342956543, 8.68394012451172, 8.94484100341797,
    8.99103088378906, 9.28208084106445, 9.25485153198242, 9.43952713012695,
    9.46648941040039, 9.29736251831055, 9.17809677124023, 9.15292205810547,
    9.86052169799805, 9.73173980712891, 9.56215209960937, 9.07076568603516,
    8.6406623840332, 9.93644332885742, 10.4607345581055, 10.7315849304199,
    10.8101539611816, 10.7245536804199, 8.11333770751953, 8.19898986816406,
    9.07229690551758, 8.52103500366211, 8.86794967651367, 13.8089904785156,
    14.1628616333008, 14.1612731933594, 13.8391723632812, 13.4812423706055,
    10.3034606933594, 10.3893714904785, 10.6155006408691, 10.7073356628418,
    10.2250640869141, 10.7160522460937, 10.9937141418457, 11.4714202880859,
    11.451326751709, 11.2873542785645, 10.1245864868164, 10.7054138183594,
    11.2963111877441, 11.2652069091797, 11.1456642150879, 10.2463417053223,
    10.7579162597656, 10.9033828735352, 10.8239326477051, 10.9808113098145,
    9.11014785766602, 9.57601928710938, 9.13134765625, 8.95542297363281,
    9.004345703125, 10.011986541748, 10.4038223266602, 10.7760765075684,
    10.8257308959961, 11.1445190429687, 10.5380798339844, 10.2488784790039,
    10.957502746582, 10.7088333129883, 10.6826118469238, 8.83894119262695,
    9.23114776611328, 8.83077545166016, 8.79364471435547, 9.5740608215332,
    9.49266204833984, 9.36201629638672, 8.86088562011719, 8.70853042602539,
    8.84630584716797, 8.54691619873047, 9.06980133056641, 9.68758087158203,
    10.2382141113281, 11.163306427002, 8.64593887329102, 8.68509368896484,
    9.1695442199707, 9.96113128662109, 10.5646827697754, 10.6185249328613,
    11.3931076049805, 11.984349822998, 12.3294868469238, 12.6237396240234,
    9.07107849121094, 8.50119094848633, 8.165673828125, 8.46488571166992,
    8.7583610534668, 9.64865646362305, 11.1105819702148, 11.4002655029297,
    10.5027854919434, 10.1196365356445, 9.72924041748047, 10.009349822998,
    10.326407623291, 9.36514053344727, 7.79587249755859, 9.68682708740234,
    9.97370910644531, 10.053092956543, 10.0790946960449, 9.88732604980469,
    8.5629150390625, 8.67814178466797, 8.62764282226562, 8.40693130493164,
    8.43646850585938, 8.18491287231445, 8.28544006347656, 8.32042083740234,
    8.37117156982422, 8.74075393676758, 10.0410667419434, 9.86564865112305,
    9.83465423583984, 10.2372169494629, 10.6772819519043, 10.7158340454102,
    11.1418548583984, 11.3801231384277, 12.3574913024902, 12.7044395446777,
    10.933625793457, 10.1660957336426, 8.9215690612793, 9.42180328369141,
    10.0563125610352, 10.6793243408203, 10.605298614502, 10.532593536377,
    10.4527519226074, 10.4930633544922, 9.60543518066406, 9.36136474609375,
    9.02150115966797, 8.90760498046875, 9.39027709960937, 11.475407409668,
    11.8939018249512, 12.2665367126465, 12.3773796081543, 12.2639549255371,
    12.1986907958984, 12.9296035766602, 14.6138290405273, 12.5118690490723,
    11.1584533691406, 11.6089347839355, 12.184122467041, 12.7126617431641,
    12.8846618652344, 12.7170280456543, 10.4427520751953, 11.0104148864746,
    11.0574317932129, 10.7889305114746, 11.428002166748, 12.8730773925781,
    13.0610855102539, 13.9772033691406, 14.7699234008789, 15.2759140014648,
    11.0441619873047, 12.8132598876953, 13.1194686889648, 13.3944534301758,
    13.439665222168, 11.8274314880371, 12.5198951721191, 13.1492401123047,
    13.310026550293, 13.7720932006836, 10.7566696166992, 11.1153205871582,
    10.8651023864746, 10.8898574829102, 11.1934638977051, 10.3416526794434,
    10.3679290771484, 10.5599853515625, 10.4897705078125, 10.3551536560059,
    10.7984680175781, 9.9300895690918, 9.24563140869141, 8.82577590942383,
    8.11003036499023, 9.96226196289063, 10.2302505493164, 10.1707107543945,
    9.78019790649414, 9.43962249755859, 11.1743797302246, 11.4034492492676,
    10.9475212097168, 11.3065505981445, 11.3690071105957, 9.07691192626953,
    8.84776763916016, 8.99648666381836, 9.46799697875977, 10.1394309997559,
    9.5390739440918, 9.72808990478516, 10.1971199035645, 10.3575813293457,
    10.6958648681641, 12.1900230407715, 11.986629486084, 12.139289855957,
    12.308757019043, 12.2176116943359, 10.5569931030273, 10.2808883666992,
    9.90982055664062, 9.57319793701172, 9.34677658081055, 9.55350112915039,
    9.78641738891602, 10.0147956848145, 10.3079559326172, 10.7283164978027,
    8.64087753295899, 8.30433197021484, 8.60956497192383, 8.60016937255859,
    8.54900741577148, 9.71597595214844, 8.8296272277832, 8.63880462646484,
    8.47726745605469, 8.84029846191406, 10.1157096862793, 9.88607330322266,
    9.32783508300781, 9.36255416870117, 10.1161201477051, 11.8296203613281,
    12.8728881835937, 13.2580642700195, 13.5822448730469, 14.2079498291016,
    8.7088752746582, 8.82841796875, 9.62056427001953, 9.44509429931641,
    8.63022689819336, 10.438533782959, 10.7936264038086, 11.1668098449707,
    11.4698097229004, 11.6895088195801, 10.657413482666, 10.6490295410156,
    10.6090156555176, 10.7308578491211, 10.2125785827637, 8.9413688659668,
    8.8182373046875, 8.83381042480469, 8.8937255859375, 8.81535415649414,
    9.55851669311523, 9.21836166381836, 9.18197784423828, 9.25029678344726,
    9.27070083618164, 8.93240661621094, 8.90249099731445, 9.04313659667969,
    9.20108184814453, 9.35103607177734, 10.5618942260742, 11.06572265625,
    11.445832824707, 11.9180442810059, 11.9453758239746, 12.2584243774414,
    11.9192649841309, 11.7775825500488, 11.8008255004883, 12.2185432434082,
    9.08272094726562, 9.66560821533203, 9.48288192749023, 9.70498886108398,
    9.56975555419922, 10.349006652832, 10.0300796508789, 9.5968864440918,
    9.54965896606445, 9.00812759399414, 10.6454582214355, 10.7713653564453,
    11.4645782470703, 11.8325187683105, 10.4740211486816, 9.41022796630859,
    9.07474822998047, 8.61860656738281, 8.40045318603516, 8.653662109375,
    9.65197830200195, 9.63723449707031, 9.51137924194336, 9.57775497436523,
    9.69926528930664, 8.98936157226563, 9.40332794189453, 9.6757568359375,
    9.79740600585938, 9.78034057617188, 10.2542152404785, 10.1619010925293,
    10.3302688598633, 10.5525291442871, 10.7628135681152, 10.2399101257324,
    10.7667839050293, 10.9936302185059, 10.8458152770996, 10.6235733032227,
    9.24678955078125, 9.91125411987305, 9.86469879150391, 10.2658912658691,
    10.1045028686523, 8.5959098815918, 8.49214401245117, 8.39304656982422,
    8.6228157043457, 8.61747360229492, 8.91071395874024, 8.69116439819336,
    8.56472625732422, 8.52434997558594, 8.64141616821289, 11.7017639160156,
    12.3285125732422, 12.0996276855469, 11.056103515625, 10.7624618530273,
    11.0327911376953, 12.0061622619629, 11.4006072998047, 10.8051193237305,
    9.97594757080078, 10.138427734375, 10.6871589660645, 11.5516906738281,
    12.4771171569824, 12.7644668579102, 9.02487182617188, 8.8429817199707,
    9.50254135131836, 9.22763977050781, 8.60505981445312, 9.68806610107422,
    9.77085647583008, 9.95944061279297, 10.3024574279785, 10.7512054443359,
    8.78317031860352, 8.94360504150391, 9.19855346679688, 9.44350967407227,
    10.2734016418457, 11.8314613342285, 12.4076805114746, 12.5829055786133,
    12.3372856140137, 11.6992652893066, 8.82733459472656, 8.83338012695313,
    9.01612014770508, 9.31243057250976, 9.52871017456055, 9.1939811706543,
    9.20086669921875, 9.17466049194336, 9.3692512512207, 9.51042022705078,
    9.55322723388672, 9.08766632080078, 9.01230697631836, 9.08840942382812,
    8.89073867797851, 10.0157516479492, 9.88614654541016, 9.88927917480469,
    9.89448471069336, 9.81435546875, 10.0982810974121, 10.8838890075684,
    12.3737106323242, 12.0203163146973, 12.3476577758789, 8.12273559570312,
    8.38578720092773, 8.5104736328125, 8.67580947875977, 8.8884521484375,
    11.280297088623, 9.81758041381836, 9.12517623901367, 9.57337417602539,
    9.93379745483398, 9.97190170288086, 9.9986442565918, 10.1007339477539,
    10.368416595459, 10.8695823669434, 10.6418167114258, 10.1072540283203,
    9.56202163696289, 10.1464050292969, 11.0315299987793, 15.5208480834961,
    16.458154296875, 16.6033325195312, 16.9603851318359, 17.5446258544922,
    11.6627197265625, 11.2967132568359, 11.0439735412598, 10.7337928771973,
    10.724112701416, 10.414665222168, 10.1816375732422, 10.0053001403809,
    10.0604530334473, 10.3831871032715, 12.5386772155762, 12.61123046875,
    11.556861114502, 10.815104675293, 10.3798713684082, 12.8164276123047,
    12.5301361083984, 12.1416007995605, 11.1006622314453, 10.5525985717773,
    12.7033218383789, 13.5069030761719, 14.3273956298828, 14.1952850341797,
    13.8862731933594, 11.5364295959473, 11.4725784301758, 11.4327659606934,
    11.6338516235352, 11.9929733276367, 10.9388458251953, 10.3944259643555,
    10.7864356994629, 10.4639877319336, 10.4192794799805, 10.584090423584,
    11.0457565307617, 11.1049293518066, 11.2156471252441, 11.2940994262695,
    11.5789703369141, 11.3852058410645, 11.312281036377, 10.8983863830566,
    10.7498306274414, 11.648999786377, 12.1443000793457, 12.3075752258301,
    12.4243774414062, 12.5793846130371, 9.53582992553711, 10.3421630859375,
    10.6005973815918, 10.7018409729004, 10.1489151000977, 15.3236968994141,
    16.6732727050781, 17.0259368896484, 16.9183380126953, 18.6379180908203,
    11.5663963317871, 13.1421661376953, 15.772624206543, 15.2286743164063,
    14.1305938720703, 10.4395881652832, 10.3302070617676, 10.3431907653809,
    10.6234725952148, 10.6850440979004, 10.1355682373047, 10.7770133972168,
    11.2220344543457, 11.121208190918, 10.9759727478027, 10.4280487060547,
    11.4163436889648, 11.5880157470703, 11.367276763916, 11.7584564208984,
    12.3622993469238, 12.8618209838867, 13.0096267700195, 12.7293991088867,
    12.3698738098145, 13.4502487182617, 13.9361175537109, 14.3981384277344,
    14.8455154418945, 14.7898071289063, 10.8285942077637, 11.0353393554688,
    13.0554183959961, 11.4933654785156, 10.6509674072266, 12.3171768188477,
    11.9701278686523, 11.7984405517578, 11.3652336120605, 11.2212104797363,
    11.7747032165527, 12.0631629943848, 11.609635925293, 12.5300575256348,
    12.5889640808105, 14.9442291259766, 15.244026184082, 15.1138778686523,
    14.8327117919922, 14.0672607421875, 13.8624649047852, 14.0361633300781,
    13.746142578125, 13.3890182495117, 12.7229309082031, 11.7338531494141,
    12.4392601013184, 12.6126739501953, 12.3359680175781, 12.0300300598145,
    13.0475494384766, 13.4870010375977, 13.1330673217773, 12.8889770507812,
    11.5218353271484, 12.9545684814453, 12.6848930358887, 12.5185249328613,
    12.1927146911621, 12.1243927001953, 13.6282653808594, 13.0329132080078,
    14.021321105957, 12.7892906188965, 11.5679710388184, 12.4451988220215,
    12.6035362243652, 12.8059692382812, 13.2598541259766, 14.1865646362305,
    11.4154563903809, 12.0055801391602, 12.315015411377, 12.8833023071289,
    13.0320266723633, 11.3923133850098, 12.2035797119141, 12.3115371704102,
    12.4416717529297, 12.8906295776367, 11.4880004882812, 11.4702560424805,
    11.063402557373, 11.520093536377, 11.4941116333008, 10.2884147644043,
    10.4248268127441, 10.2943084716797, 10.4938522338867, 10.171199798584,
    10.8181655883789, 10.7096382141113, 10.3980682373047, 9.85380783081055,
    9.06302337646484, 11.087833404541, 11.297770690918, 11.4384208679199,
    11.8333045959473, 12.6423866271973, 11.0677742004395, 11.1663566589355,
    14.6535186767578, 12.696688079834, 11.9809646606445, 12.5395179748535,
    13.5047088623047, 13.6589874267578, 13.3168762207031, 13.8064010620117,
    13.2664398193359, 12.1466331481934, 11.7755020141602, 11.2214569091797,
    11.967204284668, 13.3286544799805, 13.0230804443359, 12.4111663818359,
    11.5664184570313, 11.507154083252, 10.7482841491699, 10.2523262023926,
    10.5137763977051, 10.6416915893555, 10.925708770752, 12.1461143493652,
    12.5572776794434, 13.0962661743164, 14.0371612548828, 15.6014785766602,
    12.1392105102539, 12.4931434631348, 12.5056259155273, 12.1932655334473,
    12.1573226928711, 12.3337669372559, 12.2943237304688, 12.3938110351563,
    12.3535987854004, 12.2837997436523, 11.199015045166, 11.0299026489258,
    11.4233680725098, 11.3639068603516, 10.776929473877, 15.9578018188477,
    18.5940185546875, 16.6747985839844, 12.2459892272949, 11.7588233947754,
    10.8550109863281, 9.30074844360352, 9.1522102355957, 9.23973083496094,
    9.94997406005859, 21.4329086303711, 20.6476043701172, 20.4366928100586,
    19.5227752685547, 18.6518371582031, 13.4605987548828, 13.7962448120117,
    14.7393859863281, 14.0098480224609, 13.7022705078125, 13.8268768310547,
    13.9131362915039, 14.1420150756836, 14.5985153198242, 15.3337585449219,
    10.2976509094238, 10.6874450683594, 10.6152442932129, 10.3048629760742,
    10.0026962280273, 10.8500930786133, 12.313077545166, 12.8156112670898,
    12.4003845214844, 12.062833404541, 11.8806510925293, 11.9595237731934,
    12.7401191711426, 13.2080368041992, 12.648217010498, 14.9934814453125,
    16.2576446533203, 16.2247314453125, 15.6419891357422, 14.6681213378906,
    10.2608001708984, 10.204532623291, 10.8466209411621, 10.8580635070801,
    10.5870002746582, 12.5249855041504, 13.235661315918, 13.3415161132812,
    13.2680938720703, 13.6001312255859, 10.9847831726074, 10.9526977539062,
    12.1701835632324, 10.9867134094238, 9.62559356689453, 14.671305847168,
    15.7670822143555, 16.5200897216797, 17.2838760375977, 18.5971923828125,
    12.4218063354492, 11.5890487670898, 11.3723731994629, 11.5280731201172,
    12.0742370605469, 11.0745147705078, 10.6635795593262, 10.507258605957,
    10.358984375, 10.2047622680664, 11.231372833252, 11.1456260681152,
    10.8480117797852, 10.3289199829102, 9.81418380737305, 13.1054672241211,
    13.3634078979492, 13.6211837768555, 14.0335067749023, 13.8940582275391,
    11.4586517333984, 11.3107444763184, 12.1839057922363, 11.6442543029785,
    10.0313461303711, 11.5685440063477, 13.461506652832, 13.9238220214844,
    12.9616546630859, 12.0961059570313, 15.3089569091797, 14.529133605957,
    12.9434677124023, 11.6556198120117, 10.7868843078613, 13.7810775756836,
    14.6285568237305, 14.3505905151367, 12.6306495666504, 11.0644081115723,
    13.6406951904297, 13.0658325195313, 11.6025444030762, 10.8227111816406,
    10.6873641967773, 14.1373397827148, 15.3703903198242, 16.4337646484375,
    16.3727081298828, 16.0835571289062, 9.32263946533203, 9.81831588745117,
    10.2201850891113, 10.4734298706055, 10.432006072998, 9.83030319213867,
    9.97000503540039, 10.0799949645996, 10.1364440917969, 10.2572006225586,
    ...
     .Dim = c(10L, 140L), .Dimnames = list(NULL,
    c("layer.1", "layer.2", "layer.3", "layer.4", "layer.5",
    "layer.6", "layer.7", "layer.8", "layer.9", "layer.10", "layer.11",
    "layer.12", "layer.13", "layer.14", "layer.15", "layer.16",
    "layer.17", "layer.18", "layer.19", "layer.20", "layer.21",
    "layer.22", "layer.23", "layer.24", "layer.25", "layer.26",
    "layer.27", "layer.28", "layer.29", "layer.30", "layer.31",
    "layer.32", "layer.33", "layer.34", "layer.35", "layer.36",
    "layer.37", "layer.38", "layer.39", "layer.40", "layer.41",
    "layer.42", "layer.43", "layer.44", "layer.45", "layer.46",
    "layer.47", "layer.48", "layer.49", "layer.50", "layer.51",
    "layer.52", "layer.53", "layer.54", "layer.55", "layer.56",
    "layer.57", "layer.58", "layer.59", "layer.60", "layer.61",
    "layer.62", "layer.63", "layer.64", "layer.65", "layer.66",
    "layer.67", "layer.68", "layer.69", "layer.70", "layer.71",
    "layer.72", "layer.73", "layer.74", "layer.75", "layer.76",
    "layer.77", "layer.78", "layer.79", "layer.80", "layer.81",
    "layer.82", "layer.83", "layer.84", "layer.85", "layer.86",
    "layer.87", "layer.88", "layer.89", "layer.90", "layer.91",
    "layer.92", "layer.93", "layer.94", "layer.95", "layer.96",
    "layer.97", "layer.98", "layer.99", "layer.100", "layer.101",
    "layer.102", "layer.103", "layer.104", "layer.105", "layer.106",
    "layer.107", "layer.108", "layer.109", "layer.110", "layer.111",
    "layer.112", "layer.113", "layer.114", "layer.115", "layer.116",
    "layer.117", "layer.118", "layer.119", "layer.120", "layer.121",
    "layer.122", "layer.123", "layer.124", "layer.125", "layer.126",
    "layer.127", "layer.128", "layer.129", "layer.130", "layer.131",
    "layer.132", "layer.133", "layer.134", "layer.135", "layer.136",
    "layer.137", "layer.138", "layer.139", "layer.140")))
For the x-axis, I already have 140 values to be plotted. The x variable is called "RCP1pctCO2cumulative" and is 1-dimensional. Here are the values:
dput(RCP1pctCO2cumulative)
    c(0, 0.00697490638121963, 0.0139075990766287, 0.021697436273098,
    0.0302329704165459, 0.0389980841428041, 0.0486239280551672,
    0.0591636016964912, 0.0698652867227793, 0.0806971430778503, 0.0917696304619312,
    0.102874741703272, 0.115288959443569, 0.127942492067814, 0.140930585563183, 0.154951927065849,
    0.169483987987041, 0.18332038372755, 0.197460225224495, 0.211912712454796,
    0.227608525753021, 0.243575794994831, 0.257900005578995, 0.273098181188107,
    0.288984017074108, 0.305822652578354, 0.321933174133301, 0.338437202572823,
    0.356079193949699, 0.373604437708855, 0.389580103754997, 0.406976979970932,
    0.423514771461487, 0.440741804242134, 0.459019854664803, 0.477243804931641,
    0.494844323396683, 0.511731442809105, 0.529583910107613, 0.54879242181778,
    0.568029862642288, 0.587030050158501, 0.606201952695847, 0.626413214206696,
    0.645859175920486, 0.66550235748291, 0.685490393638611, 0.705517685413361,
    0.725719237327576, 0.74520371556282, 0.764879602193832, 0.78538470864296,
    0.806885379552841, 0.827258145809174, 0.847640424966812, 0.869502395391464,
    0.891108268499374, 0.912525850534439, 0.934271132946014, 0.956432664394379,
    0.977902102470398, 0.999574398994446, 1.02313443422317, 1.0449088037014,
    1.06765602231026, 1.09229186177254, 1.11614397168159, 1.13850414156914,
    1.16062269210815, 1.18386173844337, 1.2078672170639, 1.23217906951904,
    1.25505521297455, 1.27949770689011, 1.30394254922867, 1.32788743972778,
    1.35124933719635, 1.37474408149719, 1.39838930368423, 1.42129179239273,
    1.44566521644592, 1.47075144052506, 1.49397988319397, 1.51616193056107,
    1.54051134586334, 1.56606665849686, 1.59053231477737, 1.61592463254929,
    1.64096541404724, 1.66613935232162, 1.69049085378647, 1.71510955095291,
    1.73991868495941, 1.76491104364395, 1.79114699363708, 1.81589571237564,
    1.84101955890656, 1.864857172966, 1.8899533867836, 1.91575677394867,
    1.9422261595726, 1.96840007305145, 1.99298502206802, 2.01899757385254,
    2.04547454118729, 2.07122528553009, 2.09852977991104, 2.12717348337173,
    2.15352830886841, 2.17984690666199, 2.20684263706207, 2.23266286849976,
    2.25915194749832, 2.28647100925446, 2.31463184356689, 2.34280925989151,
    2.36965861320496, 2.39779574871063, 2.42558825016022, 2.45266799926758,
    2.48168079853058, 2.50962221622467, 2.53702754974365, 2.56574511528015,
    2.59377150535583, 2.62192821502686, 2.6505597114563, 2.68051118850708,
    2.70983340740204, 2.73927145004272, 2.76805067062378, 2.79780313968658,
    2.8272668838501, 2.85747616291046, 2.88714888095856, 2.91689431667328,
    2.94743349552155, 2.97868416309357, 3.00965495109558, 3.03861720561981
I tried doing something like this to start:
expansion <- expand.grid(103:116, 3:16) #to specify a range of longitudes  and latitudes
    >lonlat <- extract(RCP1pctCO2Mean, expansion)   >plot(RCP1pctCO2cumulative, lonlat, type="l",col="green", lwd="3",
    xlab="Cumulative emissions (TtC)", ylab="One-day maximum precipitation
    (mm/day)", main="Test model")

But this yields the error:
    Error in xy.coords(x, y, xlabel, ylabel, log) :
    'x' and 'y' lengths differ
If it helps, here are the dimensions of the new variables created:

dim(lonlat)
    [1] 196   140

dim(expansion)

    [1] 196   2

What could I be doing wrong (the lengths appear to be the same)? Ultimately, the goal would be to plot the 140 values as a function of emissions (i.e. "RCP1pctCO2Mean" as a function of "RCP1pctCO2cumulative" once each of those selected grid cells are aggregated). The above works absolutely fine when just selecting "one" specific grid cell, but not an aggregate of grid cells. Is this possible to do for an aggregate of grid cells?
Thanks, and any assistance would be greatly appreciated!
[[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]<mailto:[hidden email]>
https://nam01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-sig-geo&amp;data=02%7C01%7Ckkilpatrick%40rsmas.miami.edu%7C59333f2be1214c2ef12f08d6c859dc6e%7C2a144b72f23942d48c0e6f0f17c48e33%7C0%7C0%7C636916685638215109&amp;sdata=myKpQUhzVczqH4E4fXt%2FBOr6rPWjOW9rpdsy6RXLq%2Bc%3D&amp;reserved=0


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Selecting a range of longitudes and latitudes for plotting

Tue, 04/23/2019 - 21:08
Hi there,
I am trying to select a range of latitude and longitudes (and all grid cells within that range) to plot y-axis values (precipitation) as a function of x-axis values (emissions) based on aggregating (averaging) each of those grid cells. Thus, let's say that I wanted to aggregate/average each of the values of these grid cells and plot this as a function x-axis values. The values already computed for each grid cell for the y-axis correspond to average precipitation and consist of 140 values per grid cell. So, the idea would be the average the first value of each grid cell, then the second value of each grid cell, then the third value of each grid cell.....all the way to value #140 of each grid cell. This would yield 140 values that would be plotted as a single line plot.  The variable containing these y-axis values is called "RCP1pctCO2Mean", which is 3-dimensional and has the following attributes:    class: RasterBrick
dimensions  : 64, 128, 8192, 140  (nrow, ncol, ncell, nlayers)
resolution  : 2.8125, 2.789327  (x, y)
extent      : -181.4062, 178.5938, -89.25846, 89.25846  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names       :   layer.1,   layer.2,   layer.3,   layer.4,   layer.5,    
layer.6,   layer.7,   layer.8,   layer.9,  layer.10,  layer.11,  layer.12, 
layer.13,  layer.14,  layer.15, ...
min values  : 0.5261063, 0.5625295, 0.5301681, 0.6019284, 0.5177065, 
0.6775601, 0.5336965, 0.5213086, 0.5971723, 0.5305891, 0.5514522,  
0.5481200, 0.4681806, 0.5437223, 0.5988844, ...
max values  : 113.13776, 114.50780,  94.93643, 100.35409, 102.65459,
101.80622, 104.95480,  99.17839, 104.68667, 119.48342, 100.60391,
108.91896, 104.38969,  99.35735,  99.30752, ...     >dput(head(RCP1pctCO2ModelMean,5))
    structure(c(8.06056747436523, 7.75062637329102, 7.73271865844727,
    7.65678634643555, 7.75580596923828, 8.74016799926758, 8.28938064575195,
    8.10810775756836, 8.10339508056641, 7.86748199462891, 10.6165672302246,
    11.057600402832, 11.9450210571289, 12.3012786865234, 12.1853874206543,
    8.51755447387695, 9.16703491210938, 7.79627380371094, 7.53922271728516,
    8.14367599487305, 7.83845596313477, 8.22455596923828, 8.21650848388672,
    8.186181640625, 8.34122924804688, 9.1652702331543, 9.03225784301758,
    9.04341430664062, 8.98676376342774, 9.0090087890625, 10.5393569946289,
    11.1039672851562, 11.2379959106445, 11.333048248291, 12.0459312438965,
    10.0039085388184, 9.90224914550781, 9.24856033325195, 9.26007308959961,
    9.17901306152344, 9.55168991088867, 10.1229606628418, 10.4827072143555,
    11.0505676269531, 12.1166931152344, 9.01049194335937, 9.39016952514648,
    10.1307640075684, 9.67219467163086, 9.63750610351562, 8.14553070068359,
    8.06989059448242, 7.88368453979492, 7.78139190673828, 7.76021575927734,
    8.09026031494141, 8.47544021606445, 8.53607864379883, 9.07613296508789,
    8.45474319458008, 9.91985092163086, 10.0807098388672, 9.90288009643555,
    10.3433769226074, 10.349861907959, 11.2688484191895, 11.9406700134277,
    12.0929878234863, 11.8347038269043, 10.4144630432129, 12.5179420471191,
    13.8380874633789, 14.6360946655273, 14.0480010986328, 13.3910736083984,
    9.96924514770508, 10.3363311767578, 10.7060684204102, 10.889599609375,
    10.6653129577637, 10.5626991271973, 10.047868347168, 10.2751319885254,
    10.8663063049316, 11.7612907409668, 8.94287414550781, 9.23690567016602,
    8.96449661254883, 8.62908248901367, 8.30552215576172, 8.18369979858398,
    7.69772872924805, 7.5989143371582, 7.7111930847168, 7.66501693725586,
    10.2653533935547, 9.95307464599609, 9.71684875488281, 9.06423645019531,
    9.75586776733399, 9.83898010253906, 9.89386901855469, 9.82217864990234,
    9.5716667175293, 9.0698844909668, 9.32229309082031, 9.11556243896484,
    8.89283828735352, 9.28563232421875, 9.30773696899414, 7.3968879699707,
    7.93817901611328, 7.98456954956055, 7.95158386230469, 8.098583984375,
    8.80923156738281, 8.49755935668945, 8.15531387329102, 8.46451263427734,
    8.68563690185547, 8.89066619873047, 9.1489013671875, 9.33551254272461,
    10.1721000671387, 11.0765029907227, 8.04215698242188, 8.19046478271484,
    8.40826110839844, 8.67290573120117, 9.18575973510742, 8.3109245300293,
    9.11093368530273, 9.81162109375, 9.86040802001953, 9.50505447387695,
    10.5363166809082, 9.481689453125, 9.08926620483398, 9.52505798339844,
    8.68244476318359, 8.98393630981445, 10.1831520080566, 10.5507629394531,
    10.1666023254395, 9.69676284790039, 8.34152221679688, 8.42654571533203,
    8.35252838134766, 8.00343780517578, 7.82494201660156, 9.53874359130859,
    9.61768341064453, 9.41213912963867, 9.64521713256836, 10.2018295288086,
    10.4372673034668, 10.2102493286133, 11.5178192138672, 10.6066253662109,
    8.7693229675293, 10.0142112731934, 10.0218872070313, 9.85999298095703,
    9.61988754272461, 9.6459342956543, 8.68394012451172, 8.94484100341797,
    8.99103088378906, 9.28208084106445, 9.25485153198242, 9.43952713012695,
    9.46648941040039, 9.29736251831055, 9.17809677124023, 9.15292205810547,
    9.86052169799805, 9.73173980712891, 9.56215209960937, 9.07076568603516,
    8.6406623840332, 9.93644332885742, 10.4607345581055, 10.7315849304199,
    10.8101539611816, 10.7245536804199, 8.11333770751953, 8.19898986816406,
    9.07229690551758, 8.52103500366211, 8.86794967651367, 13.8089904785156,
    14.1628616333008, 14.1612731933594, 13.8391723632812, 13.4812423706055,
    10.3034606933594, 10.3893714904785, 10.6155006408691, 10.7073356628418,
    10.2250640869141, 10.7160522460937, 10.9937141418457, 11.4714202880859,
    11.451326751709, 11.2873542785645, 10.1245864868164, 10.7054138183594,
    11.2963111877441, 11.2652069091797, 11.1456642150879, 10.2463417053223,
    10.7579162597656, 10.9033828735352, 10.8239326477051, 10.9808113098145,
    9.11014785766602, 9.57601928710938, 9.13134765625, 8.95542297363281,
    9.004345703125, 10.011986541748, 10.4038223266602, 10.7760765075684,
    10.8257308959961, 11.1445190429687, 10.5380798339844, 10.2488784790039,
    10.957502746582, 10.7088333129883, 10.6826118469238, 8.83894119262695,
    9.23114776611328, 8.83077545166016, 8.79364471435547, 9.5740608215332,
    9.49266204833984, 9.36201629638672, 8.86088562011719, 8.70853042602539,
    8.84630584716797, 8.54691619873047, 9.06980133056641, 9.68758087158203,
    10.2382141113281, 11.163306427002, 8.64593887329102, 8.68509368896484,
    9.1695442199707, 9.96113128662109, 10.5646827697754, 10.6185249328613,
    11.3931076049805, 11.984349822998, 12.3294868469238, 12.6237396240234,
    9.07107849121094, 8.50119094848633, 8.165673828125, 8.46488571166992,
    8.7583610534668, 9.64865646362305, 11.1105819702148, 11.4002655029297,
    10.5027854919434, 10.1196365356445, 9.72924041748047, 10.009349822998,
    10.326407623291, 9.36514053344727, 7.79587249755859, 9.68682708740234,
    9.97370910644531, 10.053092956543, 10.0790946960449, 9.88732604980469,
    8.5629150390625, 8.67814178466797, 8.62764282226562, 8.40693130493164,
    8.43646850585938, 8.18491287231445, 8.28544006347656, 8.32042083740234,
    8.37117156982422, 8.74075393676758, 10.0410667419434, 9.86564865112305,
    9.83465423583984, 10.2372169494629, 10.6772819519043, 10.7158340454102,
    11.1418548583984, 11.3801231384277, 12.3574913024902, 12.7044395446777,
    10.933625793457, 10.1660957336426, 8.9215690612793, 9.42180328369141,
    10.0563125610352, 10.6793243408203, 10.605298614502, 10.532593536377,
    10.4527519226074, 10.4930633544922, 9.60543518066406, 9.36136474609375,
    9.02150115966797, 8.90760498046875, 9.39027709960937, 11.475407409668,
    11.8939018249512, 12.2665367126465, 12.3773796081543, 12.2639549255371,
    12.1986907958984, 12.9296035766602, 14.6138290405273, 12.5118690490723,
    11.1584533691406, 11.6089347839355, 12.184122467041, 12.7126617431641,
    12.8846618652344, 12.7170280456543, 10.4427520751953, 11.0104148864746,
    11.0574317932129, 10.7889305114746, 11.428002166748, 12.8730773925781,
    13.0610855102539, 13.9772033691406, 14.7699234008789, 15.2759140014648,
    11.0441619873047, 12.8132598876953, 13.1194686889648, 13.3944534301758,
    13.439665222168, 11.8274314880371, 12.5198951721191, 13.1492401123047,
    13.310026550293, 13.7720932006836, 10.7566696166992, 11.1153205871582,
    10.8651023864746, 10.8898574829102, 11.1934638977051, 10.3416526794434,
    10.3679290771484, 10.5599853515625, 10.4897705078125, 10.3551536560059,
    10.7984680175781, 9.9300895690918, 9.24563140869141, 8.82577590942383,
    8.11003036499023, 9.96226196289063, 10.2302505493164, 10.1707107543945,
    9.78019790649414, 9.43962249755859, 11.1743797302246, 11.4034492492676,
    10.9475212097168, 11.3065505981445, 11.3690071105957, 9.07691192626953,
    8.84776763916016, 8.99648666381836, 9.46799697875977, 10.1394309997559,
    9.5390739440918, 9.72808990478516, 10.1971199035645, 10.3575813293457,
    10.6958648681641, 12.1900230407715, 11.986629486084, 12.139289855957,
    12.308757019043, 12.2176116943359, 10.5569931030273, 10.2808883666992,
    9.90982055664062, 9.57319793701172, 9.34677658081055, 9.55350112915039,
    9.78641738891602, 10.0147956848145, 10.3079559326172, 10.7283164978027,
    8.64087753295899, 8.30433197021484, 8.60956497192383, 8.60016937255859,
    8.54900741577148, 9.71597595214844, 8.8296272277832, 8.63880462646484,
    8.47726745605469, 8.84029846191406, 10.1157096862793, 9.88607330322266,
    9.32783508300781, 9.36255416870117, 10.1161201477051, 11.8296203613281,
    12.8728881835937, 13.2580642700195, 13.5822448730469, 14.2079498291016,
    8.7088752746582, 8.82841796875, 9.62056427001953, 9.44509429931641,
    8.63022689819336, 10.438533782959, 10.7936264038086, 11.1668098449707,
    11.4698097229004, 11.6895088195801, 10.657413482666, 10.6490295410156,
    10.6090156555176, 10.7308578491211, 10.2125785827637, 8.9413688659668,
    8.8182373046875, 8.83381042480469, 8.8937255859375, 8.81535415649414,
    9.55851669311523, 9.21836166381836, 9.18197784423828, 9.25029678344726,
    9.27070083618164, 8.93240661621094, 8.90249099731445, 9.04313659667969,
    9.20108184814453, 9.35103607177734, 10.5618942260742, 11.06572265625,
    11.445832824707, 11.9180442810059, 11.9453758239746, 12.2584243774414,
    11.9192649841309, 11.7775825500488, 11.8008255004883, 12.2185432434082,
    9.08272094726562, 9.66560821533203, 9.48288192749023, 9.70498886108398,
    9.56975555419922, 10.349006652832, 10.0300796508789, 9.5968864440918,
    9.54965896606445, 9.00812759399414, 10.6454582214355, 10.7713653564453,
    11.4645782470703, 11.8325187683105, 10.4740211486816, 9.41022796630859,
    9.07474822998047, 8.61860656738281, 8.40045318603516, 8.653662109375,
    9.65197830200195, 9.63723449707031, 9.51137924194336, 9.57775497436523,
    9.69926528930664, 8.98936157226563, 9.40332794189453, 9.6757568359375,
    9.79740600585938, 9.78034057617188, 10.2542152404785, 10.1619010925293,
    10.3302688598633, 10.5525291442871, 10.7628135681152, 10.2399101257324,
    10.7667839050293, 10.9936302185059, 10.8458152770996, 10.6235733032227,
    9.24678955078125, 9.91125411987305, 9.86469879150391, 10.2658912658691,
    10.1045028686523, 8.5959098815918, 8.49214401245117, 8.39304656982422,
    8.6228157043457, 8.61747360229492, 8.91071395874024, 8.69116439819336,
    8.56472625732422, 8.52434997558594, 8.64141616821289, 11.7017639160156,
    12.3285125732422, 12.0996276855469, 11.056103515625, 10.7624618530273,
    11.0327911376953, 12.0061622619629, 11.4006072998047, 10.8051193237305,
    9.97594757080078, 10.138427734375, 10.6871589660645, 11.5516906738281,
    12.4771171569824, 12.7644668579102, 9.02487182617188, 8.8429817199707,
    9.50254135131836, 9.22763977050781, 8.60505981445312, 9.68806610107422,
    9.77085647583008, 9.95944061279297, 10.3024574279785, 10.7512054443359,
    8.78317031860352, 8.94360504150391, 9.19855346679688, 9.44350967407227,
    10.2734016418457, 11.8314613342285, 12.4076805114746, 12.5829055786133,
    12.3372856140137, 11.6992652893066, 8.82733459472656, 8.83338012695313,
    9.01612014770508, 9.31243057250976, 9.52871017456055, 9.1939811706543,
    9.20086669921875, 9.17466049194336, 9.3692512512207, 9.51042022705078,
    9.55322723388672, 9.08766632080078, 9.01230697631836, 9.08840942382812,
    8.89073867797851, 10.0157516479492, 9.88614654541016, 9.88927917480469,
    9.89448471069336, 9.81435546875, 10.0982810974121, 10.8838890075684,
    12.3737106323242, 12.0203163146973, 12.3476577758789, 8.12273559570312,
    8.38578720092773, 8.5104736328125, 8.67580947875977, 8.8884521484375,
    11.280297088623, 9.81758041381836, 9.12517623901367, 9.57337417602539,
    9.93379745483398, 9.97190170288086, 9.9986442565918, 10.1007339477539,
    10.368416595459, 10.8695823669434, 10.6418167114258, 10.1072540283203,
    9.56202163696289, 10.1464050292969, 11.0315299987793, 15.5208480834961,
    16.458154296875, 16.6033325195312, 16.9603851318359, 17.5446258544922,
    11.6627197265625, 11.2967132568359, 11.0439735412598, 10.7337928771973,
    10.724112701416, 10.414665222168, 10.1816375732422, 10.0053001403809,
    10.0604530334473, 10.3831871032715, 12.5386772155762, 12.61123046875,
    11.556861114502, 10.815104675293, 10.3798713684082, 12.8164276123047,
    12.5301361083984, 12.1416007995605, 11.1006622314453, 10.5525985717773,
    12.7033218383789, 13.5069030761719, 14.3273956298828, 14.1952850341797,
    13.8862731933594, 11.5364295959473, 11.4725784301758, 11.4327659606934,
    11.6338516235352, 11.9929733276367, 10.9388458251953, 10.3944259643555,
    10.7864356994629, 10.4639877319336, 10.4192794799805, 10.584090423584,
    11.0457565307617, 11.1049293518066, 11.2156471252441, 11.2940994262695,
    11.5789703369141, 11.3852058410645, 11.312281036377, 10.8983863830566,
    10.7498306274414, 11.648999786377, 12.1443000793457, 12.3075752258301,
    12.4243774414062, 12.5793846130371, 9.53582992553711, 10.3421630859375,
    10.6005973815918, 10.7018409729004, 10.1489151000977, 15.3236968994141,
    16.6732727050781, 17.0259368896484, 16.9183380126953, 18.6379180908203,
    11.5663963317871, 13.1421661376953, 15.772624206543, 15.2286743164063,
    14.1305938720703, 10.4395881652832, 10.3302070617676, 10.3431907653809,
    10.6234725952148, 10.6850440979004, 10.1355682373047, 10.7770133972168,
    11.2220344543457, 11.121208190918, 10.9759727478027, 10.4280487060547,
    11.4163436889648, 11.5880157470703, 11.367276763916, 11.7584564208984,
    12.3622993469238, 12.8618209838867, 13.0096267700195, 12.7293991088867,
    12.3698738098145, 13.4502487182617, 13.9361175537109, 14.3981384277344,
    14.8455154418945, 14.7898071289063, 10.8285942077637, 11.0353393554688,
    13.0554183959961, 11.4933654785156, 10.6509674072266, 12.3171768188477,
    11.9701278686523, 11.7984405517578, 11.3652336120605, 11.2212104797363,
    11.7747032165527, 12.0631629943848, 11.609635925293, 12.5300575256348,
    12.5889640808105, 14.9442291259766, 15.244026184082, 15.1138778686523,
    14.8327117919922, 14.0672607421875, 13.8624649047852, 14.0361633300781,
    13.746142578125, 13.3890182495117, 12.7229309082031, 11.7338531494141,
    12.4392601013184, 12.6126739501953, 12.3359680175781, 12.0300300598145,
    13.0475494384766, 13.4870010375977, 13.1330673217773, 12.8889770507812,
    11.5218353271484, 12.9545684814453, 12.6848930358887, 12.5185249328613,
    12.1927146911621, 12.1243927001953, 13.6282653808594, 13.0329132080078,
    14.021321105957, 12.7892906188965, 11.5679710388184, 12.4451988220215,
    12.6035362243652, 12.8059692382812, 13.2598541259766, 14.1865646362305,
    11.4154563903809, 12.0055801391602, 12.315015411377, 12.8833023071289,
    13.0320266723633, 11.3923133850098, 12.2035797119141, 12.3115371704102,
    12.4416717529297, 12.8906295776367, 11.4880004882812, 11.4702560424805,
    11.063402557373, 11.520093536377, 11.4941116333008, 10.2884147644043,
    10.4248268127441, 10.2943084716797, 10.4938522338867, 10.171199798584,
    10.8181655883789, 10.7096382141113, 10.3980682373047, 9.85380783081055,
    9.06302337646484, 11.087833404541, 11.297770690918, 11.4384208679199,
    11.8333045959473, 12.6423866271973, 11.0677742004395, 11.1663566589355,
    14.6535186767578, 12.696688079834, 11.9809646606445, 12.5395179748535,
    13.5047088623047, 13.6589874267578, 13.3168762207031, 13.8064010620117,
    13.2664398193359, 12.1466331481934, 11.7755020141602, 11.2214569091797,
    11.967204284668, 13.3286544799805, 13.0230804443359, 12.4111663818359,
    11.5664184570313, 11.507154083252, 10.7482841491699, 10.2523262023926,
    10.5137763977051, 10.6416915893555, 10.925708770752, 12.1461143493652,
    12.5572776794434, 13.0962661743164, 14.0371612548828, 15.6014785766602,
    12.1392105102539, 12.4931434631348, 12.5056259155273, 12.1932655334473,
    12.1573226928711, 12.3337669372559, 12.2943237304688, 12.3938110351563,
    12.3535987854004, 12.2837997436523, 11.199015045166, 11.0299026489258,
    11.4233680725098, 11.3639068603516, 10.776929473877, 15.9578018188477,
    18.5940185546875, 16.6747985839844, 12.2459892272949, 11.7588233947754,
    10.8550109863281, 9.30074844360352, 9.1522102355957, 9.23973083496094,
    9.94997406005859, 21.4329086303711, 20.6476043701172, 20.4366928100586,
    19.5227752685547, 18.6518371582031, 13.4605987548828, 13.7962448120117,
    14.7393859863281, 14.0098480224609, 13.7022705078125, 13.8268768310547,
    13.9131362915039, 14.1420150756836, 14.5985153198242, 15.3337585449219,
    10.2976509094238, 10.6874450683594, 10.6152442932129, 10.3048629760742,
    10.0026962280273, 10.8500930786133, 12.313077545166, 12.8156112670898,
    12.4003845214844, 12.062833404541, 11.8806510925293, 11.9595237731934,
    12.7401191711426, 13.2080368041992, 12.648217010498, 14.9934814453125,
    16.2576446533203, 16.2247314453125, 15.6419891357422, 14.6681213378906,
    10.2608001708984, 10.204532623291, 10.8466209411621, 10.8580635070801,
    10.5870002746582, 12.5249855041504, 13.235661315918, 13.3415161132812,
    13.2680938720703, 13.6001312255859, 10.9847831726074, 10.9526977539062,
    12.1701835632324, 10.9867134094238, 9.62559356689453, 14.671305847168,
    15.7670822143555, 16.5200897216797, 17.2838760375977, 18.5971923828125,
    12.4218063354492, 11.5890487670898, 11.3723731994629, 11.5280731201172,
    12.0742370605469, 11.0745147705078, 10.6635795593262, 10.507258605957,
    10.358984375, 10.2047622680664, 11.231372833252, 11.1456260681152,
    10.8480117797852, 10.3289199829102, 9.81418380737305, 13.1054672241211,
    13.3634078979492, 13.6211837768555, 14.0335067749023, 13.8940582275391,
    11.4586517333984, 11.3107444763184, 12.1839057922363, 11.6442543029785,
    10.0313461303711, 11.5685440063477, 13.461506652832, 13.9238220214844,
    12.9616546630859, 12.0961059570313, 15.3089569091797, 14.529133605957,
    12.9434677124023, 11.6556198120117, 10.7868843078613, 13.7810775756836,
    14.6285568237305, 14.3505905151367, 12.6306495666504, 11.0644081115723,
    13.6406951904297, 13.0658325195313, 11.6025444030762, 10.8227111816406,
    10.6873641967773, 14.1373397827148, 15.3703903198242, 16.4337646484375,
    16.3727081298828, 16.0835571289062, 9.32263946533203, 9.81831588745117,
    10.2201850891113, 10.4734298706055, 10.432006072998, 9.83030319213867,
    9.97000503540039, 10.0799949645996, 10.1364440917969, 10.2572006225586, 
    ...
     .Dim = c(10L, 140L), .Dimnames = list(NULL,
    c("layer.1", "layer.2", "layer.3", "layer.4", "layer.5",
    "layer.6", "layer.7", "layer.8", "layer.9", "layer.10", "layer.11",
    "layer.12", "layer.13", "layer.14", "layer.15", "layer.16",
    "layer.17", "layer.18", "layer.19", "layer.20", "layer.21",
    "layer.22", "layer.23", "layer.24", "layer.25", "layer.26",
    "layer.27", "layer.28", "layer.29", "layer.30", "layer.31",
    "layer.32", "layer.33", "layer.34", "layer.35", "layer.36",
    "layer.37", "layer.38", "layer.39", "layer.40", "layer.41",
    "layer.42", "layer.43", "layer.44", "layer.45", "layer.46",
    "layer.47", "layer.48", "layer.49", "layer.50", "layer.51",
    "layer.52", "layer.53", "layer.54", "layer.55", "layer.56",
    "layer.57", "layer.58", "layer.59", "layer.60", "layer.61",
    "layer.62", "layer.63", "layer.64", "layer.65", "layer.66",
    "layer.67", "layer.68", "layer.69", "layer.70", "layer.71",
    "layer.72", "layer.73", "layer.74", "layer.75", "layer.76",
    "layer.77", "layer.78", "layer.79", "layer.80", "layer.81",
    "layer.82", "layer.83", "layer.84", "layer.85", "layer.86",
    "layer.87", "layer.88", "layer.89", "layer.90", "layer.91",
    "layer.92", "layer.93", "layer.94", "layer.95", "layer.96",
    "layer.97", "layer.98", "layer.99", "layer.100", "layer.101",
    "layer.102", "layer.103", "layer.104", "layer.105", "layer.106",
    "layer.107", "layer.108", "layer.109", "layer.110", "layer.111",
    "layer.112", "layer.113", "layer.114", "layer.115", "layer.116",
    "layer.117", "layer.118", "layer.119", "layer.120", "layer.121",
    "layer.122", "layer.123", "layer.124", "layer.125", "layer.126",
    "layer.127", "layer.128", "layer.129", "layer.130", "layer.131",
    "layer.132", "layer.133", "layer.134", "layer.135", "layer.136",
    "layer.137", "layer.138", "layer.139", "layer.140")))
For the x-axis, I already have 140 values to be plotted. The x variable is called "RCP1pctCO2cumulative" and is 1-dimensional. Here are the values:
>dput(RCP1pctCO2cumulative)
    c(0, 0.00697490638121963, 0.0139075990766287, 0.021697436273098,
    0.0302329704165459, 0.0389980841428041, 0.0486239280551672,
    0.0591636016964912, 0.0698652867227793, 0.0806971430778503, 0.0917696304619312,
    0.102874741703272, 0.115288959443569, 0.127942492067814, 0.140930585563183, 0.154951927065849,
    0.169483987987041, 0.18332038372755, 0.197460225224495, 0.211912712454796,
    0.227608525753021, 0.243575794994831, 0.257900005578995, 0.273098181188107,
    0.288984017074108, 0.305822652578354, 0.321933174133301, 0.338437202572823,
    0.356079193949699, 0.373604437708855, 0.389580103754997, 0.406976979970932,
    0.423514771461487, 0.440741804242134, 0.459019854664803, 0.477243804931641,
    0.494844323396683, 0.511731442809105, 0.529583910107613, 0.54879242181778,
    0.568029862642288, 0.587030050158501, 0.606201952695847, 0.626413214206696,
    0.645859175920486, 0.66550235748291, 0.685490393638611, 0.705517685413361,
    0.725719237327576, 0.74520371556282, 0.764879602193832, 0.78538470864296,
    0.806885379552841, 0.827258145809174, 0.847640424966812, 0.869502395391464,
    0.891108268499374, 0.912525850534439, 0.934271132946014, 0.956432664394379,
    0.977902102470398, 0.999574398994446, 1.02313443422317, 1.0449088037014,
    1.06765602231026, 1.09229186177254, 1.11614397168159, 1.13850414156914,
    1.16062269210815, 1.18386173844337, 1.2078672170639, 1.23217906951904,
    1.25505521297455, 1.27949770689011, 1.30394254922867, 1.32788743972778,
    1.35124933719635, 1.37474408149719, 1.39838930368423, 1.42129179239273,
    1.44566521644592, 1.47075144052506, 1.49397988319397, 1.51616193056107,
    1.54051134586334, 1.56606665849686, 1.59053231477737, 1.61592463254929,
    1.64096541404724, 1.66613935232162, 1.69049085378647, 1.71510955095291,
    1.73991868495941, 1.76491104364395, 1.79114699363708, 1.81589571237564,
    1.84101955890656, 1.864857172966, 1.8899533867836, 1.91575677394867,
    1.9422261595726, 1.96840007305145, 1.99298502206802, 2.01899757385254,
    2.04547454118729, 2.07122528553009, 2.09852977991104, 2.12717348337173,
    2.15352830886841, 2.17984690666199, 2.20684263706207, 2.23266286849976,
    2.25915194749832, 2.28647100925446, 2.31463184356689, 2.34280925989151,
    2.36965861320496, 2.39779574871063, 2.42558825016022, 2.45266799926758,
    2.48168079853058, 2.50962221622467, 2.53702754974365, 2.56574511528015,
    2.59377150535583, 2.62192821502686, 2.6505597114563, 2.68051118850708,
    2.70983340740204, 2.73927145004272, 2.76805067062378, 2.79780313968658,
    2.8272668838501, 2.85747616291046, 2.88714888095856, 2.91689431667328,
    2.94743349552155, 2.97868416309357, 3.00965495109558, 3.03861720561981
I tried doing something like this to start:
>expansion <- expand.grid(103:116, 3:16) #to specify a range of longitudes  and latitudes
    >lonlat <- extract(RCP1pctCO2Mean, expansion)   >plot(RCP1pctCO2cumulative, lonlat, type="l",col="green", lwd="3", 
    xlab="Cumulative emissions (TtC)", ylab="One-day maximum precipitation 
    (mm/day)", main="Test model")
 
But this yields the error:
    Error in xy.coords(x, y, xlabel, ylabel, log) :
    'x' and 'y' lengths differ
If it helps, here are the dimensions of the new variables created:
   
>dim(lonlat)
    [1] 196   140
   
>dim(expansion)
   
    [1] 196   2

What could I be doing wrong (the lengths appear to be the same)? Ultimately, the goal would be to plot the 140 values as a function of emissions (i.e. "RCP1pctCO2Mean" as a function of "RCP1pctCO2cumulative" once each of those selected grid cells are aggregated). The above works absolutely fine when just selecting "one" specific grid cell, but not an aggregate of grid cells. Is this possible to do for an aggregate of grid cells?
Thanks, and any assistance would be greatly appreciated!
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

masking_data

Tue, 04/23/2019 - 02:41
Dear R users,
Could anyone please let me know how to mask the data over only Indian
region.

my code is


august_temp <-ReadNetCDF("/Users/kunalbali/Desktop/test/soma/india.nc")
str(august_temp)

shapeindia <-
readOGR(dsn="/Users/kunalbali/Desktop/india/",layer="india_state")
shapefile_df <- fortify(shapeindia)

ggplot(august_temp[time == time[1]], aes(lon, lat)) +
  geom_contour_fill(aes(z = olr)) + scale_fill_distiller(palette =
"OrRd",trans = "reverse") +
  geom_path(data = shapefile_df,
            aes(x = long, y = lat, group = group),
            color = 'black', size = .5) +
  metR:::theme_field()


---
Kunal Bali

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

using cokriging for probability kriging

Mon, 04/22/2019 - 10:38
Hello everyone!

I found an interesting technical note by David Rossiter about doing
cokriging in R.

Would this be the same as probability kriging if the target variable is an
indicator variable and the cokriging variable is the rank order/n, please?

Thanks for your help,
Sincerely,
Erin

Erin Hodgess, PhD
mailto: [hidden email]

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Measures of dispersion and statistical significance of the impacts of a panel Spatial Durbin model (SDM)

Sun, 04/21/2019 - 12:22
On Fri, 19 Apr 2019, Alain N'Ghauran wrote:

> Hello, group
>
> I ran a panel Spatial Durbin model (SDM) and computed the summary measures of
> impacts (direct, indirect and total). Now, I would like to get measures of
> dispersion for the impacts estimates as well as the statistical significance
> of the impacts.
>
> How can I get such measures ?
>
> Here is a reproducible example:
>
> ################################################################################
> ################################################################################
> set.seed(1234)
> library(plm)
> library(splm)
> data(Produc, package = "plm")
> data(usaww)
>
> # Create spatially lagged independent variables WX using slag()
> Produc2 <- pdata.frame(Produc, index = c("state", "year"))
> Produc2$pcap_SL <- slag(log(Produc2$pcap), mat2listw(usaww))
> Produc2$pc_SL <- slag(log(Produc2$pc), mat2listw(usaww))
> Produc2$emp_SL <- slag(log(Produc2$emp), mat2listw(usaww))
> Produc2$unemp_SL <- slag(log(Produc2$unemp), mat2listw(usaww))
> # Define formula
> fm <- log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp +
>         pcap_SL + pc_SL + emp_SL + unemp_SL
> # Spatial Durbin Model : Y = ρ.WY + β.X + θ.WX + μ
> summary(
>         sdm <- spml(fm, data = Produc2, index = c("dep", "period"),
>                     model = "within", effect = "twoways", lag = TRUE,
>                     listw = mat2listw(usaww), spatial.error = "none",
>                     LeeYu = TRUE, Hess = FALSE)
>         )
>
> ## Compute impact measures of variable pcap (thanks to Prof Bivand)
> #  Impacts are computed using equation (25) in LeSage (2008)
> #  LeSage (2008) is available at
> https://journals.openedition.org/rei/pdf/3887
> # Note that I cannot use impacts.splm() since the current development of splm
> doesn’t allow impacts on SDM
>
> Time <- length(unique(Produc$year))
> N <- length(unique(Produc$state))
> library(Matrix)
> s.lws <- kronecker(Diagonal(Time) , listw2dgCMatrix(mat2listw(usaww)))
> IrW <- Diagonal(N * Time) - sdm$spat.coef * s.lws
> IrWi <- solve(IrW)
> S_pcap <- IrWi * (Diagonal(N * Time) * sdm$coefficients[2] +
>                           s.lws * sdm$coefficients[6])
> # direct impact
> dir_imp <- mean(diag(S_pcap))
> # total impact
> tot_imp <- mean(rowSums(S_pcap)) # or sum(S_pcap)/816
> # indirect impact : total impact - direct impact
> indir_imp <- tot_imp - dir_imp
>
> # LeSage (2008) provides guidance for drawing inference regarding the
> significance
> # of these impacts (section 4.2, page 35) but I'm struggling to implement it
> in R.
>
> # Could you help me deal with this ? I think that during the next few years, someone may implement this, but it
is far from simple. If you have the time and energy, you'd need to set up
input for spatialreg::intImpacts(), which would then sample from the
fitted model and calculate the impacts on those samples to give an
inferential basis. It will be easier to add a Durbin= argument to splm
fitting functions, but this needs to wait until spatialreg exposes a
single portable function handling the argument. For the present time, your
only option is S_r(W) and no inference. Consider making an issue in
spatialreg on github with regard to a Durbin= argument handling function,
but I do not anticipate being able to do that this year without
contributions from others.

Roger

>
> ################################################################################
> ################################################################################
>
> Thanks,
>
> Alain
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
> --
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway

Re: Selecting a range of longitude and latitudes

Sun, 04/21/2019 - 09:31
Hi Tom (and everyone),

Ah, yes, that is what I wanted to consider in terms of selecting grid cells! :) But let's say that I wanted to aggregate each of the values of these grid cells and plot this as a function x-axis values. The values already computed for each grid cell for the y-axis correspond to average precipitation and consist of 140 values per grid cell. The variable containing these y-axis values is called "RCP1pctCO2Mean", which is 3-dimensional and has the following attributes:
class       : RasterBrick
dimensions  : 64, 128, 8192, 140  (nrow, ncol, ncell, nlayers)
resolution  : 2.8125, 2.789327  (x, y)
extent      : -181.4062, 178.5938, -89.25846, 89.25846  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0
data source : in memory
names       :   layer.1,   layer.2,   layer.3,   layer.4,   layer.5,   layer.6,   layer.7,   layer.8,   layer.9,  layer.10,  layer.11,  layer.12,  layer.13,  layer.14,  layer.15, ...
min values  : 0.5261063, 0.5625295, 0.5301681, 0.6019284, 0.5177065, 0.6775601, 0.5336965, 0.5213086, 0.5971723, 0.5305891, 0.5514522, 0.5481200, 0.4681806, 0.5437223, 0.5988844, ...
max values  : 113.13776, 114.50780,  94.93643, 100.35409, 102.65459, 101.80622, 104.95480,  99.17839, 104.68667, 119.48342, 100.60391, 108.91896, 104.38969,  99.35735,  99.30752, ...

For the x-axis, I already have 140 values to be plotted. The x variable is called "RCP1pctCO2cumulative". 
I tried doing something like this to start:
>expansion <- expand.grid(103:116, 3:16)>lonlat <- extract(RCP1pctCO2Mean, expansion)
>plot(RCP1pctCO2cumulative,lonlat, type="l",col="green", lwd="3", xlab="Cumulative emissions (TtC)", ylab="One-day maximum precipitation (mm/day)", main="Test model") But this yields the error:
Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ>dim(lonlat)
[1] 196   140>dim(expansion)[1] 196   2
What could I be doing wrong (the lengths appear to be the same)? Ultimately, the goal would be to plot the 140 values as a function of cumulative emissions (i.e. "RCP1pctCO2Mean" as a function of "RCP1pctCO2cumulative" once each of those selected grid cells are aggregated. This works absolutely fine when just selecting "one" specific grid cell. Is this possible to do for an aggregate of grid cells?
Thanks, again! 
-----Original Message-----
From: Tom Philippi <[hidden email]>
To: rain1290 <[hidden email]>
Cc: btupper <[hidden email]>; r-sig-geo <[hidden email]>
Sent: Sun, Apr 21, 2019 12:17 am
Subject: Re: [R-sig-Geo] Selecting a range of longitude and latitudes

Trav--Are you trying to specify a grid of each of those lon values by each of those lat values?  cbind() is matching the first lon with the first lat, the second with the second, generating a diagonal of locations.  [That's also why there have to be as many lats as lons.]  To fill out the grid of each lon with each lat, look at expand.grid(103:116, 3:16)
Tom
On Thu, Apr 18, 2019 at 6:51 PM rain1290--- via R-sig-Geo <[hidden email]> wrote:

Hi Ben (and everyone),

Ah, yes, you're right - using the suggestion that you specified, that error message disappeared! So, if I understand, this would take all of the grid cells within those specified longitude and latitude ranges (i.e. that entire area)? 
That said, when I try plotting this using the following:
get <- ncvar_get(Model1, "cum_co2_emi-CanESM2")   #for x-axis (140 values)
Model2 <- brick("MaxPrecCCCMACanESM21pctCO2.nc", var="onedaymax")    #for y-axis (140 values)

Hope2 <- extract(Model2, lonlat)

plot(get,Hope2, type="l",col="green", lwd="3", xlab="Cumulative emissions (TtC)", ylab="One-day maximum precipitation (mm/day)", main="CanESM2")
I receive this error:
Error in xy.coords(x, y, xlabel, ylabel, log) :
  'x' and 'y' lengths differ
*Note that I do not have this problem when specifying a "specific" longitude and latitude, rather than a range. Is there any reason for this?
Thanks, again
-----Original Message-----
From: Ben Tupper <[hidden email]>
To: rain1290 <[hidden email]>
Cc: r-sig-geo <[hidden email]>
Sent: Thu, Apr 18, 2019 9:26 pm
Subject: Re: [R-sig-Geo] Selecting a range of longitude and latitudes

Hi,
The example you give is different than the one listed in the error message.  In your example you bind two 14-element vectors into a matrix of two columns.
cbind(103:116, 3:16)
But in the error you show the first vector is only 8 elements long...
cbind(103:110, 3:16)
When R encounters an attempt to bind columns of unequal length it will try to "recycle" the shorter vector as long as it is a multiple of the longer. In this case of binding an 8-element vector and a 14-element vector it fails.  
Note that shortening up the first vector to 7 does work since 7 is a multiple of 14...
cbind(103:109, 3:16)      [,1] [,2] [1,]  103    3 [2,]  104    4 [3,]  105    5 [4,]  106    6 [5,]  107    7 [6,]  108    8 [7,]  109    9 [8,]  103   10 [9,]  104   11[10,]  105   12[11,]  106   13[12,]  107   14[13,]  108   15[14,]  109   16

Note how the sequence 103...109 appears twice in the first column.  Recycling is nice (and handy) until you get surprised by it.
Cheers,Ben

On Apr 18, 2019, at 8:37 PM, rain1290--- via R-sig-Geo <[hidden email]> wrote:
Hi there,
I am trying to specify a range of longitudes and latitudes. I tried this using the following:


lonlat <- cbind(103:116, 3:16)  #This would specify a range of longitudes and latitudes

However, I receive the following warning message:
Warning message:
In cbind(103:110, 3:16) :
  number of rows of result is not a multiple of vector length (arg 1)

When I specify the longitude and latitude of a specific location, though, it works just fine, like this:
lonlat <- cbind(103, 3)

Am I specifying the ranges of coordinates incorrectly? The warning message would suggest yes, but I do not understand why.
Thanks, and any help with this would be greatly appreciated!
~Trav.~
 [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


Ben Tupper
Bigelow Laboratory for Ocean Sciences
60 Bigelow Drive, P.O. Box 380
East Boothbay, Maine 04544
http://www.bigelow.org
Ecological Forecasting: https://eco.bigelow.org/





        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo


        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Selecting a range of longitude and latitudes

Sat, 04/20/2019 - 23:17
Trav--
Are you trying to specify a grid of each of those lon values by each of
those lat values?  cbind() is matching the first lon with the first lat,
the second with the second, generating a diagonal of locations.  [That's
also why there have to be as many lats as lons.]  To fill out the grid of
each lon with each lat, look at expand.grid(103:116, 3:16)

Tom

On Thu, Apr 18, 2019 at 6:51 PM rain1290--- via R-sig-Geo <
[hidden email]> wrote:

> Hi Ben (and everyone),
>
> Ah, yes, you're right - using the suggestion that you specified, that
> error message disappeared! So, if I understand, this would take all of the
> grid cells within those specified longitude and latitude ranges (i.e. that
> entire area)?
> That said, when I try plotting this using the following:
> get <- ncvar_get(Model1, "cum_co2_emi-CanESM2")   #for x-axis (140 values)
> Model2 <- brick("MaxPrecCCCMACanESM21pctCO2.nc", var="onedaymax")    #for
> y-axis (140 values)
>
> Hope2 <- extract(Model2, lonlat)
>
> plot(get,Hope2, type="l",col="green", lwd="3", xlab="Cumulative emissions
> (TtC)", ylab="One-day maximum precipitation (mm/day)", main="CanESM2")
> I receive this error:
> Error in xy.coords(x, y, xlabel, ylabel, log) :
>   'x' and 'y' lengths differ
> *Note that I do not have this problem when specifying a "specific"
> longitude and latitude, rather than a range. Is there any reason for this?
> Thanks, again
> -----Original Message-----
> From: Ben Tupper <[hidden email]>
> To: rain1290 <[hidden email]>
> Cc: r-sig-geo <[hidden email]>
> Sent: Thu, Apr 18, 2019 9:26 pm
> Subject: Re: [R-sig-Geo] Selecting a range of longitude and latitudes
>
> Hi,
> The example you give is different than the one listed in the error
> message.  In your example you bind two 14-element vectors into a matrix of
> two columns.
> cbind(103:116, 3:16)
> But in the error you show the first vector is only 8 elements long...
> cbind(103:110, 3:16)
> When R encounters an attempt to bind columns of unequal length it will try
> to "recycle" the shorter vector as long as it is a multiple of the longer.
> In this case of binding an 8-element vector and a 14-element vector it
> fails.
> Note that shortening up the first vector to 7 does work since 7 is a
> multiple of 14...
> cbind(103:109, 3:16)      [,1] [,2] [1,]  103    3 [2,]  104    4 [3,]
>  105    5 [4,]  106    6 [5,]  107    7 [6,]  108    8 [7,]  109    9 [8,]
>  103   10 [9,]  104   11[10,]  105   12[11,]  106   13[12,]  107   14[13,]
>  108   15[14,]  109   16
>
> Note how the sequence 103...109 appears twice in the first column.
> Recycling is nice (and handy) until you get surprised by it.
> Cheers,Ben
>
> On Apr 18, 2019, at 8:37 PM, rain1290--- via R-sig-Geo <
> [hidden email]> wrote:
> Hi there,
> I am trying to specify a range of longitudes and latitudes. I tried this
> using the following:
>
>
> lonlat <- cbind(103:116, 3:16)  #This would specify a range of longitudes
> and latitudes
>
> However, I receive the following warning message:
> Warning message:
> In cbind(103:110, 3:16) :
>   number of rows of result is not a multiple of vector length (arg 1)
>
> When I specify the longitude and latitude of a specific location, though,
> it works just fine, like this:
> lonlat <- cbind(103, 3)
>
> Am I specifying the ranges of coordinates incorrectly? The warning message
> would suggest yes, but I do not understand why.
> Thanks, and any help with this would be greatly appreciated!
> ~Trav.~
>  [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
> Ecological Forecasting: https://eco.bigelow.org/
>
>
>
>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Re: Selecting a range of longitude and latitudes

Fri, 04/19/2019 - 18:24
Hi Mike (and everyone),

Thanks for this reply! 
Let's say that I wanted to average the values of every grid cell within, say, 103 to 116 degrees longitude and 5 to 16 degrees latitude. Would there be a way to select all of those grid cells to average them? I've done something like this to already compute the averages across all grid cells based on values :
RCP1pctCO2ModelMean <- (Model2 + Model10 + Model18 + Model26 + subset14 + Model42 + subset20 + subset24 + Model60 + Model68) / 10   ###This provides an average value across each of the 140 layers for each of the 8192 grid cells based on these 10 models (i.e. all of the layer 1s are averaged for each model for the first grid cell, then all of the layer 2s are averaged for the first grid cell.....all the way to layer 140. Then, this is repeated for the second grid cell....all the way to grid cell 8192). This way, I have 140 averages across all grid cells. :)
So, to average values ONLY across a selected range of grid cells, is there a way to do that? 
Thanks, again,


-----Original Message-----
From: Michael Sumner <[hidden email]>
To: rain1290 <[hidden email]>
Sent: Fri, Apr 19, 2019 6:36 pm
Subject: Re: [R-sig-Geo] Selecting a range of longitude and latitudes

You want expand.grid(get, Hope2) to get every coordinate, but

coordinates(Model2)  ## gives a matrix (topleft, across rows, then
down same as values(Model2))

is far easier, albeit having been through layers of interpretation of
the original arrays in the file.

All the best, Mike


On Fri, Apr 19, 2019 at 11:51 AM rain1290--- via R-sig-Geo
<[hidden email]> wrote:
>
> Hi Ben (and everyone),
>
> Ah, yes, you're right - using the suggestion that you specified, that error message disappeared! So, if I understand, this would take all of the grid cells within those specified longitude and latitude ranges (i.e. that entire area)?
> That said, when I try plotting this using the following:
> get <- ncvar_get(Model1, "cum_co2_emi-CanESM2")  #for x-axis (140 values)
> Model2 <- brick("MaxPrecCCCMACanESM21pctCO2.nc", var="onedaymax")    #for y-axis (140 values)
>
> Hope2 <- extract(Model2, lonlat)
>
> plot(get,Hope2, type="l",col="green", lwd="3", xlab="Cumulative emissions (TtC)", ylab="One-day maximum precipitation (mm/day)", main="CanESM2")
> I receive this error:
> Error in xy.coords(x, y, xlabel, ylabel, log) :
>  'x' and 'y' lengths differ
> *Note that I do not have this problem when specifying a "specific" longitude and latitude, rather than a range. Is there any reason for this?
> Thanks, again
> -----Original Message-----
> From: Ben Tupper <[hidden email]>
> To: rain1290 <[hidden email]>
> Cc: r-sig-geo <[hidden email]>
> Sent: Thu, Apr 18, 2019 9:26 pm
> Subject: Re: [R-sig-Geo] Selecting a range of longitude and latitudes
>
> Hi,
> The example you give is different than the one listed in the error message.  In your example you bind two 14-element vectors into a matrix of two columns.
> cbind(103:116, 3:16)
> But in the error you show the first vector is only 8 elements long...
> cbind(103:110, 3:16)
> When R encounters an attempt to bind columns of unequal length it will try to "recycle" the shorter vector as long as it is a multiple of the longer. In this case of binding an 8-element vector and a 14-element vector it fails.
> Note that shortening up the first vector to 7 does work since 7 is a multiple of 14...
> cbind(103:109, 3:16)      [,1] [,2] [1,]  103    3 [2,]  104    4 [3,]  105    5 [4,]  106    6 [5,]  107    7 [6,]  108    8 [7,]  109    9 [8,]  103  10 [9,]  104  11[10,]  105  12[11,]  106  13[12,]  107  14[13,]  108  15[14,]  109  16
>
> Note how the sequence 103...109 appears twice in the first column.  Recycling is nice (and handy) until you get surprised by it.
> Cheers,Ben
>
> On Apr 18, 2019, at 8:37 PM, rain1290--- via R-sig-Geo <[hidden email]> wrote:
> Hi there,
> I am trying to specify a range of longitudes and latitudes. I tried this using the following:
>
>
> lonlat <- cbind(103:116, 3:16)  #This would specify a range of longitudes and latitudes
>
> However, I receive the following warning message:
> Warning message:
> In cbind(103:110, 3:16) :
>  number of rows of result is not a multiple of vector length (arg 1)
>
> When I specify the longitude and latitude of a specific location, though, it works just fine, like this:
> lonlat <- cbind(103, 3)
>
> Am I specifying the ranges of coordinates incorrectly? The warning message would suggest yes, but I do not understand why.
> Thanks, and any help with this would be greatly appreciated!
> ~Trav.~
>  [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
>
> Ben Tupper
> Bigelow Laboratory for Ocean Sciences
> 60 Bigelow Drive, P.O. Box 380
> East Boothbay, Maine 04544
> http://www.bigelow.org
> Ecological Forecasting: https://eco.bigelow.org/
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


--
Michael Sumner
Software and Database Engineer
Australian Antarctic Division
Hobart, Australia
e-mail: [hidden email]

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Getting averaged variable importance after bootsrapping

Fri, 04/19/2019 - 10:23
Dear All,



I am using a Bootstrapping approach with the Cubist model like the example
below for 3 bootsraps.



library(Cubist)

library(ithir) # install.packages("ithir", repos="
http://R-Forge.R-project.org <http://r-forge.r-project.org/>")

library(caret)



# Point data

data(HV_subsoilpH)



# subset data for modeling

training <- sample(nrow(HV_subsoilpH), 0.7 * nrow(HV_subsoilpH))

cDat <- HV_subsoilpH[training, ]



# Number of bootstraps

nbag <- 3



# Fit cubist models for each bootstrap

for (i in 1:nbag) {

  trainingREP <- sample.int(nrow(cDat), 1.0 * nrow(cDat),replace = TRUE)

  fit_cubist <- cubist(x = cDat[trainingREP, 4:ncol(cDat),

                       y = cDat$pH60_100cm[trainingREP],
cubistControl(rules = 5,

                                       extrapolation = 5), committees = 3)

}



It is possible to get the variable importance (percentages  in variable
usage in the models) after running the models. Because of the random
sampling at each run of the model, the variable importance is different. A
robust estimate may be determined by taking the average of all the
percentages of usage for each specific variable involved in the models.



However using varImp(fit_cubist) only gives variable importance for the
final model.



Is there anyway to extract the variable importance for each model and
arrange them finally to get the final table as presented below? I am
actually running the models 100 times. It is possible to do  it manually by
saving to file each model and then calls  in each model but the workload is
too high when you have 100 number of bootstraps.



 The final table I am expecting should like the table below.


Expected table-----------------------------------------------

*Variables*

*VImp*

*cubist.type*

MRVBF

62.5

Vimp.cubist1

AACN

72.5

Vimp.cubist1

NDVI

41

Vimp.cubist1

MRVBF

81.5

Vimp.cubist2

Elevation

48.5

Vimp.cubist2

NDVI

62.5

Vimp.cubist2

MRVBF

78

Vimp.cubist3

Hillshading

62

Vimp.cubist3

TWI

57

Vimp.cubist3



I will appreciate any help.



Best Regards,

Ozias

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo

Pages