[R] Problems trying to place a global map with Ncdf data plot

2019-02-17 Thread rain1290--- via R-help
Hello there,

I am trying to overlay a global map with ncdf data of precipitation for a
particular location (using specific coordinates). The file is in ncdf format
(commonly used to store away climate data), and I am currently attempting to
place a global map on plotted precipitation values. However, I am having
difficulty placing a global map on this plot and am encountering errors. I
will show you what I have done:

#To create a plot of precipitation data using the following ncdf file - the
following works fine and provides the distributions global precipitation
values (Land+Water values):

library(ncdf4)
Can<-"MaxPrecCCCMACanESM2rcp45.nc"


>Model<-nc_open(Can)
>print(Model)
>attributes(Model$var)
>$names
>dat<-ncvar_get(Model, "onedaymax")
>dat[128,50,1] #View onedaymax for selected latitude, longitude and Year
>nc_lat<-ncvar_get(Model,attributes(Model$dim)$names[2]) #Retrieve latitude
>nc_lon<-ncvar_get(Model,attributes(Model$dim)$names[3]) #Retrieve longitude
>print(paste(dim(nc_lat), "latitudes and", dim(nc_lon), "longitudes"))
>library(maptools)
>map<-dat[,,5] #Precipitation for all longitudes, latitudes, and Year 5
>grid<-expand.grid(nc_lon=nc_lon, nc_lat=nc_lat)
>image(nc_lon,nc_lat,map, ylab="Latitude", xlab="Longitude", main="One-day
maximum precipitation")
>levelplot(map~nc_lon*nc_lat, data=grid, at=cutpoints, cuts=11,
ylab="Latitude", xlab="Longitude", >main="Year 5 one-day maximum
precipitation (mm/day) for CanESM2 under RCP4.5", pretty=T,
col.regions=(rev(brewer.pal(10, "Spectral"

#To place a global map on the map that map that returns using the above
code. *This is where errors begin:

>ggplot()+geom_point(aes(x=nc_lon,y=nc_lat,color="onedaymax"),
size=0.8)+borders("world",
colour="black")+scale_color_viridis(name="onedaymax")+theme_void()+coord_quickmap()
*Error: Aesthetics must be either length 1 or the same as the data (128): x,
y, colour*


Why doesn't this work? Could it be that I am not including the "time"
dimension in the ggplot function? The problem, though, is when I try to
obtain the "time" dimension, like I did for latitude and longitude, I
receive the following error:

t<-ncvar_get(Model,"time")
*Error in nc$dim[[idobj$list_index]] : 
  attempt to select more than one element*

If it helps, this is what the variables and dimensions look like in the ncdf
file:

/File MaxPrecCCCMACanESM2rcp45.nc (NC_FORMAT_NETCDF4):

    3 variables (excluding dimension variables):
        double onedaymax[lon,lat,time]  (Contiguous storage)  
            units: mm/day
        double fivedaymax[lon,lat,time]  (Contiguous storage)  
            units: mm/day
        short Year[time]  (Contiguous storage)  

    3 dimensions:
        time  Size:95
        lat  Size:64
            units: degree North
        lon  Size:128
            units: degree East/

Any help would be greatly appreciated

Thanks,
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Problems trying to make a time series using NetCDF file

2019-03-16 Thread rain1290--- via R-help
Hi there,
I am using climate model data in attempt to create a time series for a specific 
location. Getting longitude and latitude is fine. However, I am receiving the 
following error when using the "ncvar_get" function in trying to derive the 
"time" dimension:
Error in nc$dim[[idobj$list_index]] : 
  attempt to select more than one element in get1index 
What could be causing this?
-This is what I have done so far:
#CanESM2 plotting for specified yearncfname<-"MaxPrecCCCMACanESM2rcp45.nc"
Prec<-raster(ncfname)
print(Prec)
Model<-nc_open(ncfname)longitude<-ncvar_get(Model, "lon") #Works fine
latitude<-ncvar_get(Model, "lat") #Works fine
time<-ncvar_get(Model, "time") #Error in nc$dim[[idobj$list_index]] : attempt 
to select more than one element in get1index 


Here is the structure of the file after using "nc_open":
File MaxPrecCCCMACanESM2rcp45.nc (NC_FORMAT_NETCDF4):

 3 variables (excluding dimension variables):
double onedaymax[lon,lat,time]   (Contiguous storage)  
units: mm/day
double fivedaymax[lon,lat,time]   (Contiguous storage)  
units: mm/day
short Year[time]   (Contiguous storage)  

 3 dimensions:
time  Size:95
lat  Size:64
units: degree North
lon  Size:128
units: degree East
What could be causing this error? 
Thanks in advance, and I look forward to your response!
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Weighted spatial averages across grid cells in NetCDF file

2019-03-18 Thread rain1290--- via R-help
Hi there,
I am currently working on a project that involves climate model data stored in 
a NetCDF file. I am currently trying to calculate "weighted" spatial annual 
"global" averages for precipitation. I need to do this for each of the 95 years 
of global precipitation data that I have. The idea would be to somehow apply 
weights to each grid cell by using the cosine of its latitude (which means 
latitude grid cells at the equator would have a weight of 1 (i.e. the cosine of 
0 degrees is 1), and the poles would have a value of 1 (as the cosine of 90 is 
1)). Then, I would be in a position to calculate annual weighted averages based 
on averaging each grid cell. 
I have an idea how to do this conceptually, but I am not sure where to begin 
writing a script in R to apply the weights across all grid cells and then 
average these for each of the 95 years. I would greatly appreciate any help 
with this, or any resources that may be helpful!!!
At the very least, I have opened the .nc file and read-in the NetCDF variables, 
as shown below:
ncfname<-"MaxPrecCCCMACanESM2rcp45.nc"
Prec<-raster(ncfname)
print(Prec)
Model<-nc_open(ncfname)
get<-ncvar_get(Model,"onedaymax")longitude<-ncvar_get(Model, "lon")
latitude<-ncvar_get(Model, "lat")
Year<-ncvar_get(Model, "Year")

Also, if it helps, here is what the .nc file contains:

3 variables (excluding dimension variables):
double onedaymax[lon,lat,time]   (Contiguous storage)  
units: mm/day
double fivedaymax[lon,lat,time]   (Contiguous storage)  
units: mm/day
short Year[time]   (Contiguous storage)  

 3 dimensions:
time  Size:95
lat  Size:64
units: degree North
lon  Size:128
units: degree East
Again, any assistance would be extremely valuable with this! I look forward to 
your response!
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Creating a mean line plot

2019-04-12 Thread rain1290--- via R-help
Hi there,
I am trying to create a mean line plot that shows the mean of a series of 
separate line plots that correspond to two climate models. Let's first try 
getting the mean of two line plots. To create the separate line plots, here is 
what I did to set up the x and y axis variables:

Getting cumulative emissions data for x-axis: 1-dimensional 

#For CanESM model#

ncfname <- "cumulative_emissions_1pctCO2.nc"
Model1 <- nc_open(ncfname)
get <- ncvar_get(Model1, "cum_co2_emi-CanESM2")     #units of terratones of 
carbon (TtC) for x-axis (140 values)
#For IPSL LR Model#
#Getting cumulative emissions data for x-axis IPSL LR 1pctCO2 IPSL <- 
ncvar_get(Model1, "cum_co2_emi-IPSL-CM5A-LR")     #units of terratones of 
carbon (TtC) for x-axis (140 values)



#Getting precipitation data for y-axis - these are 3-dimensional

#For CanESM2 model#
Model2 <- brick("MaxPrecCCCMACanESM21pctCO2.nc", var="onedaymax")


#For IPSL LR Model#
Model10 <- brick("MaxPrecIPSLIPSL-CM5A-LR1pctCO2.nc", var="onedaymax")
#
To create plots for a specific location:
lonlat <- cbind(103,3)          #specifies a specific longitude and latitude
Hope2 <- extract(Model2,lonlat)      #CanESM2
Hope6 <- extract(Model10,lonlat)   #start IPSL CM5A LR
plot(get,Hope2, type="l",col="green", lwd="3", xlab="Cumulative CO2 emissions 
(TtC)", ylab="One-day maximum precipitation (mm/day)", main="One-day maximum 
precipitation for random location for 1pctCO2 scenario")
lines(IPSL, Hope6, type="l", lwd="3", col="green")
#
So, the idea would be to create a plot that shows the mean of these two plots. 
Given what I showed above, how should I go about creating the mean of these two 
green line plots? Would you have to get the mean of the x-values, and then 
obtain the mean of the y-values, and then plot these?
Thanks, and any help would be greatly appreciated!
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Creating a mean line plot

2019-04-12 Thread rain1290--- via R-help
2, 14.7103695664555, 
    19.504395313561, 22.4196153692901, 22.2453631460667, 8.23867111466825, 
    8.1761412084, 7.8771845670417, 7.56322089582682, 7.14911003597081, 
    9.50618146453053, 8.6958515457809, 7.36113237217069, 6.79777669720352, 
    6.69330381788313), .Dim = c(10L, 90L), .Dimnames = list(NULL, 
    c("X1", "X2", "X3", "X4", "X5", "X6", "X7", "X8", "X9", "X10", 
    "X11", "X12", "X13", "X14", "X15", "X16", "X17", "X18", "X19", 
    "X20", "X21", "X22", "X23", "X24", "X25", "X26", "X27", "X28", 
    "X29", "X30", "X31", "X32", "X33", "X34", "X35", "X36", "X37", 
    "X38", "X39", "X40", "X41", "X42", "X43", "X44", "X45", "X46", 
    "X47", "X48", "X49", "X50", "X51", "X52", "X53", "X54", "X55", 
    "X56", "X57", "X58", "X59", "X60", "X61", "X62", "X63", "X64", 
    "X65", "X66", "X67", "X68", "X69", "X70", "X71", "X72", "X73", 
    "X74", "X75", "X76", "X77", "X78", "X79", "X80", "X81", "X82", 
    "X83", "X84", "X85", "X86", "X87", "X88", "X89", "X90")))

Is there any way to compute the means in this way? I just tried this, but I 
received the following error:
result <- rowMeans(cbind(c(subset), c(subset5)));dim(result) <- 
dim(subset);colnames(result) <- colnames(subset)

Error in rowMeans(cbind(c(subset), c(subset5))) : 'x' must be numeric

Thanks,
-Original Message-
From: Eric Berger 
To: rain1290 
Cc: r-sig-geo ; R mailing list 
Sent: Fri, Apr 12, 2019 11:47 am
Subject: Re: [R] Creating a mean line plot

I don't have your data. Are the x-values the same in both plots?Does this 
example cover the situation?
f1 <- function(x) { x^3 - 2 }f2 <- function(x) { 2 - x^2 }
xV <- seq(from=0,to=2,length=50)y1 <- f1(xV)y2 <- f2(xV)y3 <- 
.5*(y1+y2)plot(x=xV,y=y1,col="blue",lwd=2,type='l',xlab="x",ylab="y")lines(x=xV,y=y2,col="green",lwd=2)lines(x=xV,y=y3,col="red",lwd=2)legend("topleft",legend=c("y1","y2","mean"),col=c("blue","green","red"),lwd=rep(2,3))
       

On Fri, Apr 12, 2019 at 5:34 PM rain1290--- via R-help  
wrote:

Hi there,
I am trying to create a mean line plot that shows the mean of a series of 
separate line plots that correspond to two climate models. Let's first try 
getting the mean of two line plots. To create the separate line plots, here is 
what I did to set up the x and y axis variables:

Getting cumulative emissions data for x-axis: 1-dimensional 

#For CanESM model#

ncfname <- "cumulative_emissions_1pctCO2.nc"
Model1 <- nc_open(ncfname)
get <- ncvar_get(Model1, "cum_co2_emi-CanESM2")     #units of terratones of 
carbon (TtC) for x-axis (140 values)
#For IPSL LR Model#
#Getting cumulative emissions data for x-axis IPSL LR 1pctCO2 IPSL <- 
ncvar_get(Model1, "cum_co2_emi-IPSL-CM5A-LR")     #units of terratones of 
carbon (TtC) for x-axis (140 values)



#Getting precipitation data for y-axis - these are 3-dimensional

#For CanESM2 model#
Model2 <- brick("MaxPrecCCCMACanESM21pctCO2.nc", var="onedaymax")


#For IPSL LR Model#
Model10 <- brick("MaxPrecIPSLIPSL-CM5A-LR1pctCO2.nc", var="onedaymax")
#
To create plots for a specific location:
lonlat <- cbind(103,3)          #specifies a specific longitude and latitude
Hope2 <- extract(Model2,lonlat)      #CanESM2
Hope6 <- extract(Model10,lonlat)   #start IPSL CM5A LR
plot(get,Hope2, type="l",col="green", lwd="3", xlab="Cumulative CO2 emissions 
(TtC)", ylab="One-day maximum precipitation (mm/day)", main="One-day maximum 
precipitation for random location for 1pctCO2 scenario")
lines(IPSL, Hope6, type="l", lwd="3", col="green")
#
So, the idea would be to create a plot that shows the mean of these two plots. 
Given what I showed above, how should I go about creating the mean of these two 
green line plots? Would you have to get the mean of the x-values, and then 
obtain the mean of the y-values, and then plot these?
Thanks, and any help would be greatly appreciated!
        [[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Creating a mean line plot

2019-04-14 Thread rain1290--- via R-help
Hi Bill,

For the x-axis variable, in this case, indeed, I used 
rowMeans(cbind(get2.teratons, get5.teratons)). This averaged each value between 
these two 1-dimensional variables (i.e. value#1 of "get2.teratons" was averaged 
with value#1 of "get5.teratons" - this was done for all 90 values). 
To obtain the means for the values of the y-axis variables, which are 
3-dimensional, I simply took each variable and divided by 2, in this case. 
Thus: (variableA+variableB)/2. This took the mean of the variable for each grid 
cell for each layer (90 layers). So, for grid cell #1, doing this averaged all 
90 values corresponding to the 90 layers between the two variables. For 
example, the values of layer 1 of variableA and layer 1 of variableB were 
averaged (and then layer 2 with layer 2, and then layer 3 with layer 3.all 
the way to layer 90 with layer 90. This method simultaneously did this for all 
8192 grid cells (128 lines of longitude and 64 lines of latitude). At the end, 
I obtained 90 averages for each grid cell. :)
~Trav.~
-Original Message-
From: William Michels 
To: rain1290 
Cc: r-help ; r-sig-geo 
Sent: Sun, Apr 14, 2019 4:46 am
Subject: Re: [R] Creating a mean line plot

So you're saying rowMeans(cbind(matrix_a, matrix_b)) worked to obtain
your X-axis values?

Wild guess here, are you simply looking for:
colMeans(rbind(matrix_a, matrix_b)) to obtain your Y-axis values?

[Above assuming matrix_a and matrix_b have identical dimensions (nrow, ncol)].

--Bill

William Michels, Ph.D.


On Fri, Apr 12, 2019 at 11:09 AM rain1290--- via R-help






 wrote:
>
> Hi Eric,
>
> Ah, I apologize, and thank you for your response!
> I just figured out a way to average my x-values, so at least that is solved. 
> I will still include the data for the two variables (1-dimensional) of 
> interest that I was trying to average, just to show what was done:
> get2.teratons #(90 values)
> get5.teratons #(90 values)
> Here is what get2.teratons looks like (same idea for get5.teratons):
>    >print(get2.teratons)
>    [1] 0.4558545 0.4651129 0.4747509 0.4848242 0.4950900 0.5056109 0.5159335
>    0.5262532 0.5372275 0.5481839 0.5586787 0.5694379 0.5802970
>    [14] 0.5909211 0.6015753 0.6124256 0.6237733 0.6353634 0.6467227 0.6582857
>    0.6702509 0.6817027 0.6935311 0.7060161 0.7182312 0.7301909
>    [27] 0.7422574 0.7544744 0.7665907 0.7786409 0.7907518 0.8032732 0.8158733
>    0.8284363 0.8413905 0.8545881 0.8674711 0.8797701 0.8927392
>    [40] 0.9059937 0.9189707 0.9317215 0.9438155 0.9558035 0.9673665 0.9784927
>    0.9900898 1.0020388 1.0132683 1.0240023 1.0347708 1.0456077
>    [53] 1.0570347 1.0682903 1.0793535 1.0901511 1.1001753 1.1101276 1.1199142
>    1.1293237 1.1384669 1.1470002 1.1547341 1.1622488 1.1697549
>    [66] 1.1777542 1.1857587 1.1930233 1.1999645 1.2067172 1.2132979 1.2199317
>    1.2265673 1.2328599 1.2390689 1.2446050 1.2495579 1.2546455
>    [79] 1.2599212 1.2648733 1.2700068 1.2753889 1.2807509 1.2856922 1.2905927
>    1.2953338 1.3000484 1.3045992 1.3091128 1.3144190
> The following worked in terms of averaging all of the elements of 
> get2.teratons and get5.teratons:
> rowMeans(cbind(get2.teratons,get5.teratons))
> However, I am trying to do something similar for the values on my y-axis. So, 
> for now, here are the two variables (3-dimensional) that I would like to 
> average:
>    subset
>    subset5
> Using the print function for "subset" (same idea for subset5):    
> >print(subset)
>    class      : RasterStack
>    dimensions  : 64, 128, 8192, 90  (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
>    names      : X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14,
>    X15, ...    >dim(subset)
>    [1]  64 128  90>dim(subset5)
>    [1]  64 128  90
> I tried `mean(subset,subset5)`, which works, BUT it combines the 90 layers 
> into 1 layer. I want keep the number of layers at 90, but simply average each 
> of the grid cell values of "subset" and "subset5" for each layer. So, for 
> instance, I want to average the values of each grid cell of layer 1 of 
> "subset" with the values of each grid cell of layer 1 of "subset5", and then 
> average those values of layer 2 of "subset" with those values of layer 2 of 
> "subset5"..all the way to layer 90. That way, I have 90 averages across 
> all grid cells.
> Here is what the data looks like for "subset":
> >dput(head(subset,5))
>    structure(c(11.5447145886719, 11.2479725852609, 10.0223480723798,
>    11.4909216295928, 12.5930442474

[R] Creating a median curve among multiple curvesin ggplot

2019-06-04 Thread rain1290--- via R-help
Hi there,
Using ggplot, I have successfully created a plot that contains 37 separate line 
plots that each represent a trend in precipitation over 140 years. However, 
what I would like to do is show the curve that is the "median" of these lines. 
Is this possible to do? 
Here is what I have so far in an attempt to do this, but I am not certain if it 
is the correct approach to create the desired median line - the first variable 
shows x-variable objects (each 1-dimensional) and the second variable shows the 
y-variable objects (3-dimensional):
RCP1pctCO2Median <- median(cbind(get, IPSL, IPSLMR, IPSL5, MIROC, HadGEM, MPI, 
MPI5, GFDL, GFDL5)) 
RCP1pctCO2ModelMedian <- median(cbind(Model2, Model10, Model18, Model26, 
subset14, Model42, subset20, subset24, Model60, Model68))

The first variable appears to work, but it only returns one value, and I want 
all of the 140 values corresponding to whichever curve was returned. Why is it 
that only one value returns? Here is what the variable contains:
>RCP1pctCO2Median[1] 1.189044
When I run the second variable the same way, I receive the following error:
Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 
  'x' must be atomic
Why does this appear?  I tried "unlist" and "as.vector", but the same error 
appears.
If it helps, to show what the 1-dimensional objects of the first variable look 
like, here is an example of one (the object "get"):
>get
  [1] 0. 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.4102 
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.6896 
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.9006 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

For the 3-D objects within the second variable, here is what is contained in 
the object "Model2", for example:
>Model2 <- brick("MaxPrecCCCMACanESM21pctCO2.nc", var = "onedaymax")
>Model2class   : 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 : C:/Users/Travis/Documents/Other documents/All netCDF 
files/netcdffiles/MaxPrecCCCMACanESM21pctCO2.nc 
names   : X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12, X13, X14, X15, 
... 
z-value : 1, 140 (min, max)
varname : onedaymax 


In any case, I am not even certain if what I have done above is the correct 
approach altogether to create a median line, but I would greatly appreciate any 
assistance! Your feedback would be extremely valuable to me!
Thank you, and I very much look forward to hearing from you!
[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Plotting more than one regression line in ggplot

2019-06-05 Thread rain1290--- via R-help
I am trying to plot, using ggplot, a series of scatter plots with regression 
lines for several datasets. I started with the following dataset, 
"onepectCO2MEDIAN". The data for this dataset is as follows:
    onepctCO2MEDIAN
    x  y
    layer.1   0.0  0.000
    layer.2   0.006794447  4.9002490
    layer.3   0.014288058  0.1608000
    layer.4   0.022087920  6.6349133
    layer.5   0.030797357 -1.2429506
    layer.6   0.038451072  1.5643374
    layer.7   0.048087904 -2.2659035
    layer.8   0.058677729  2.2070045
    layer.9   0.069261406 -2.3677001
    layer.10  0.080524530 -1.0913506
    layer.11  0.092760246  0.4099940
    layer.12  0.103789609 -0.1259727
    layer.13  0.116953168 -2.4138253
    layer.14  0.129253298  7.0890257
    layer.15  0.141710050 -0.7593539
    layer.16  0.156002052  0.0454416
    layer.17  0.170648172 -1.5349683
    layer.18  0.185318425  6.5524201
    layer.19  0.199463055 -0.8312563
    layer.20  0.213513337 -2.5099183
    layer.21  0.228839271  0.1365968
    layer.22  0.246981293 -1.3719845
    layer.23  0.263012767 -0.8712988
    layer.24  0.278505564  0.6632584
    layer.25  0.293658361  0.7938036
    layer.26  0.310747266  3.4880637
    layer.27  0.325990349 -4.4612208
    layer.28  0.342517540  0.0871734
    layer.29  0.362751633 -1.4171578
    layer.30  0.380199537 -0.9956508
    layer.31  0.394992948  0.3215526
    layer.32  0.414373398  3.1403866
    layer.33  0.430690214 -0.7376099
    layer.34  0.449738145 -2.4860541
    layer.35  0.470167458 -3.4235858
    layer.36  0.489019871  0.4824748
    layer.37  0.507242471 -0.9785386
    layer.38  0.524314284  8.5359684
    layer.39  0.543750525  5.4844742
    layer.40  0.564234197  3.2149367
    layer.41  0.583679616  3.9168916 
    layer.42  0.601459444  4.4907020
    layer.43  0.619924664  6.5410410
    layer.44  0.639932007  4.8068650
    layer.45  0.661347181  8.1510170
    layer.46  0.684117317  0.2697413
    layer.47  0.704829752 -0.1807501
    layer.48  0.725045770  9.7181249
    layer.49  0.745165825  1.5406466
    layer.50  0.765016139 -1.6476041
    layer.51  0.783461511  4.8024603
    layer.52  0.806382924  4.0421516
    layer.53  0.829241335  9.3756512
    layer.54  0.849924415  5.3305050
    layer.55  0.871352434  7.5445803
    layer.56  0.893632233  6.4679547
    layer.57  0.916052133  2.8096065
    layer.58  0.938579470  5.3921661
    layer.59  0.959907651  7.2043689
    layer.60  0.981643587  3.3350806
    layer.61  1.004116774  8.8690707
    layer.62  1.028363466  1.7861299
    layer.63  1.054009140  6.2555038
    layer.64  1.072440803  7.6079236
    layer.65  1.094457805  7.6871483
    layer.66  1.123176277  4.7787764
    layer.67  1.149430871 12.7110502
    layer.68  1.170912921 -0.7156284
    layer.69  1.196743071  1.6490899
    layer.70  1.218625903  3.0363024
    layer.71  1.241868377  4.2974769
    layer.72  1.267941594  1.9543778
    layer.73  1.290708780  3.9986964
    layer.74  1.31389  4.5179472
    layer.75  1.339045882  0.9337905
    layer.76  1.362803459  3.3050770
    layer.77  1.384450197  3.5422970
    layer.78  1.409720302  5.9973660
    layer.79  1.435851157  0.5081869
    layer.80  1.455592215  7.9661630
    layer.81  1.479495347  9.9460496
    layer.82  1.506051958  3.7908372
    layer.83  1.525728464  2.5735847
    layer.84  1.549362063 10.1404974
    layer.85  1.573440671 13.7408304
    layer.86  1.600278735  0.9335771
    layer.87  1.623879492  9.7588742
    layer.88  1.650029302  1.2769395
    layer.89  1.672362328 13.4970906
    layer.90  1.700221121 10.2087502
    layer.91  1.724793375  1.6811275
    layer.92  1.751070559  6.1178992
    layer.93  1.778022110 -0.1567626
    layer.94  1.803022087  3.8237479
    layer.95  1.830668867  4.4331468
    layer.96  1.855736911  5.9790707
    layer.97  1.882615030 11.3104333
    layer.98  1.909218490  8.2142607
    layer.99  1.938130021 15.3209674
    layer.100 1.963727593  5.8178217
    layer.101 1.993271947  9.6004907
    layer.102 2.022548139  3.4063646
    layer.103 2.050679922  4.7375010
    layer.104 2.078064442  3.0133019
    layer.105 2.104113460  5.5659522
    layer.106 2.133597612 12.0346333
    layer.107 2.164026260 -0.4028320
    layer.108 2.194852829 10.5996780
    layer.109 2.224257946  5.4479584
    layer.110 2.252194643  4.7052374
    layer.111 2.277335048 14.0962019
    layer.112 2.304058313  5.7149016
    layer.113 2.330930233  3.7780072
    layer.114 2.357022762  4.4120620
    layer.115 2.386489272  4.1866085
    layer.116 2.417503953  6.9078802
    layer.117 2.448524356  2.7825739
    layer.118 2.478698969  7.6171786
    layer.119 2.510175705 10.2410603
    layer.120 2.539697886  8.1820711
    layer.121 2.567915559  4.8275494
    layer.122 2.597463250 19.1624883
    layer.123 2.627518773 16.0677109
    layer.124 2.658759236 12.5897081
    layer.125 2.692401528  9.2907988
    layer.126 2.721903205  7.4262502
    layer.127 2.753021359  9.3902518
    layer.128 2.786313415 12.6193550
   

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread rain1290--- via R-help
Hi Jeff (and everyone),

Thank you for your response and feedback. Yes, I know what you mean - it was a 
blind and quick choice to use "lm" as my object name. Unfortunately, changing 
the object name to something else does not eliminate that error/warning 
message. As a result, the same error/warning appears when running it. Oddly 
enough, the scatter plot is just fine - it's the regression line that struggles 
to appear. Could there be another reason for that?
Thanks, again,


-Original Message-
From: Jeff Newmiller 
To: rain1290 ; rain1290--- via R-help ; 
r-help ; r-sig-geo 
Sent: Wed, Jun 5, 2019 10:49 am
Subject: Re: [R] Plotting more than one regression line in ggplot

Please read the Posting Guide... posting HTML on a plain text mailing list 
really interferes with clear communication.

If you had spent even a small amount of time working with R tutorials then you 
would know that "lm" is the name of a very basic, very important R function. 
However, you are defining your own object called "lm" that is very different 
indeed than the usual "lm" function. I would guess that in a clean new R 
workspace where you had not already run your ggplot function and assigned the 
result to your own "lm" object then this code might run. However, once you have 
run it once and try to run it again, your "method" argument gives the wrong 
version of "lm" to geom_smooth and you confuse it.

As the doctor said to the man pounding his own head against the wall, "If it 
hurts, don't do that." Avoid re-using important object names in R... some 
common names I see abused this way are df, data, c, t, T, and F. Your choice 
was unusual, but quite effective at illustrating the problem.

On June 5, 2019 7:21:57 AM PDT, rain1290--- via R-help  
wrote:
>I am trying to plot, using ggplot, a series of scatter plots with
>regression lines for several datasets. I started with the following
>dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:
>    onepctCO2MEDIAN
>    x  y
>    layer.1   0.0  0.000
>    layer.2   0.006794447  4.9002490
>    layer.3   0.014288058  0.1608000
>    layer.4   0.022087920  6.6349133
>    layer.5   0.030797357 -1.2429506
>    layer.6   0.038451072  1.5643374
>    layer.7   0.048087904 -2.2659035
>    layer.8   0.058677729  2.2070045
>    layer.9   0.069261406 -2.3677001
>    layer.10  0.080524530 -1.0913506
>    layer.11  0.092760246  0.4099940
>    layer.12  0.103789609 -0.1259727
>    layer.13  0.116953168 -2.4138253
>    layer.14  0.129253298  7.0890257
>    layer.15  0.141710050 -0.7593539
>    layer.16  0.156002052  0.0454416
>    layer.17  0.170648172 -1.5349683
>    layer.18  0.185318425  6.5524201
>    layer.19  0.199463055 -0.8312563
>    layer.20  0.213513337 -2.5099183
>    layer.21  0.228839271  0.1365968
>    layer.22  0.246981293 -1.3719845
>    layer.23  0.263012767 -0.8712988
>    layer.24  0.278505564  0.6632584
>    layer.25  0.293658361  0.7938036
>    layer.26  0.310747266  3.4880637
>    layer.27  0.325990349 -4.4612208
>    layer.28  0.342517540  0.0871734
>    layer.29  0.362751633 -1.4171578
>    layer.30  0.380199537 -0.9956508
>    layer.31  0.394992948  0.3215526
>    layer.32  0.414373398  3.1403866
>    layer.33  0.430690214 -0.7376099
>    layer.34  0.449738145 -2.4860541
>    layer.35  0.470167458 -3.4235858
>    layer.36  0.489019871  0.4824748
>    layer.37  0.507242471 -0.9785386
>    layer.38  0.524314284  8.5359684
>    layer.39  0.543750525  5.4844742
>    layer.40  0.564234197  3.2149367
>    layer.41  0.583679616  3.9168916 
>    layer.42  0.601459444  4.4907020
>    layer.43  0.619924664  6.5410410
>    layer.44  0.639932007  4.8068650
>    layer.45  0.661347181  8.1510170
>    layer.46  0.684117317  0.2697413
>    layer.47  0.704829752 -0.1807501
>    layer.48  0.725045770  9.7181249
>    layer.49  0.745165825  1.5406466
>    layer.50  0.765016139 -1.6476041
>    layer.51  0.783461511  4.8024603
>    layer.52  0.806382924  4.0421516
>    layer.53  0.829241335  9.3756512
>    layer.54  0.849924415  5.3305050
>    layer.55  0.871352434  7.5445803
>    layer.56  0.893632233  6.4679547
>    layer.57  0.916052133  2.8096065
>    layer.58  0.938579470  5.3921661
>    layer.59  0.959907651  7.2043689
>    layer.60  0.981643587  3.3350806
>    layer.61  1.004116774  8.8690707
>    layer.62  1.028363466  1.7861299
>    layer.63  1.054009140  6.2555038
>    layer.64  1.072440803  7.6079236
>    layer.65  1.094457805  7.6871483
>    layer.66  1.123176277  4.7787764
>    layer.67  1.149430871 12.7110502
>    layer.68  1.170912921 -0.7156284
>    layer.69  1.196743071  1.6490899
>    layer.70  1

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread rain1290--- via R-help
Hi David (and everyone),

Thank you for your response. I changed the column names to x and y, but the 
error/warning persists:
Warning message:
Computation failed in `stat_smooth()`:
'what' must be a function or character string 
It is quite baffling as to why this is happening. Why would it work for the 
scatter plot and not the regression line?

-Original Message-
From: David Winsemius 
To: r-help 
Sent: Wed, Jun 5, 2019 12:00 pm
Subject: Re: [R] Plotting more than one regression line in ggplot


On 6/5/19 8:04 AM, rain1290--- via R-help wrote:
> Hi Jeff (and everyone),
>
> Thank you for your response and feedback. Yes, I know what you mean - it was 
> a blind and quick choice to use "lm" as my object name. Unfortunately, 
> changing the object name to something else does not eliminate that 
> error/warning message. As a result, the same error/warning appears when 
> running it. Oddly enough, the scatter plot is just fine - it's the regression 
> line that struggles to appear. Could there be another reason for that?
> Thanks, again,


TRhe error came because you did not reference the column names 
correctly. This succeeds with the data you offered:


ggplot(onepctCO2MEDIAN) +
  geom_jitter(aes(x,y),
  colour="blue") + geom_smooth(aes(x,y), method=lm)


# At some point you changed the column names from 
(RCP1pctCO2cumulativeMedian, departurea) to (x,y) , but didn't adjust 
your code.


Best;

David.

>
> -----Original Message-
> From: Jeff Newmiller 
> To: rain1290 ; rain1290--- via R-help 
> ; r-help ; r-sig-geo 
> 
> Sent: Wed, Jun 5, 2019 10:49 am
> Subject: Re: [R] Plotting more than one regression line in ggplot
>
> Please read the Posting Guide... posting HTML on a plain text mailing list 
> really interferes with clear communication.
>
> If you had spent even a small amount of time working with R tutorials then 
> you would know that "lm" is the name of a very basic, very important R 
> function. However, you are defining your own object called "lm" that is very 
> different indeed than the usual "lm" function. I would guess that in a clean 
> new R workspace where you had not already run your ggplot function and 
> assigned the result to your own "lm" object then this code might run. 
> However, once you have run it once and try to run it again, your "method" 
> argument gives the wrong version of "lm" to geom_smooth and you confuse it.
>
> As the doctor said to the man pounding his own head against the wall, "If it 
> hurts, don't do that." Avoid re-using important object names in R... some 
> common names I see abused this way are df, data, c, t, T, and F. Your choice 
> was unusual, but quite effective at illustrating the problem.
>
> On June 5, 2019 7:21:57 AM PDT, rain1290--- via R-help  
> wrote:
>> I am trying to plot, using ggplot, a series of scatter plots with
>> regression lines for several datasets. I started with the following
>> dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:
>>      onepctCO2MEDIAN
>>      x  y
>>      layer.1   0.0  0.000
>>      layer.2   0.006794447  4.9002490
>>      layer.3   0.014288058  0.1608000
>>      layer.4   0.022087920  6.6349133
>>      layer.5   0.030797357 -1.2429506
>>      layer.6   0.038451072  1.5643374
>>      layer.7   0.048087904 -2.2659035
>>      layer.8   0.058677729  2.2070045
>>      layer.9   0.069261406 -2.3677001
>>      layer.10  0.080524530 -1.0913506
>>      layer.11  0.092760246  0.4099940
>>      layer.12  0.103789609 -0.1259727
>>      layer.13  0.116953168 -2.4138253
>>      layer.14  0.129253298  7.0890257
>>      layer.15  0.141710050 -0.7593539
>>      layer.16  0.156002052  0.0454416
>>      layer.17  0.170648172 -1.5349683
>>      layer.18  0.185318425  6.5524201
>>      layer.19  0.199463055 -0.8312563
>>      layer.20  0.213513337 -2.5099183
>>      layer.21  0.228839271  0.1365968
>>      layer.22  0.246981293 -1.3719845
>>      layer.23  0.263012767 -0.8712988
>>      layer.24  0.278505564  0.6632584
>>      layer.25  0.293658361  0.7938036
>>      layer.26  0.310747266  3.4880637
>>      layer.27  0.325990349 -4.4612208
>>      layer.28  0.342517540  0.0871734
>>      layer.29  0.362751633 -1.4171578
>>      layer.30  0.380199537 -0.9956508
>>      layer.31  0.394992948  0.3215526
>>      layer.32  0.414373398  3.1403866
>>      layer.33  0.430690214 -0.7376099
>>      layer.34  0.449738145 -2.4860541
>>      layer.35  0.470167458 -3.4235858
>>      l

Re: [R] Plotting more than one regression line in ggplot

2019-06-05 Thread rain1290--- via R-help
O2MEDIAN, onepctCO2MEDIAN2)

ggplot(df2, aes(x, y, group = id, colour = factor(id))) +
  geom_point() +
  geom_smooth(method = 'lm')


Hope this helps,

Rui Barradas

Às 15:21 de 05/06/19, rain1290--- via R-help escreveu:
> I am trying to plot, using ggplot, a series of scatter plots with regression 
> lines for several datasets. I started with the following dataset, 
> "onepectCO2MEDIAN". The data for this dataset is as follows:
>      onepctCO2MEDIAN
>      x  y
>      layer.1   0.0  0.000
>      layer.2   0.006794447  4.9002490
>      layer.3   0.014288058  0.1608000
>      layer.4   0.022087920  6.6349133
>      layer.5   0.030797357 -1.2429506
>      layer.6   0.038451072  1.5643374
>      layer.7   0.048087904 -2.2659035
>      layer.8   0.058677729  2.2070045
>      layer.9   0.069261406 -2.3677001
>      layer.10  0.080524530 -1.0913506
>      layer.11  0.092760246  0.4099940
>      layer.12  0.103789609 -0.1259727
>      layer.13  0.116953168 -2.4138253
>      layer.14  0.129253298  7.0890257
>      layer.15  0.141710050 -0.7593539
>      layer.16  0.156002052  0.0454416
>      layer.17  0.170648172 -1.5349683
>      layer.18  0.185318425  6.5524201
>      layer.19  0.199463055 -0.8312563
>      layer.20  0.213513337 -2.5099183
>      layer.21  0.228839271  0.1365968
>      layer.22  0.246981293 -1.3719845
>      layer.23  0.263012767 -0.8712988
>      layer.24  0.278505564  0.6632584
>      layer.25  0.293658361  0.7938036
>      layer.26  0.310747266  3.4880637
>      layer.27  0.325990349 -4.4612208
>      layer.28  0.342517540  0.0871734
>      layer.29  0.362751633 -1.4171578
>      layer.30  0.380199537 -0.9956508
>      layer.31  0.394992948  0.3215526
>      layer.32  0.414373398  3.1403866
>      layer.33  0.430690214 -0.7376099
>      layer.34  0.449738145 -2.4860541
>      layer.35  0.470167458 -3.4235858
>      layer.36  0.489019871  0.4824748
>      layer.37  0.507242471 -0.9785386
>      layer.38  0.524314284  8.5359684
>      layer.39  0.543750525  5.4844742
>      layer.40  0.564234197  3.2149367
>      layer.41  0.583679616  3.9168916
>      layer.42  0.601459444  4.4907020
>      layer.43  0.619924664  6.5410410
>      layer.44  0.639932007  4.8068650
>      layer.45  0.661347181  8.1510170
>      layer.46  0.684117317  0.2697413
>      layer.47  0.704829752 -0.1807501
>      layer.48  0.725045770  9.7181249
>      layer.49  0.745165825  1.5406466
>      layer.50  0.765016139 -1.6476041
>      layer.51  0.783461511  4.8024603
>      layer.52  0.806382924  4.0421516
>      layer.53  0.829241335  9.3756512
>      layer.54  0.849924415  5.3305050
>      layer.55  0.871352434  7.5445803
>      layer.56  0.893632233  6.4679547
>      layer.57  0.916052133  2.8096065
>      layer.58  0.938579470  5.3921661
>      layer.59  0.959907651  7.2043689
>      layer.60  0.981643587  3.3350806
>      layer.61  1.004116774  8.8690707
>      layer.62  1.028363466  1.7861299
>      layer.63  1.054009140  6.2555038
>      layer.64  1.072440803  7.6079236
>      layer.65  1.094457805  7.6871483
>      layer.66  1.123176277  4.7787764
>      layer.67  1.149430871 12.7110502
>      layer.68  1.170912921 -0.7156284
>      layer.69  1.196743071  1.6490899
>      layer.70  1.218625903  3.0363024
>      layer.71  1.241868377  4.2974769
>      layer.72  1.267941594  1.9543778
>      layer.73  1.290708780  3.9986964
>      layer.74  1.31389  4.5179472
>      layer.75  1.339045882  0.9337905
>      layer.76  1.362803459  3.3050770
>      layer.77  1.384450197  3.5422970
>      layer.78  1.409720302  5.9973660
>      layer.79  1.435851157  0.5081869
>      layer.80  1.455592215  7.9661630
>      layer.81  1.479495347  9.9460496
>      layer.82  1.506051958  3.7908372
>      layer.83  1.525728464  2.5735847
>      layer.84  1.549362063 10.1404974
>      layer.85  1.573440671 13.7408304
>      layer.86  1.600278735  0.9335771
>      layer.87  1.623879492  9.7588742
>      layer.88  1.650029302  1.2769395
>      layer.89  1.672362328 13.4970906
>      layer.90  1.700221121 10.2087502
>      layer.91  1.724793375  1.6811275
>      layer.92  1.751070559  6.1178992
>      layer.93  1.778022110 -0.1567626
>      layer.94  1.803022087  3.8237479
>      layer.95  1.830668867  4.4331468
>      layer.96  1.855736911  5.9790707
>      layer.97  1.882615030 11.3104333
>      layer.98  1.909218490  8.2142607
>      layer.99  1.938130021 15.3209674
>      layer.100 1.963727593  5.8178217
>      layer.101 1.993271947  9.6004907
>      layer.102 2.022548139  3.4063646
>      layer.103 2.050679922  4.7375010
>      layer.104 2.078064442  3.0

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
ctCO2MEDIAN Warning:Ignoring 
> unknown aesthetics: onepctCO2MEDIAN
> 
> **//___^
> Perhaps I am not assigning the columns properly? Essentially, I just 
> want create two scatter plots and two regression lines for these two 
> objects.
> 
> Once again, any assistance would be greatly appreciated!
> 
> -Original Message-
> From: Rui Barradas 
> To: rain1290 ; r-help ; 
> r-sig-geo 
> Sent: Wed, Jun 5, 2019 10:52 am
> Subject: Re: [R] Plotting more than one regression line in ggplot
> 
> Hello,
> 
> This is pretty basic ggplot.
> 
> 
> lm1 <- ggplot(onepctCO2MEDIAN, aes(x, y)) +
>    geom_point(colour = 'blue') +
>    geom_smooth(method = 'lm')
> 
> lm1
> 
> 
> If you want to combine several datasets, you will have to have a
> variable telling which dataset is which. In the example below, this is
> column 'id'.
> 
> 
> onepctCO2MEDIAN2 <- onepctCO2MEDIAN
> onepctCO2MEDIAN2$y <- jitter(onepctCO2MEDIAN2$y) + 2
> onepctCO2MEDIAN$id <- 1
> onepctCO2MEDIAN2$id <- 2
> df2 <- rbind(onepctCO2MEDIAN, onepctCO2MEDIAN2)
> 
> ggplot(df2, aes(x, y, group = id, colour = factor(id))) +
>    geom_point() +
>    geom_smooth(method = 'lm')
> 
> 
> Hope this helps,
> 
> Rui Barradas
> 
> Às 15:21 de 05/06/19, rain1290--- via R-help escreveu:
>  > I am trying to plot, using ggplot, a series of scatter plots with 
> regression lines for several datasets. I started with the following 
> dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:
>  >      onepctCO2MEDIAN
>  >      x  y
>  >      layer.1   0.0  0.000
>  >      layer.2   0.006794447  4.9002490
>  >      layer.3   0.014288058  0.1608000
>  >      layer.4   0.022087920  6.6349133
>  >      layer.5   0.030797357 -1.2429506
>  >      layer.6   0.038451072  1.5643374
>  >      layer.7   0.048087904 -2.2659035
>  >      layer.8   0.058677729  2.2070045
>  >      layer.9   0.069261406 -2.3677001
>  >      layer.10  0.080524530 -1.0913506
>  >      layer.11  0.092760246  0.4099940
>  >      layer.12  0.103789609 -0.1259727
>  >      layer.13  0.116953168 -2.4138253
>  >      layer.14  0.129253298  7.0890257
>  >      layer.15  0.141710050 -0.7593539
>  >      layer.16  0.156002052  0.0454416
>  >      layer.17  0.170648172 -1.5349683
>  >      layer.18  0.185318425  6.5524201
>  >      layer.19  0.199463055 -0.8312563
>  >      layer.20  0.213513337 -2.5099183
>  >      layer.21  0.228839271  0.1365968
>  >      layer.22  0.246981293 -1.3719845
>  >      layer.23  0.263012767 -0.8712988
>  >      layer.24  0.278505564  0.6632584
>  >      layer.25  0.293658361  0.7938036
>  >      layer.26  0.310747266  3.4880637
>  >      layer.27  0.325990349 -4.4612208
>  >      layer.28  0.342517540  0.0871734
>  >      layer.29  0.362751633 -1.4171578
>  >      layer.30  0.380199537 -0.9956508
>  >      layer.31  0.394992948  0.3215526
>  >      layer.32  0.414373398  3.1403866
>  >      layer.33  0.430690214 -0.7376099
>  >      layer.34  0.449738145 -2.4860541
>  >      layer.35  0.470167458 -3.4235858
>  >      layer.36  0.489019871  0.4824748
>  >      layer.37  0.507242471 -0.9785386
>  >      layer.38  0.524314284  8.5359684
>  >      layer.39  0.543750525  5.4844742
>  >      layer.40  0.564234197  3.2149367
>  >      layer.41  0.583679616  3.9168916
>  >      layer.42  0.601459444  4.4907020
>  >      layer.43  0.619924664  6.5410410
>  >      layer.44  0.639932007  4.8068650
>  >      layer.45  0.661347181  8.1510170
>  >      layer.46  0.684117317  0.2697413
>  >      layer.47  0.704829752 -0.1807501
>  >      layer.48  0.725045770  9.7181249
>  >      layer.49  0.745165825  1.5406466
>  >      layer.50  0.765016139 -1.6476041
>  >      layer.51  0.783461511  4.8024603
>  >      layer.52  0.806382924  4.0421516
>  >      layer.53  0.829241335  9.3756512
>  >      layer.54  0.849924415  5.3305050
>  >      layer.55  0.871352434  7.5445803
>  >      layer.56  0.893632233  6.4679547
>  >      layer.57  0.916052133  2.8096065
>  >      layer.58  0.938579470  5.3921661
>  >      layer.59  0.959907651  7.2043689
>  >      layer.60  0.981643587  3.3350806
>  >      layer.61  1.004116774  8.8690707
>  >      layer.62  1.028363466  1.7861299
>  >      layer.63  1.054009140  6.2555038
>  >      layer.64  1.072440803  7.6079236
>  >      layer.65  1.094457805  7.6871483
>  >      layer.66  1.123176277  4.7787764

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
1.154488347 y -4.24916247 RCP4.5MEDIAN 215 1.159872903 y 7.90741918
>  > RCP4.5MEDIAN 216 1.165477487 y -3.91386711 RCP4.5MEDIAN 217 1.171103424
>  > y 1.02370701 RCP4.5MEDIAN 218 1.177498256 y -3.71206616 RCP4.5MEDIAN 219
>  > 1.184003888 y -1.05694182 RCP4.5MEDIAN 220 1.190395856 y 1.10501459
>  > RCP4.5MEDIAN 221 1.197284280 y 2.67668639 RCP4.5MEDIAN 222 1.204590551 y
>  > 2.21693031 RCP4.5MEDIAN 223 1.210807614 y 2.90252830 RCP4.5MEDIAN 224
>  > 1.216470664 y 2.75093766 RCP4.5MEDIAN 225 1.221914148 y -0.73815245
>  > RCP4.5MEDIAN 226 1.227580480 y 3.58554626 RCP4.5MEDIAN 227 1.233317788 y
>  > 10.89961658 RCP4.5MEDIAN 228 1.238093406 y 3.23374387 RCP4.5MEDIAN 229
>  > 0.466622908 y -1.92366466 RCP8.5MEDIAN 230 0.474211509 y 4.09292949
>  > RCP8.5MEDIAN 231 0.480383051 y -0.84736312 RCP8.5MEDIAN 232 0.486304903
>  > y -0.80597889 RCP8.5MEDIAN 233 0.492151615 y -0.50244413 RCP8.5MEDIAN
>  > 234 0.499312643 y 3.07785701 RCP8.5MEDIAN 235 0.508859905 y -6.15175322
>  > RCP8.5MEDIAN 236 0.518758845 y -0.51590144 RCP8.5MEDIAN 237 0.528675758
>  > y 3.33135956 RCP8.5MEDIAN 238 0.538928423 y 2.62280891 RCP8.5MEDIAN 239
>  > 0.549621221 y -6.90096009 RCP8.5MEDIAN 240 0.560062840 y -3.45706029
>  > RCP8.5MEDIAN 241 0.570860791 y 1.36192518 RCP8.5MEDIAN 242 0.581923368 y
>  > 0.34822359 RCP8.5MEDIAN 243 0.592628298 y 3.06882935 RCP8.5MEDIAN 244
>  > 0.604230648 y -3.56142825 RCP8.5MEDIAN 245 0.615975167 y 10.35932554
>  > RCP8.5MEDIAN 246 0.627448279 y 10.21751629 RCP8.5MEDIAN 247 0.639401050
>  > y 3.31040335 RCP8.5MEDIAN 248 0.651949591 y -0.53558775 RCP8.5MEDIAN 249
>  > 0.664634427 y 2.66081860 RCP8.5MEDIAN 250 0.677343552 y 3.21379656
>  > RCP8.5MEDIAN Maybe something like this?
>  >
>  > lusher<-ggplot(NewestdataULTRA) +
>  > geom_jitter(aes(x,value,onepctCO2MEDIAN=L1), colour="green") +
>  > geom_smooth(aes(x, value, onepctCO2MEDIAN=L1), method=lm) +
>  > geom_jitter(aes(x, value, RCP8.5MEDIAN=L1), colour="red")**//___^
>  > **//___^
>  > I receive this warning, however:
>  >
>  > Warning:Ignoring unknown aesthetics: onepctCO2MEDIAN Warning:Ignoring
>  > unknown aesthetics: onepctCO2MEDIAN
>  >
>  > **//___^
>  > Perhaps I am not assigning the columns properly? Essentially, I just
>  > want create two scatter plots and two regression lines for these two
>  > objects.
>  >
>  > Once again, any assistance would be greatly appreciated!
>  >
>  > -Original Message-
>  > From: Rui Barradas mailto:ruipbarra...@sapo.pt>>
>  > To: rain1290 mailto:rain1...@aim.com>>; r-help 
> mailto:r-help@R-project.org>>;
>  > r-sig-geo mailto:r-sig-...@r-project.org>>
>  > Sent: Wed, Jun 5, 2019 10:52 am
>  > Subject: Re: [R] Plotting more than one regression line in ggplot
>  >
>  > Hello,
>  >
>  > This is pretty basic ggplot.
>  >
>  >
>  > lm1 <- ggplot(onepctCO2MEDIAN, aes(x, y)) +
>  >    geom_point(colour = 'blue') +
>  >    geom_smooth(method = 'lm')
>  >
>  > lm1
>  >
>  >
>  > If you want to combine several datasets, you will have to have a
>  > variable telling which dataset is which. In the example below, this is
>  > column 'id'.
>  >
>  >
>  > onepctCO2MEDIAN2 <- onepctCO2MEDIAN
>  > onepctCO2MEDIAN2$y <- jitter(onepctCO2MEDIAN2$y) + 2
>  > onepctCO2MEDIAN$id <- 1
>  > onepctCO2MEDIAN2$id <- 2
>  > df2 <- rbind(onepctCO2MEDIAN, onepctCO2MEDIAN2)
>  >
>  > ggplot(df2, aes(x, y, group = id, colour = factor(id))) +
>  >    geom_point() +
>  >    geom_smooth(method = 'lm')
>  >
>  >
>  > Hope this helps,
>  >
>  > Rui Barradas
>  >
>  > Às 15:21 de 05/06/19, rain1290--- via R-help escreveu:
>  >  > I am trying to plot, using ggplot, a series of scatter plots with
>  > regression lines for several datasets. I started with the following
>  > dataset, "onepectCO2MEDIAN". The data for this dataset is as follows:
>  >  >      onepctCO2MEDIAN
>  >  >      x  y
>  >  >      layer.1   0.0  0.000
>  >  >      layer.2   0.006794447  4.9002490
>  >  >      layer.3   0.014288058  0.1608000
>  >  >      layer.4   0.022087920  6.6349133
>  >  >      layer.5   0.030797357 -1.2429506
>  >  >      layer.6   0.038451072  1.5643374
>  >  >      layer.7   0.048087904 -2.2659035
>  >  >      layer.8   0.058677729  2.2070045
>  >  >      layer.9   0.069261406 -2.3677001
>  >  >      

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
 RCP4.5MEDIAN 191 0.987694790 y 0.20892853 RCP4.5MEDIAN 192 
> 0.994548581 y
>  >  > -1.52787222 RCP4.5MEDIAN 193 1.001274595 y -0.72374597 
> RCP4.5MEDIAN 194
>  >  > 1.007810612 y 2.26062309 RCP4.5MEDIAN 195 1.014270389 y -2.40270340
>  >  > RCP4.5MEDIAN 196 1.022719711 y -1.94548262 RCP4.5MEDIAN 197 
> 1.032070810
>  >  > y -1.13053235 RCP4.5MEDIAN 198 1.041118812 y 0.56107969 
> RCP4.5MEDIAN 199
>  >  > 1.050189571 y 3.27941835 RCP4.5MEDIAN 200 1.059380475 y 3.01333588
>  >  > RCP4.5MEDIAN 201 1.067877585 y 4.87457336 RCP4.5MEDIAN 202 
> 1.076078766 y
>  >  > 1.02457895 RCP4.5MEDIAN 203 1.084707357 y 4.49174869 RCP4.5MEDIAN 204
>  >  > 1.093223180 y 8.24629303 RCP4.5MEDIAN 205 1.101414382 y -0.03364132
>  >  > RCP4.5MEDIAN 206 1.108886304 y 9.12509848 RCP4.5MEDIAN 207 
> 1.115482896 y
>  >  > 1.74254621 RCP4.5MEDIAN 208 1.121856558 y 2.27004536 RCP4.5MEDIAN 209
>  >  > 1.127809421 y -0.65627179 RCP4.5MEDIAN 210 1.133265961 y 12.02566969
>  >  > RCP4.5MEDIAN 211 1.138549712 y -1.04260843 RCP4.5MEDIAN 212 
> 1.143910237
>  >  > y -6.47611327 RCP4.5MEDIAN 213 1.149437787 y 8.88410567 
> RCP4.5MEDIAN 214
>  >  > 1.154488347 y -4.24916247 RCP4.5MEDIAN 215 1.159872903 y 7.90741918
>  >  > RCP4.5MEDIAN 216 1.165477487 y -3.91386711 RCP4.5MEDIAN 217 
> 1.171103424
>  >  > y 1.02370701 RCP4.5MEDIAN 218 1.177498256 y -3.71206616 
> RCP4.5MEDIAN 219
>  >  > 1.184003888 y -1.05694182 RCP4.5MEDIAN 220 1.190395856 y 1.10501459
>  >  > RCP4.5MEDIAN 221 1.197284280 y 2.67668639 RCP4.5MEDIAN 222 
> 1.204590551 y
>  >  > 2.21693031 RCP4.5MEDIAN 223 1.210807614 y 2.90252830 RCP4.5MEDIAN 224
>  >  > 1.216470664 y 2.75093766 RCP4.5MEDIAN 225 1.221914148 y -0.73815245
>  >  > RCP4.5MEDIAN 226 1.227580480 y 3.58554626 RCP4.5MEDIAN 227 
> 1.233317788 y
>  >  > 10.89961658 RCP4.5MEDIAN 228 1.238093406 y 3.23374387 RCP4.5MEDIAN 229
>  >  > 0.466622908 y -1.92366466 RCP8.5MEDIAN 230 0.474211509 y 4.09292949
>  >  > RCP8.5MEDIAN 231 0.480383051 y -0.84736312 RCP8.5MEDIAN 232 
> 0.486304903
>  >  > y -0.80597889 RCP8.5MEDIAN 233 0.492151615 y -0.50244413 RCP8.5MEDIAN
>  >  > 234 0.499312643 y 3.07785701 RCP8.5MEDIAN 235 0.508859905 y 
> -6.15175322
>  >  > RCP8.5MEDIAN 236 0.518758845 y -0.51590144 RCP8.5MEDIAN 237 
> 0.528675758
>  >  > y 3.33135956 RCP8.5MEDIAN 238 0.538928423 y 2.62280891 
> RCP8.5MEDIAN 239
>  >  > 0.549621221 y -6.90096009 RCP8.5MEDIAN 240 0.560062840 y -3.45706029
>  >  > RCP8.5MEDIAN 241 0.570860791 y 1.36192518 RCP8.5MEDIAN 242 
> 0.581923368 y
>  >  > 0.34822359 RCP8.5MEDIAN 243 0.592628298 y 3.06882935 RCP8.5MEDIAN 244
>  >  > 0.604230648 y -3.56142825 RCP8.5MEDIAN 245 0.615975167 y 10.35932554
>  >  > RCP8.5MEDIAN 246 0.627448279 y 10.21751629 RCP8.5MEDIAN 247 
> 0.639401050
>  >  > y 3.31040335 RCP8.5MEDIAN 248 0.651949591 y -0.53558775 
> RCP8.5MEDIAN 249
>  >  > 0.664634427 y 2.66081860 RCP8.5MEDIAN 250 0.677343552 y 3.21379656
>  >  > RCP8.5MEDIAN Maybe something like this?
>  >  >
>  >  > lusher<-ggplot(NewestdataULTRA) +
>  >  > geom_jitter(aes(x,value,onepctCO2MEDIAN=L1), colour="green") +
>  >  > geom_smooth(aes(x, value, onepctCO2MEDIAN=L1), method=lm) +
>  >  > geom_jitter(aes(x, value, RCP8.5MEDIAN=L1), colour="red")**//___^
>  >  > **//___^
>  >  > I receive this warning, however:
>  >  >
>  >  > Warning:Ignoring unknown aesthetics: onepctCO2MEDIAN Warning:Ignoring
>  >  > unknown aesthetics: onepctCO2MEDIAN
>  >  >
>  >  > **//___^
>  >  > Perhaps I am not assigning the columns properly? Essentially, I just
>  >  > want create two scatter plots and two regression lines for these two
>  >  > objects.
>  >  >
>  >  > Once again, any assistance would be greatly appreciated!
>  >  >
>  >  > -Original Message-
>  >  > From: Rui Barradas  <mailto:ruipbarra...@sapo.pt> <mailto:ruipbarra...@sapo.pt 
> <mailto:ruipbarra...@sapo.pt>>>
>  >  > To: rain1290 mailto:rain1...@aim.com> 
> <mailto:rain1...@aim.com <mailto:rain1...@aim.com>>>; r-help
>  > mailto:r-help@R-project.org> 
> <mailto:r-help@R-project.org <mailto:r-help@R-project.org>>>;
>  >  > r-sig-geo  <mailto:r-sig-...@r-project.org> <mailto:r-sig-...@r-project.org 
> <mailto:r-sig-...@r-project.org>>>
>  >  > Sent: Wed, Jun 5, 2019 10:52 am
>  >  > Subject: Re: [R] Plotting more than one regression line in ggplot
>  >  >

Re: [R] Plotting more than one regression line in ggplot

2019-06-06 Thread rain1290--- via R-help
6722666 y
>  >  >  > 3.30007615 RCP4.5MEDIAN 158 0.658285673 y -0.79555442 
> RCP4.5MEDIAN 159
>  >  >  > 0.670250852 y -2.05220500 RCP4.5MEDIAN 160 0.681702690 y 
> -5.56808946
>  >  >  > RCP4.5MEDIAN 161 0.693531145 y 2.24168605 RCP4.5MEDIAN 162
>  > 0.706016061 y
>  >  >  > -4.83673351 RCP4.5MEDIAN 163 0.718231249 y 0.40086819 
> RCP4.5MEDIAN 164
>  >  >  > 0.730190911 y -1.98026992 RCP4.5MEDIAN 165 0.741269845 y 0.39963115
>  >  >  > RCP4.5MEDIAN 166 0.751000321 y -0.83241777 RCP4.5MEDIAN 167
>  > 0.760886972
>  >  >  > y -1.66101404 RCP4.5MEDIAN 168 0.771137164 y -1.05452982 
> RCP4.5MEDIAN
>  >  >  > 169 0.781856383 y -1.18338156 RCP4.5MEDIAN 170 0.792607542 y
>  > 0.22722653
>  >  >  > RCP4.5MEDIAN 171 0.803724128 y -1.90642564 RCP4.5MEDIAN 172
>  > 0.815066246
>  >  >  > y 0.75010550 RCP4.5MEDIAN 173 0.826027437 y -1.31108646
>  > RCP4.5MEDIAN 174
>  >  >  > 0.836766732 y 1.05961515 RCP4.5MEDIAN 175 0.847553312 y -2.06588010
>  >  >  > RCP4.5MEDIAN 176 0.858331452 y 8.53403315 RCP4.5MEDIAN 177
>  > 0.869154422 y
>  >  >  > 0.09979751 RCP4.5MEDIAN 178 0.879572539 y -2.50854353 
> RCP4.5MEDIAN 179
>  >  >  > 0.889426601 y 5.29550783 RCP4.5MEDIAN 180 0.899009805 y 2.02909481
>  >  >  > RCP4.5MEDIAN 181 0.908289566 y 2.66922982 RCP4.5MEDIAN 182
>  > 0.917284978 y
>  >  >  > -4.17757196 RCP4.5MEDIAN 183 0.926128960 y 3.40202916 
> RCP4.5MEDIAN 184
>  >  >  > 0.934752874 y -1.92292218 RCP4.5MEDIAN 185 0.943010943 y 6.36969150
>  >  >  > RCP4.5MEDIAN 186 0.950999217 y 1.86490308 RCP4.5MEDIAN 187
>  > 0.958795701 y
>  >  >  > 8.32126161 RCP4.5MEDIAN 188 0.966310396 y 10.15048356 
> RCP4.5MEDIAN 189
>  >  >  > 0.973635493 y 6.68925964 RCP4.5MEDIAN 190 0.980834088 y -1.01615369
>  >  >  > RCP4.5MEDIAN 191 0.987694790 y 0.20892853 RCP4.5MEDIAN 192
>  > 0.994548581 y
>  >  >  > -1.52787222 RCP4.5MEDIAN 193 1.001274595 y -0.72374597
>  > RCP4.5MEDIAN 194
>  >  >  > 1.007810612 y 2.26062309 RCP4.5MEDIAN 195 1.014270389 y -2.40270340
>  >  >  > RCP4.5MEDIAN 196 1.022719711 y -1.94548262 RCP4.5MEDIAN 197
>  > 1.032070810
>  >  >  > y -1.13053235 RCP4.5MEDIAN 198 1.041118812 y 0.56107969
>  > RCP4.5MEDIAN 199
>  >  >  > 1.050189571 y 3.27941835 RCP4.5MEDIAN 200 1.059380475 y 3.01333588
>  >  >  > RCP4.5MEDIAN 201 1.067877585 y 4.87457336 RCP4.5MEDIAN 202
>  > 1.076078766 y
>  >  >  > 1.02457895 RCP4.5MEDIAN 203 1.084707357 y 4.49174869 
> RCP4.5MEDIAN 204
>  >  >  > 1.093223180 y 8.24629303 RCP4.5MEDIAN 205 1.101414382 y -0.03364132
>  >  >  > RCP4.5MEDIAN 206 1.108886304 y 9.12509848 RCP4.5MEDIAN 207
>  > 1.115482896 y
>  >  >  > 1.74254621 RCP4.5MEDIAN 208 1.121856558 y 2.27004536 
> RCP4.5MEDIAN 209
>  >  >  > 1.127809421 y -0.65627179 RCP4.5MEDIAN 210 1.133265961 y 
> 12.02566969
>  >  >  > RCP4.5MEDIAN 211 1.138549712 y -1.04260843 RCP4.5MEDIAN 212
>  > 1.143910237
>  >  >  > y -6.47611327 RCP4.5MEDIAN 213 1.149437787 y 8.88410567
>  > RCP4.5MEDIAN 214
>  >  >  > 1.154488347 y -4.24916247 RCP4.5MEDIAN 215 1.159872903 y 7.90741918
>  >  >  > RCP4.5MEDIAN 216 1.165477487 y -3.91386711 RCP4.5MEDIAN 217
>  > 1.171103424
>  >  >  > y 1.02370701 RCP4.5MEDIAN 218 1.177498256 y -3.71206616
>  > RCP4.5MEDIAN 219
>  >  >  > 1.184003888 y -1.05694182 RCP4.5MEDIAN 220 1.190395856 y 1.10501459
>  >  >  > RCP4.5MEDIAN 221 1.197284280 y 2.67668639 RCP4.5MEDIAN 222
>  > 1.204590551 y
>  >  >  > 2.21693031 RCP4.5MEDIAN 223 1.210807614 y 2.90252830 
> RCP4.5MEDIAN 224
>  >  >  > 1.216470664 y 2.75093766 RCP4.5MEDIAN 225 1.221914148 y -0.73815245
>  >  >  > RCP4.5MEDIAN 226 1.227580480 y 3.58554626 RCP4.5MEDIAN 227
>  > 1.233317788 y
>  >  >  > 10.89961658 RCP4.5MEDIAN 228 1.238093406 y 3.23374387 
> RCP4.5MEDIAN 229
>  >  >  > 0.466622908 y -1.92366466 RCP8.5MEDIAN 230 0.474211509 y 4.09292949
>  >  >  > RCP8.5MEDIAN 231 0.480383051 y -0.84736312 RCP8.5MEDIAN 232
>  > 0.486304903
>  >  >  > y -0.80597889 RCP8.5MEDIAN 233 0.492151615 y -0.50244413 
> RCP8.5MEDIAN
>  >  >  > 234 0.499312643 y 3.07785701 RCP8.5MEDIAN 235 0.508859905 y
>  > -6.15175322
>  >  >  > RCP8.5MEDIAN 236 0.518758845 y -0.51590144 RCP8.5MEDIAN 237
>  > 0.528675758
>  >  >  > y 3.33135956 RCP8.5MEDIAN 238 0.538928423 y 2.62280891
>  > RCP8.5MEDIAN 239
>  >  >  > 0.549621221 y -6.90096009 RCP8.5MED