Re: [R] date conversion problem
Hi Jim, Thanks for the hint, that makes sense and I'll arrange accordingly. Best regards, Abdoulaye On Thu, Aug 13, 2020 at 8:38 AM Jim Lemon wrote: > Hi Abdoulaye, > It looks to me as though your offsets are in hours, not days. You can > get a rough date like this: > > time<-c(1569072,1569096,1569120,1569144, > 1569168,1569192,1569216,1569240) > time_d<-as.Date("1800-01-01")+time/24 > time_d > [1] "1979-01-01" "1979-01-02" "1979-01-03" "1979-01-04" "1979-01-05" > [6] "1979-01-06" "1979-01-07" "1979-01-08" > > Jim > > On Thu, Aug 13, 2020 at 6:10 PM Abdoulaye Sarr > wrote: > > > > I have dataset with time sine 1800-01-01 and extracted data from 1981 to > > 2019 and used these lines for the data conversion: > > > time_d <- as.Date(time, format="%j", origin=as.Date("1800-01-01")) > > > time_years <- format(time_d, "%Y") > > > time_months <- format(time_d, "%m") > > > time_year_months <- format(time_d, "%Y-%m") > > > head(time_d) > > [1] "6095-12-22" "6096-01-15" "6096-02-08" "6096-03-03" "6096-03-27" > > "6096-04-20" > > > > As you see these gregorian dates are unrealistic and wonder what I am > doing > > wrong? > > The time from the raw file in Jd are like this: > > > > > time > >[1] 1569072 1569096 1569120 1569144 1569168 1569192 1569216 > 1569240etc. > > > > Hope hint and/or suggestion to solve this. > > > > Best regards > > > > [[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.
[R] date conversion problem
I have dataset with time sine 1800-01-01 and extracted data from 1981 to 2019 and used these lines for the data conversion: > time_d <- as.Date(time, format="%j", origin=as.Date("1800-01-01")) > time_years <- format(time_d, "%Y") > time_months <- format(time_d, "%m") > time_year_months <- format(time_d, "%Y-%m") > head(time_d) [1] "6095-12-22" "6096-01-15" "6096-02-08" "6096-03-03" "6096-03-27" "6096-04-20" As you see these gregorian dates are unrealistic and wonder what I am doing wrong? The time from the raw file in Jd are like this: > time [1] 1569072 1569096 1569120 1569144 1569168 1569192 1569216 1569240etc. Hope hint and/or suggestion to solve this. Best regards [[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] Fwd: problem writing .bil files in netcdf
-- Forwarded message -- From: Abdoulaye SARR <abdoulaye...@gmail.com> Date: Mon, Jan 1, 2001 at 4:02 AM Subject: Re: [R] problem writing .bil files in netcdf To: Michael Sumner <mdsum...@gmail.com> Cc: r-help@r-project.org Hi Michael, I had a problem with my mac hopefully solve now. For the issue i submitted, I tried your suggestion with writeRaster which creates a netcdf file. The problem when I look the results by displaying as graph I seen the values starting by -9000 and mainly are located in the continent boundaries, so how to add in write taste the undef values and have precip from 0 to x. For the loop if successful is toe write each day in a separate netcdf file, if done it will be easy to concatenate using nco or cdo. To convert each day in netcdf I need to have an appropriate loop in a script. I have to process many years. Cheers, Le 2 sept. 2016 à 15:09, Michael Sumner <mdsum...@gmail.com> a écrit : On Fri, 2 Sep 2016 at 00:43 Abdoulaye SARR <abdoulaye...@gmail.com> wrote: > Dear List, > > I have daily rainfall data in .bil format and can get info of the file > using rgdal: > > > library(rgdal) > > GDALinfo("/1981/v2p19810101.bil") > rows1600 > columns 1500 > bands 1 > lower left origin.x-20 > lower left origin.y-40 > res.x 0.05 > res.y 0.05 > ysign -1 > oblique.x 0 > oblique.y 0 > driver EHdr > projection NA > > How can I read all daily file and write them as netcdf files and > concatenate as one yearly file and also avoid boundary pixels alter > rainfall values. > > Hi, You can read the single .bil and write it to NetCDF with raster (and the rgdal and ncdf4) package: library(raster) r <- raster("/1981/v2p19810101.bil") writeRaster(r, "v2p19810101.nc") But, if you read in multi .bil files and build a multilayer raster, i.e. st <- stack(list.files("/1981", pattern = "bil$", full.names = TRUE)) you *can* write it out to NetCDF, very similar to above with writeRaster, but I think it will generate a variable (an netcdf array) for each layer. To really write to .nc in a specific way you'll need to delve into the standard tools in ncdf4, to create a file, create variables/dimensions/attributes, and then populate the variable, in this case probably one 3rd-level slice for each .bil. That might be better done at the command line, say with nco (the "nc operators"). There are copy-create idioms which is probably the way to go if you have a template data file or CDF specification. There may be some higher level tools in other packages on CRAN, check the reverse depends/imports/suggests on CRAN for ncdf4. Also you should explore RNetCDF which has an independent implementation. (raster really blitzes the field in terms of high-level tools here, but it has limits, with writing NetCDF *in specific ways* being one of them. GDAL has similar limitations, since it sees the world in this "array-as-2d-bands" way). HTH, at least a little. Cheers, Mike. Best regards, > > Eus > > __ > 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 <http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. > -- Dr. Michael Sumner Software and Database Engineer Australian Antarctic Division 203 Channel Highway Kingston Tasmania 7050 Australia [[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] problem writing .bil files in netcdf
Dear List, I have daily rainfall data in .bil format and can get info of the file using rgdal: > library(rgdal) > GDALinfo("/1981/v2p19810101.bil") rows1600 columns 1500 bands 1 lower left origin.x-20 lower left origin.y-40 res.x 0.05 res.y 0.05 ysign -1 oblique.x 0 oblique.y 0 driver EHdr projection NA How can I read all daily file and write them as netcdf files and concatenate as one yearly file and also avoid boundary pixels alter rainfall values. Best regards, Eus __ 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] probelm with xlab ylab and xaxp barplot
Hi Marc, I have something very close now, and think to leave it like that. Thank you so much for your help to solve the problem. Cheers, asarr On Mon, Jul 25, 2016 at 6:03 PM, Marc Schwartz <marc_schwa...@me.com> wrote: > Hi, > > First, I noted again that you still have: > >xaxp=c(181,2005,1) > > in the first barplot() call. Get rid of that, as barplot() does not use > normal axis ranges for the bar midpoints. > > Second, I do not see an indication that you are using the 'names.arg' > argument in barplot(), which supplies the vector of text to place below > each bar. If this is correct, then you want the basic barplot() call to > look something like: > > barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", > names.arg = 1981:2005, > col=ifelse(z1>0,"green","brown")) > > where names.arg on the second line is the vector of years from 1981 to > 2005. If the data passed to barplot() have name attributes (for example, > they are the result of using table() on a vector), those would be used, but > I am guessing that your z* vectors are just numeric vectors without labels. > > If you then need to further adjust the axes to make more room below the > plots, adjust the first element of par(mar) until the default axes show. > > For example: > > par(mar = c(6, 4, 4, 2)) > > where 6 replaces the default 5 for the first element. You may need to go > higher if the text is still not showing. If need be, increase it further > slowly to view the impact. You can also change by less than a full integer > (e.g. 5.5, 6.25, etc.) as you may need. At some point, you will overshoot > with too much room and you can then back down slowly. > > Using this approach, each plot will have a similar size as you adjust the > margins and then look similar visually, presuming that the axis ranges are > the same for each. > > Regards, > > Marc > > > > On Jul 25, 2016, at 11:56 AM, Abdoulaye SARR <abdoulaye...@gmail.com> > wrote: > > > > Hi Marc, > > > > According to your guidance the labels are almost at the right place when > adjusting mar values. > > > > A remaining need is to have the x axis at least for the two bottom > figures as date from 1981 to 2005. Do you think this is doable. Ylim is > fine but how tots in this case xlim. > > > > Best regards, > > > > asarr > > Le 25 juil. 2016 à 14:28, Marc Schwartz <marc_schwa...@me.com> a écrit : > > > >> Hi, > >> > >> If your code below is a verbatim copy and paste, you still have the > following two lines active: > >> > >> par(mar=rep(2,4)) > >> > >> and > >> > >> op <- par(oma=c(1,2,3,5)) > >> > >> Comment out both of those lines and then see what the result looks like. > >> > >> As I noted before, try the plot **without any modifications** to the > default margin values. Then adjust from there, which may require you to > increase, not decrease, the values from their defaults in order to have > room for your text. > >> > >> The values you have for par(mar) above, for example, reduce the values > to 2 for each side from the default, which is: > >> > >> c(5, 4, 4, 2) + 0.1. > >> > >> So that alone will likely result in there not being enough room for > your axis labels. > >> > >> You may also have to create the barplot without any default annotation > created by the function itself and then add it with ?axis, ?text and > ?mtext. You may also have to reduce the size of the font itself, which is > done via the cex* arguments to barplot() and the additional annotation > functions mentioned in the prior sentence. > >> > >> Regards, > >> > >> Marc > >> > >> > >>> On Jul 25, 2016, at 8:06 AM, Abdoulaye SARR <abdoulaye...@gmail.com> > wrote: > >>> > >>> > >>>>> Hi Marc and Others, > >>> > >>> > >>> I am still struggling to have my slab and ylab displayed on a bar > plot. Marc did useful advise on playing with mar settings. I tried may > combinations and can�t have it work. > >>> > >>> I paste the code I am suing hoping guidance on solving this issue. > >>> > >>> > >>> > >>> > >>> ## extract works for all time steps > >>> d1<-read.nc(gp) > >>> > >>> d2<-read.nc(er) > >>> > >>> d3<-read.nc(me) > >>> > >>> d4<-read.nc(ne) > >>&
Re: [R] probelm with xlab ylab and xaxp barplot
Hi Marc, According to your guidance the labels are almost at the right place when adjusting mar values. A remaining need is to have the x axis at least for the two bottom figures as date from 1981 to 2005. Do you think this is doable. Ylim is fine but how tots in this case xlim. Best regards, asarr Le 25 juil. 2016 à 14:28, Marc Schwartz <marc_schwa...@me.com> a écrit : > Hi, > > If your code below is a verbatim copy and paste, you still have the following > two lines active: > > par(mar=rep(2,4)) > > and > > op <- par(oma=c(1,2,3,5)) > > Comment out both of those lines and then see what the result looks like. > > As I noted before, try the plot **without any modifications** to the default > margin values. Then adjust from there, which may require you to increase, not > decrease, the values from their defaults in order to have room for your text. > > The values you have for par(mar) above, for example, reduce the values to 2 > for each side from the default, which is: > > c(5, 4, 4, 2) + 0.1. > > So that alone will likely result in there not being enough room for your axis > labels. > > You may also have to create the barplot without any default annotation > created by the function itself and then add it with ?axis, ?text and ?mtext. > You may also have to reduce the size of the font itself, which is done via > the cex* arguments to barplot() and the additional annotation functions > mentioned in the prior sentence. > > Regards, > > Marc > > >> On Jul 25, 2016, at 8:06 AM, Abdoulaye SARR <abdoulaye...@gmail.com> wrote: >> >> >>>> Hi Marc and Others, >> >> >> I am still struggling to have my slab and ylab displayed on a bar plot. Marc >> did useful advise on playing with mar settings. I tried may combinations and >> can�t have it work. >> >> I paste the code I am suing hoping guidance on solving this issue. >> >> >> >> >> ## extract works for all time steps >> d1<-read.nc(gp) >> >> d2<-read.nc(er) >> >> d3<-read.nc(me) >> >> d4<-read.nc(ne) >> >> d5<-read.nc(ar) >> >> d6<-read.nc(cc) >> >> d7<-read.nc(mr) >> >> d8<-read.nc(ic) >> >> z1<-d1$spei >> z2<-d2$spei >> z3<-d3$spei >> z4<-d4$spei >> z5<-d5$spei >> z6<-d6$spei >> z7<-d7$spei >> z8<-d8$spei >> #par(oma=c(2,2,2,2)) # all sides have 3 lines of space >> >> par(mar=rep(2,4)) >> #par(mar=c(5.1, 4.1, 2.1, 2.1)) >> #par(mai=c(1.02,0.82,0.82,0.42)) >> op <- par(oma=c(1,2,3,5)) >> #op <- par(oma=c(6,5,0,0)) >> par(mfrow=c(4,2)) >> >> line = 3 >> >> barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), >> col=ifelse(z1>0,"green","brown")) >> >> mtext("a") >> barplot(z2,xlab="Years", ylab="spei", ylim=c(-2,2), >> col=ifelse(z2>0,"green","brown")) >> mtext("b") >> barplot(z3, ylim=c(-2,2), xlab="Years", ylab="spei", >> col=ifelse(z3>0,"green","brown")) >> mtext("c") >> barplot(z4, xlab="Years", ylab="spei", ylim=c(-2,2), >> col=ifelse(z4>0,"green","brown")) >> mtext("d") >> barplot(z5, xlab="Years", ylab="spei", ylim=c(-2,2), >> col=ifelse(z5>0,"green","brown")) >> mtext("e") >> barplot(z6, xlab="Years", ylab="spei", ylim=c(-2,2), >> col=ifelse(z6>0,"green","brown")) >> mtext("f") >> barplot(z7,xlab="Years", ylab="spei", ylim=c(-2,2), >> col=ifelse(z7>0,"green","brown")) >> mtext("g") >> barplot(z8, ylim=c(-2,2), xlab="Years", ylab="spei", >> col=ifelse(z8>0,"green","brown")) >> mtext("h") >> par(op) >> >> Another solution with ggplot2 or lattice also welcome. >> >> >> Best regards, >> >> asarr > > [[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] probelm with xlab ylab and xaxp barplot
>> Hi Marc and Others, I am still struggling to have my slab and ylab displayed on a bar plot. Marc did useful advise on playing with mar settings. I tried may combinations and can�t have it work. I paste the code I am suing hoping guidance on solving this issue. ## extract works for all time steps d1<-read.nc(gp) d2<-read.nc(er) d3<-read.nc(me) d4<-read.nc(ne) d5<-read.nc(ar) d6<-read.nc(cc) d7<-read.nc(mr) d8<-read.nc(ic) z1<-d1$spei z2<-d2$spei z3<-d3$spei z4<-d4$spei z5<-d5$spei z6<-d6$spei z7<-d7$spei z8<-d8$spei #par(oma=c(2,2,2,2)) # all sides have 3 lines of space par(mar=rep(2,4)) #par(mar=c(5.1, 4.1, 2.1, 2.1)) #par(mai=c(1.02,0.82,0.82,0.42)) op <- par(oma=c(1,2,3,5)) #op <- par(oma=c(6,5,0,0)) par(mfrow=c(4,2)) line = 3 barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), col=ifelse(z1>0,"green","brown")) mtext("a") barplot(z2,xlab="Years", ylab="spei", ylim=c(-2,2), col=ifelse(z2>0,"green","brown")) mtext("b") barplot(z3, ylim=c(-2,2), xlab="Years", ylab="spei", col=ifelse(z3>0,"green","brown")) mtext("c") barplot(z4, xlab="Years", ylab="spei", ylim=c(-2,2), col=ifelse(z4>0,"green","brown")) mtext("d") barplot(z5, xlab="Years", ylab="spei", ylim=c(-2,2), col=ifelse(z5>0,"green","brown")) mtext("e") barplot(z6, xlab="Years", ylab="spei", ylim=c(-2,2), col=ifelse(z6>0,"green","brown")) mtext("f") barplot(z7,xlab="Years", ylab="spei", ylim=c(-2,2), col=ifelse(z7>0,"green","brown")) mtext("g") barplot(z8, ylim=c(-2,2), xlab="Years", ylab="spei", col=ifelse(z8>0,"green","brown")) mtext("h") par(op) Another solution with ggplot2 or lattice also welcome. Best regards, asarr >> >> >> On Wed, Jul 20, 2016 at 6:03 PM, Marc Schwartz <marc_schwa...@me.com> wrote: >> >> > On Jul 20, 2016, at 4:00 AM, Abdoulaye SARR <abdoulaye...@gmail.com> wrote: >> > >> > I have the color of my bar plot displayed correctly but don�t have xlab, >> > ylab and xaxp don�t show up. >> > >> > here is example of yearly data (25 years 1981-2005) >> >> head(z1) >> > [1] -0.1001726 0.2014272 -0.8556950 0.1920669 -0.8013520 1.3324949 >> > >> > code to display values >> > >> > par(mar=rep(2,4)) >> > op <- par(oma=c(5,7,1,1)) >> > par(mfrow=c(4,2)) >> > >> > line = 3 >> > >> > barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), >> > col=ifelse(z1>0,"green","brown �)) >> > >> > hoe help on this issue >> > >> > Fipou >> >> >> Hi, >> >> First, a general comment, which is that barplots are typically good for >> displaying counts and percentages, not continuous data points or perhaps >> estimates of means, etc. Your values for z1 above, suggest that you might be >> better off just plotting the points on the y axis against the years on the x >> axis. That is, for example: >> >> plot(1981:2005, z1, col = ifelse(z1 > 0, "green", "brown"), >>ylab = "spei", xlab = "Years", pch = 19) >> >> presuming that z1 has 25 values. >> >> That being said, some additional notes to hopefully guide you here with >> barplot(): >> >> 1. You appear to be wanting to plot a matrix of 8 plots in a 4 row by 2 >> column matrix. That is fine, but note that changing the graphic parameters >> associated with the spacing of margins, etc. in a matrix don't always >> provide a result similar to what you might find in a single plot. I would >> start by not adjusting par(mar) and par(oma) from their default values to >> get an idea of what the plot looks like with default settings and then >> modify from there so that you can see how any adjustments affect the result. >> You may be adjusting the margins for each plot and the outer margins of the >> overall matrix in a manner that conflicts. >> >> >> 2. In the case of a vertical barplot, the bars are not centered around >> integer values on the x axis, as they would be in say a boxplot. In the help >> for barplot() you will note that the Value section indicates that barplot >> returns a vector (by default) o
[R] probelm with xlab ylab and xaxp barplot
I have the color of my bar plot displayed correctly but don’t have xlab, ylab and xaxp don’t show up. here is example of yearly data (25 years 1981-2005) > head(z1) [1] -0.1001726 0.2014272 -0.8556950 0.1920669 -0.8013520 1.3324949 code to display values par(mar=rep(2,4)) op <- par(oma=c(5,7,1,1)) par(mfrow=c(4,2)) line = 3 barplot(z1, ylim=c(-2,2), xlab="Years", ylab="spei", xaxp=c(181,2005,1), col=ifelse(z1>0,"green","brown »)) hoe help on this issue Fipou __ 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] barplot colour problem
Thank you Marc, The typo was causing the problem, solved now. Regards, Fipou On Mon, Jul 18, 2016 at 8:38 PM, Marc Schwartz <marc_schwa...@me.com> wrote: > > > On Jul 18, 2016, at 1:06 PM, Abdoulaye Sarr <abdoulaye...@gmail.com> > wrote: > > > > I am doing a basic bar plot which works but the color of bars positive > > (green) and negative (brown) don’t show up from the below command: > > > > barplot(z, ylim=c(-2,2), col=ifelse(x>0,"brown","green »)) > > > > any help? or other methods? > > > > fipou > > > Presuming that the above is a direct copy and paste, your ifelse() > statement is using 'x' to determine the color, rather than 'z'. Presumably > a typo? > > This works, for example, with 'z' as a vector: > > z <- seq(from = -5, to = 5) > > barplot(z, col = ifelse(z > 0, "brown", "green")) > > > Regards, > > Marc Schwartz > > > [[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] barplot colour problem
I am doing a basic bar plot which works but the color of bars positive (green) and negative (brown) don’t show up from the below command: barplot(z, ylim=c(-2,2), col=ifelse(x>0,"brown","green »)) any help? or other methods? fipou [[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] color problem barplot
I am doing a basic bar plot which works but the color of bars positive (green) and negative (brown) don’t show up from the below command: barplot(z, ylim=c(-2,2), col=ifelse(x>0,"brown","green »)) any help? or other methods? asarr __ 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.