Skip to content
Prev 27339 / 29559 Next

Creating a median curve among multiple curvesin ggplot

Hi Akos (and everyone),
Thank you kindly for this response!
I tried your suggestions, but for the first variable:?
RCP1pctCO2Median <- median(apply(X = cbind(get, IPSL, IPSLMR, IPSL5, 
MIROC, HadGEM, MPI, MPI5, GFDL, GFDL5)), MARGIN = 1, FUN = median)
I receive this error:
Error in match.fun(FUN) : argument "FUN" is missing, with no default
Why would that appear?
Also, for the raster objects for the second variable, yes, what you suggested worked, but this returns only the single median value per grid cell for the 140 years, as opposed to 140 medians (i.e. a median for each year/each layer) for each grid cell. Ideally, I would like to derive 140 medians corresponding to each of the 140 years/layers for each grid cell. Is there a way to do this??
Here is what some of the values/structure look like for the object Model2:
X1       X2        X3        X4       X5       X6        X7        X8        X9       X10       X11
 [1,]  7.395703 6.493830  7.432156  6.767403 11.66004 7.158040 13.968703  8.139962  7.927880 10.367045  8.560315
 [2,]  7.277671 6.318810  8.406366  5.974478 12.51484 7.405914 15.350679  7.977879  8.039850  9.696597  9.374163
 [3,]  6.919258 6.119063  9.485675  6.256432 13.44547 7.542754 10.846225  8.441847  8.155234 10.129576 10.074353
 [4,]  6.633444 6.300559 10.349174  6.733875 14.35567 7.589797 12.452223  8.384633  8.697707 10.025741 10.589373
 [5,]  6.986749 7.057785 11.202586  8.037964 15.08123 7.668468 11.838186  8.506311  8.978721  9.699996 10.256382
 [6,]  7.287383 7.561100 12.091483  8.384658 15.56648 7.662876  8.925544  9.431210  8.979276 10.047477 10.898319
 [7,]  7.957773 7.732338 13.998432  8.982379 15.50928 7.599275  8.548879  8.287948  8.745722  9.496011 10.861937
            X12       X13       X14       X15      X16       X17      X18       X19      X20       X21       X22
 [1,]  5.533977 10.534669 12.136978  8.897428 10.07571  8.485538 7.731084 10.557160 15.36603 12.320665 11.274374
 [2,]  6.010256 10.299062 12.703854  9.522287 11.08078  8.996936 6.919732 10.900610 14.44405 11.949420 11.202058
 [3,]  6.590125  9.553597 12.781633  9.015289 11.35786  9.215069 6.888467  9.571572 13.47964 10.308230  9.772387
 [4,]  7.042177  8.800974 12.292124 11.457335 11.96268  9.329095 7.078347  9.072567 13.90133  9.780438  9.901325
 [5,]  7.613796  9.617242 11.511468 11.527631 12.94864  9.510409 7.504535  8.380163 14.01753  9.804405 10.389509
 [6,]  8.146129  9.211740 11.250921 11.483143 13.93948  8.881543 7.888670  8.917588 13.32526  8.609215  9.584101
 [7,]  8.551682  8.858268 10.417808 11.292067 15.19191  9.224810 8.231571  7.949825 12.58279  8.042569  9.816563
Thanks, once again, and I look forward to your response!
-----Original Message-----
From: Bede-Fazekas ?kos <bfalevlist at gmail.com>
To: r-sig-geo <r-sig-geo at r-project.org>
Sent: Sat, Jun 1, 2019 11:47 am
Subject: Re: [R-sig-Geo] Creating a median curve among multiple curvesin ggplot

Hello,
in case of the vectors, you can get the median of the different models 
for each of the years using apply() function:
RCP1pctCO2Median <- median(apply(X = cbind(get, IPSL, IPSLMR, IPSL5, 
MIROC, HadGEM, MPI, MPI5, GFDL, GFDL5)), MARGIN = 1, FUN = median)
It calculates the median of each of the rows (= years) of the matrix.

In case of rasters, use raster::calc(), if all the rasters are 
single-layer RasterLayer objects:
RCP1pctCO2ModelMedian <- calc(x = stack(Model2, Model10, Model18, 
Model26, subset14, Model42, subset20, subset24, Model60, Model68), fun = 
median)
Since your rasters are multi-layer RasterBrick, you should give more 
details of their stucture/content to let us answer your question.

HTH,
?kos Bede-Fazekas
Hungarian Academy of Sciences

2019.06.01. 17:24 keltez?ssel, rain1290--- via R-sig-Geo ?rta:
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo at r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo