Re: [R] add error bars to rarecurve from package vegan

2019-10-21 Thread Duncan Mackay
Hi Luigi

Using the help example for vegan:: rarefy 
It appears that the example for vegan:: rarefy does not work for SE=T
in the plot command the x values (S) are a vector and  yvalues Srare is a
list

It appears that the argument se = TRUE is not coded
So that your commands cannot produce error bars

Suggest contacting the maintainer

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Tuesday, 22 October 2019 01:44
To: Eric Berger
Cc: r-help
Subject: Re: [R] add error bars to rarecurve from package vegan

sorry there was a typo: it is `se = TRUE` but the result is the same:
SE is not a rarecurve's parameter.

On Mon, Oct 21, 2019 at 4:41 PM Luigi Marongiu 
wrote:
>
> I did not put an example because it is a question of the basic syntax
> of this function, not about the data at hand. However, here is a
> working example:
>
> ```
> library(vegan)
> data(dune)
> spAbund <- rowSums(dune)
> raremin <- min(rowSums(dune))
> rarecurve(dune, col = "blue", es = TRUE)
> ```
>
> Thank you
>
> On Mon, Oct 21, 2019 at 2:41 PM Eric Berger  wrote:
> >
> > You might improve your chances for getting a response by supplying
> > a minimal reproducible example. Remember to include all the library()
commands
> > showing which packages you are using.
> >
> >
> > On Mon, Oct 21, 2019 at 2:53 PM Luigi Marongiu
 wrote:
> >>
> >> Hello,
> >> I am using the package vegan to generate rarefaction curves with the
> >> function rarecurve.
> >> Is it possible to add error bars to the plot? I tried to add se =
> >> FALSE but it did not work.
> >> Also, would it be possible to remove the box around the label of the
data?
> >> Thank you
> >>
> >> --
> >> Best regards,
> >> Luigi
> >>
> >> __
> >> 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.
>
>
>
> --
> Best regards,
> Luigi



-- 
Best regards,
Luigi

__
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-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] hist{graphics}

2019-07-14 Thread Duncan Mackay
Also there is 

@ARTICLE{JCGS18-0021,
  author = {Denby, L. and Mallows, C.},
  year = {2009},
  title = {Variations on the histogram},
  journal = {Journal of Computational and Graphical Statistics},
  volume = {18},
  number = {1},
  pages = {21--31},
  doi = {10.1198/jcgs.2009.0002},
  abstract = {When constructing a histogram, it is common to make all bars the 
same
width. One could also choose to make them all have the same area.
These two options have complementary strengths and weaknesses; the
equal-width histogram oversmooths in regions of high density, and
is poor at identifying sharp peaks; the equal-area histogram oversmooths
in regions of low density, and so does not identify outliers. We
describe a compromise approach which avoids both of these defects.
We regard the histogram as an exploratory device, rather than as
an estimate of a density. We argue that relying on the asymptotics
of integrated mean squared error leads to inappropriate recommendations
for choosing bin-widths. Datasets and R codes are available in the
online supplements.},
  keywords = {diagonally-cut histogram; equal-area histogram; asymptotics;
IMSE.},
}

I have not looked at the site for a while but I think it has some code in 
?Splus which should work in R.
This follows a report in the same name which appears to be no longer available 
at the original site which has code 

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of peter dalgaard
Sent: Sunday, 14 July 2019 02:15
To: Duncan Murdoch
Cc: r-help@r-project.org; Steven
Subject: Re: [R] hist{graphics}

Also checkout MASS::truehist or simply consider setting breaks so as not to 
coincide with data values. (hist() not doing something like this, but instead 
actively aiming for pretty breaks is something of a design bug in my book, but 
ancient history and not easy to change at this point in time.)

-pd

> On 13 Jul 2019, at 11:29 , Duncan Murdoch  wrote:
> 
> On 12/07/2019 11:38 a.m., Steven wrote:
>> Never mind. Thanks.
>> I found that adding parameter right=F to the call fixes it.
> 
> Drawing a histogram of discrete data often leads to bad results. Histograms 
> are intended for continuous data, where no observations fall on bin 
> boundaries.
> 
> You often get a more faithful representation of discrete data using something 
> like
> 
> plot(table(x))
> 
> Duncan Murdoch
> 
>> On 2019/7/12 下午 05:10, Steven wrote:
>>> # Can someone help with this simple frequency histogram problem (n = 15)?
>>> # I use four class limits: [90,95], [95,100], [100,105], [105,110].
>>> # These coincide with the limits obtain by pretty {base}.
>>> # Proper frequencies would be: (1,5,6,3).
>>> # But hist{graphics} gives me a histogram showing frequencies (1,8,3,3),
>>> # with or without argument break = ...
>>> # Replicable codes below. Thanks.
>>> 
>>> set.seed(123)
>>> x<-rnorm(15,mean=100,sd=5); x<-as.integer(x)
>>> x<-sort(x)
>>> x
>>> breaks<-seq(90,110,by=5); breaks
>>> pretty(x,n=5) # pretty {base}
>>> x.cut<-cut(x,breaks,right=F) ; x.cut
>>> freq<-table(x.cut); cbind(freq)
>>> hist(x,breaks=breaks) # hist {graphics}
>>> hist(x)
>>> 
>>> 
>>> 
>> __
>> 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-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.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@gmail.com

__
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-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] placement of plot in rgl

2019-07-01 Thread Duncan Mackay
Dear All

I rarely use the excellent rgl package but have sometimes run into a problem
with placement of the plot within the window.
Up to now I have avoided having to find a solution.

I was going through the series of posts from 
https://stat.ethz.ch/pipermail/r-help/2019-June/463014.html  
when I came across
https://stat.ethz.ch/pipermail/r-help/2019-June/463057.html
where the plot starts in the bottom left corner as a results when moving it
parts of the plot get obscured.

Is there a way around this; forceClipregion and  getr3dDefaults() to me seem
a little sparse on details.
I tried using xyz.coords but no improvement

Code is as follows:

p1 <-
structure(c(0.6, 0.584775906502257, 0.54142135623731, 0.476536686473018, 
0.4, 0.323463313526982, 0.258578643762691, 0.215224093497743, 
0.2, 0.215224093497743, 0.25857864376269, 0.323463313526982, 
0.4, 0.476536686473018, 0.541421356237309, 0.584775906502257, 
0.4, 0.476536686473018, 0.54142135623731, 0.584775906502257, 
0.6, 0.584775906502257, 0.54142135623731, 0.476536686473018, 
0.4, 0.323463313526982, 0.258578643762691, 0.215224093497743, 
0.2, 0.215224093497743, 0.25857864376269, 0.323463313526982, 
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), .Dim = c(16L, 
3L), .Dimnames = list(NULL, c("x1", "y1", "z1")))

p2 <-
structure(c(0.7, 0.684775906502257, 0.64142135623731, 0.576536686473018, 
0.5, 0.423463313526982, 0.35857864376269, 0.315224093497743, 
0.3, 0.315224093497743, 0.35857864376269, 0.423463313526982, 
0.5, 0.576536686473018, 0.641421356237309, 0.684775906502257, 
0.5, 0.576536686473018, 0.641421356237309, 0.684775906502257, 
0.7, 0.684775906502257, 0.64142135623731, 0.576536686473018, 
0.5, 0.423463313526982, 0.35857864376269, 0.315224093497743, 
0.3, 0.315224093497743, 0.35857864376269, 0.423463313526982, 
0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 
0.5, 0.5, 0.5), .Dim = c(16L, 3L), .Dimnames = list(NULL, c("x2", 
"y2", "z2")))

p3 <-
structure(c(0.4, 0.392387953251129, 0.370710678118655, 0.338268343236509, 
0.3, 0.261731656763491, 0.229289321881345, 0.207612046748871, 
0.2, 0.207612046748871, 0.229289321881345, 0.261731656763491, 
0.3, 0.338268343236509, 0.370710678118655, 0.392387953251129, 
0.3, 0.338268343236509, 0.370710678118655, 0.392387953251129, 
0.4, 0.392387953251129, 0.370710678118655, 0.338268343236509, 
0.3, 0.261731656763491, 0.229289321881345, 0.207612046748871, 
0.2, 0.207612046748871, 0.229289321881345, 0.261731656763491, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), .Dim = c(16L, 
3L), .Dimnames = list(NULL, c("x3", "y3", "z3")))

library(rgl)

open3d()

plot3d(p1,
   box = FALSE,
   axes = FALSE,
   xlim = c(0,1),
   ylim = c(0,1),
   zlim = c(0,1),
   xlab = "",
   ylab = "",
   zlab = "",
   type = "n")

points3d(p1, size = 10, col = "red")
points3d(p2, size = 10, col = "blue")
points3d(p3, size = 10, col = "green")

axes3d(c('x', 'y', 'z'))

title3d(xlab = "x", ylab = "y", zlab = "z", line = 1.7)

aspect3d(1,1,1)   

highlevel()

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351

__
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] Unable to Understand Results of pglm function

2019-04-23 Thread Duncan Mackay
Hi Paul

I think you may have too many IDs DATE for your model as you posted

I converted your DATE into date format and named it df3
str(df3)
'data.frame':   527 obs. of  11 variables:
 $ TRANSIT : int  1 1 1 0 1 1 1 1 1 1 ...
 $ ID  : int  1 1 2 2 3 4 5 5 6 7 ...
 $ DATE: Factor w/ 377 levels "1-Aug-17","1-Aug-18",..: 47 75 89 252 3 
221 62 99 224 114 ...
 $ SHIPNAME: Factor w/ 482 levels "Aby Jeannette",..: 295 295 151 151 19 41 
292 292 201 148 ...
 $ Draft   : int  12 12 12 13 12 12 12 12 12 12 ...
 $ TOTALCOST   : int  194364 219364 198260 237456 197159 198992 194337 219337 
199198 196604 ...
 $ BUNKER  : int  350 405 276 350 373 355 370 343 345 288 ...
 $ CHARTERVALUE: int  14000 12825 10475 11850 13250 12100 11875 14500 12500 
10500 ...
 $ dt  : Date, format: "2018-03-15" "2018-08-19" "2017-07-20" 
"2017-12-19" ...
 $ dtym: chr  "201803" "201808" "201707" "201712" ...
 $ dty : chr  "2018" "2018" "2017" "2017" ...

Here are 2 results 

> model1 = pglm(TRANSIT~ Draft+TOTALCOST+BUNKER+CHARTERVALUE + dty,
+  effect=c("time"), 
+  model=c("pooling"), 
+  family=binomial('logit'),
+  index=c("ID"), 
+  start = NULL, data=df3)
> 
> summary(model1)

Maximum Likelihood estimation
Newton-Raphson maximisation, 11 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -14.14988 
6  free parameters
Estimates:
   Estimate Std. error t value Pr(> t)
(Intercept)   1.023e+02Inf   0   1
Draft-5.088e+00Inf   0   1
TOTALCOST-1.708e-04Inf   0   1
BUNKER   -6.712e-03Inf   0   1
CHARTERVALUE  2.524e-04Inf   0   1
dty2018   2.215e+00Inf   0   1


> model1=pglm(TRANSIT~ Draft+TOTALCOST+BUNKER+CHARTERVALUE + dty,
+  effect=c("time"), 
+  model=c("pooling"), 
+  family=binomial('logit'),
+  index=c("ID","dty"), 
+  start = NULL, data=df3)
Warning messages:
1: In pdata.frame(data, index) :
  duplicate couples (id-time) in resulting pdata.frame
 to find out which, use e.g. table(index(your_pdataframe), useNA = "ifany")
2: In is.pbalanced.default(index[[1]], index[[2]]) :
  duplicate couples (id-time)

> 
> summary(model1)

Maximum Likelihood estimation
Newton-Raphson maximisation, 11 iterations
Return code 2: successive function values within tolerance limit
Log-Likelihood: -14.14988 
6  free parameters
Estimates:
   Estimate Std. error t value Pr(> t)
(Intercept)   1.023e+02Inf   0   1
Draft-5.088e+00Inf   0   1
TOTALCOST-1.708e-04Inf   0   1
BUNKER   -6.712e-03Inf   0   1
CHARTERVALUE  2.524e-04Inf   0   1
dty2018   2.215e+00Inf   0   1


I have no knowledge of the pglm package and was trying it out on your data 
without going through the help properly
NBB your DATE column has several formats which do not help

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Bernal
Sent: Wednesday, 24 April 2019 06:44
To: yves.croiss...@univ-reunion.fr
Cc: r-help@r-project.org
Subject: [R] Unable to Understand Results of pglm function

Dear Yves,

Hope you are doing great. I have been testing the pglm function from the
pglm package, in order to fit a logit regression to a panel dataset, and I
do not understand the results and/or errors produced by the function, so I
want to be able to understand whether there is a problem with the structure
of my dataset, or I am not using the function properly or if there is
something else going on that I am ignoring. Also, I would like to know what
the start argument is for, or at least an example of how to use it, since I
don´t know how to properly apply it.

Here the details of what I am using and under what environment settings:
1-R version: 3.5.3
2-packages called: plm and pglm
3-Running on a 64-bit Operating System
4-Windows 8

Here is the code with the different things I have tried so far:
> PGLM_Model11 <-
pglm(dataframe3$TRANSIT~dataframe3$Draft+dataframe3$TOTALCOST+dataframe3$BUNKER+dataframe3$CHARTERVALUE,
effect=c("twoways"), model=c("random"), family=binomial('logit'),
index=c("ID","DATE"), start = NULL, data=dataframe3)
>
> summary(PGLM_M

Re: [R] Define pch and color based on two different columns

2019-04-10 Thread Duncan Mackay
Hi

Here is the caveat
If you want to repeat it with loess? or panel loess something else that is
not groups aware  (I have not checked to see if it has been up dated) have a
look at

https://stat.ethz.ch/pipermail/r-help/2010-August/250050.html

Regards

Duncan Mackay

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Matthew
Snyder
Sent: Wednesday, 10 April 2019 15:03
To: Peter Langfelder
Cc: r-help
Subject: Re: [R] Define pch and color based on two different columns

You are not late to the party. And you solved it!

Thank you very much. You just made my PhD a little closer to reality!

Matt



*Matthew R. Snyder*
*~*
PhD Candidate
University Fellow
University of Toledo
Computational biologist, ecologist, and bioinformatician
Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
matthew.snyd...@rockets.utoledo.edu
msnyder...@gmail.com



[image: Mailtrack]
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=sig
naturevirality5&>
Sender
notified by
Mailtrack
<https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=sig
naturevirality5&>
04/09/19,
10:01:53 PM

On Tue, Apr 9, 2019 at 9:37 PM Peter Langfelder 
wrote:

> Sorry for being late to the party, but has anyone suggested a minor
> but important modification of the code from stack exchange?
>
> xyplot(mpg ~ wt | cyl,
>   panel = function(x, y, ..., groups, subscripts) {
>   pch <- mypch[factor(carb)[subscripts]]
>   col <- mycol[factor(gear)[subscripts]]
>   grp <- c(gear,carb)
>   panel.xyplot(x, y, pch = pch, col = col)
>   }
> )
>
> From the little I understand about what you're trying to do, this may
> just do the trick.
>
> Peter
>
> On Tue, Apr 9, 2019 at 2:43 PM Matthew Snyder 
> wrote:
> >
> > I am making a lattice plot and I would like to use the value in one
> column
> > to define the pch and another column to define color of points.
Something
> > like:
> >
> > xyplot(mpg ~ wt | cyl,
> >data=mtcars,
> >col = gear,
> >pch = carb
> > )
> >
> > There are unique pch points in the second and third panels, but these
> > points are only unique within the plots, not among all the plots (as
they
> > should be). You can see this if you use the following code:
> >
> > xyplot(mpg ~ wt | cyl,
> >data=mtcars,
> >groups = carb
> > )
> >
> > This plot looks great for one group, but if you try to invoke two groups
> > using c(gear, carb) I think it simply takes unique combinations of those
> > two variables and plots them as unique colors.
> >
> > Another solution given by a StackExchange user:
> >
> > mypch <- 1:6
> > mycol <- 1:3
> >
> > xyplot(mpg ~ wt | cyl,
> >   panel = function(x, y, ..., groups, subscripts) {
> >   pch <- mypch[factor(carb[subscripts])]
> >   col <- mycol[factor(gear[subscripts])]
> >   grp <- c(gear,carb)
> >   panel.xyplot(x, y, pch = pch, col = col)
> >   }
> > )
> >
> > This solution has the same problems as the code at the top. I think the
> > issue causing problems with both solutions is that not every value for
> each
> > group is present in each panel, and they are almost never in the same
> > order. I think R is just interpreting the appearance of unique values as
> a
> > signal to change to the next pch or color. My actual data file is very
> > large, and it's not possible to sort my way out of this mess. It would
be
> > best if I could just use the value in two columns to actually define a
> > color or pch for each point on an entire plot. Is there a way to do
this?
> >
> > Ps, I had to post this via email because the Nabble site kept sending me
> an
> > error message: "Message rejected by filter rule match"
> >
> > Thanks,
> > Matt
> >
> >
> >
> > *Matthew R. Snyder*
> > *~*
> > PhD Candidate
> > University Fellow
> > University of Toledo
> > Computational biologist, ecologist, and bioinformatician
> > Sponsored Guest Researcher at NOAA PMEL, Seattle, WA.
> > matthew.snyd...@rockets.utoledo.edu
> > msnyder...@gmail.com
> >
> >
> >
> > [image: Mailtrack]
> > <
>
https://mailtrack.io?utm_source=gmail&utm_medium=signature&utm_campaign=sign
aturevirality5&
> >
> > Send

Re: [R] add points to lattice cloud plot (3D scatter)

2019-04-04 Thread Duncan Mackay
Sorry my fingers slipped and hit the send button.

One further thing is that I do not know why distribute.type = TRUE for cloud
did not work

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350

-Original Message-
From: Duncan Mackay [mailto:dulca...@bigpond.com] 
Sent: Friday, 5 April 2019 12:48
To: 'Luigi Marongiu'
Cc: 'r-help'
Subject: RE: [R] add points to lattice cloud plot (3D scatter)


Hi all

I know it is a bit late but I have been on other things.

This is a custom solution as it requires manual tweeking for further use in
getting the letter positioning

As cloud is fairly rigid I made a duplicate dataset and reduced the x and y
values by 0.1 as a trial.
Will need tweeking possibly in the z direction if needed.
I then combinded the 2 to form a third to which I assigned a grouping factor
G

df = data.frame(Name = c("A", "B", "C", "D", "E"),
  x_axis = c(-0.591, 0.384, -0.384, -0.032, 0.754),
  y_axis = c(-1.302, 1.652, -1.652, 0.326, 0.652),
  z_axis = c(1.33, 1.33, 2.213, 0.032, -0.754),
  stringsAsFactors = FALSE)
df2 = df
df2[,2] <- df2[,2]-.1
df2[,3] <- df2[,3]-.1
df3 <- rbind(df,df2)
df3$G <- rep(letters[1:2],ea= 5)

After trying to use groups with cloud but this did not work even with
distribute.type = TRUE, I then tried panel.superpose but failed.

Using trellis.print works but ALL the axes must be the same it then it was a
simple matter of superimposing them

x1 =
cloud(z_axis ~ x_axis * y_axis, data = df,
  xlab = "X",
  ylab = "Y",
  zlab = "Z",
  xlim = c(-0.691,0.754),
  ylim = c(-1.752,1.652),
  zlim = c(-0.754,2.213),
  scales = list(arrows = FALSE),
  pch = c(rep(16,5), 64:69),
  type = "b",
  col = "red",
  cex = 1.5)
x2 =
cloud(z_axis ~ x_axis * y_axis, data = df2,
  xlab = "X",
  ylab = "Y",
  zlab = "Z",
  xlim = c(-0.691,0.754),
  ylim = c(-1.752,1.652),
  zlim = c(-0.754,2.213),
  scales = list(arrows = FALSE),
  pch = 65:70,
  col = "black",
  type = "p",
  cex = 1.5)
  )

print(x1, position = c(0,0,1,1), more = TRUE)
print(x2, position = c(0,0,1,1), more = FALSE)


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Friday, 1 March 2019 02:39
To: Duncan Murdoch
Cc: r-help
Subject: Re: [R] add points to lattice cloud plot (3D scatter)

I see. I have been thinking of superimposing two plots with
par(new=TRUE), but how could I remove all the graphic parameters
(axes, background etc) keeping only the actual points in lattice? (if
possible).
Tx

On Thu, Feb 28, 2019 at 3:53 PM Duncan Murdoch 
wrote:
>
> On 28/02/2019 5:39 a.m., Luigi Marongiu wrote:
> > Dear all,
> > is it possible to add points to a lattice cloud plot (3D scatter)? I
> > can plot the main data, but what if I wanted to add another point. In
> > R there is the high level plotting function plot(), then the low level
> > points() or lines() etc. What is the equivalent for lattice?
>
> I don't know for sure, but I don't think you can do that in lattice.
> The scatterplot3d::scatterplot3d function returns enough information to
> do this, but I don't think lattice::cloud does.  But even
> scatterplot3d::scatterplot3d won't necessarily get it right if points
> hide others that are behind them.  It uses the "painter's algorithm",
> and that needs everything to be drawn in just the right order, which you
> probably won't get if you draw things in several calls.
>
> You can draw things in arbitrary order using rgl::plot3d or related
> functions, but you'll need to do more work yourself to get an array of
> plots like lattice gives.
>
> Duncan Murdoch
>
>
> >
> > Thank you
> >
> >
> >>>>
> >
> > df = data.frame(Name = c("A", "B", "C", "D", "E"),
> >x_axis = c(-0.591, 0.384, -0.384, -0.032, 0.754),
> >y_axis = c(-1.302, 1.652, -1.652, 0.326, 0.652),
> >z_axis = c(1.33, 1.33, 2.213, 0.032, -0.754),
> >stringsAsFactors = FALSE)
> >
> > cloud(z_axis ~ x_axis * y_axis, data = df,
> >xlab = "X", ylab = "Y", zlab = "Z",
> >pch = 16, col = "red", type = "b", cex = 1.5,
> >ltext(x=df$x_axis, y=df$y_axis, z=df$z_axis,
> >  labels=df$Names, pos=1, offset=1, cex=0.8)
> > )
> >
> > df2 = data.frame(Name = "F",
> >  x_

Re: [R] add points to lattice cloud plot (3D scatter)

2019-04-04 Thread Duncan Mackay


Hi all

I know it is a bit late but I have been on other things.

This is a custom solution as it requires manual tweeking for further use in
getting the letter positioning

As cloud is fairly rigid I made a duplicate dataset and reduced the x and y
values by 0.1 as a trial.
Will need tweeking possibly in the z direction if needed.
I then combinded the 2 to form a third to which I assigned a grouping factor
G

df = data.frame(Name = c("A", "B", "C", "D", "E"),
  x_axis = c(-0.591, 0.384, -0.384, -0.032, 0.754),
  y_axis = c(-1.302, 1.652, -1.652, 0.326, 0.652),
  z_axis = c(1.33, 1.33, 2.213, 0.032, -0.754),
  stringsAsFactors = FALSE)
df2 = df
df2[,2] <- df2[,2]-.1
df2[,3] <- df2[,3]-.1
df3 <- rbind(df,df2)
df3$G <- rep(letters[1:2],ea= 5)

After trying to use groups with cloud but this did not work even with
distribute.type = TRUE, I then tried panel.superpose but failed.

Using trellis.print works but ALL the axes must be the same it then it was a
simple matter of superimposing them

x1 =
cloud(z_axis ~ x_axis * y_axis, data = df,
  xlab = "X",
  ylab = "Y",
  zlab = "Z",
  xlim = c(-0.691,0.754),
  ylim = c(-1.752,1.652),
  zlim = c(-0.754,2.213),
  scales = list(arrows = FALSE),
  pch = c(rep(16,5), 64:69),
  type = "b",
  col = "red",
  cex = 1.5)
x2 =
cloud(z_axis ~ x_axis * y_axis, data = df2,
  xlab = "X",
  ylab = "Y",
  zlab = "Z",
  xlim = c(-0.691,0.754),
  ylim = c(-1.752,1.652),
  zlim = c(-0.754,2.213),
  scales = list(arrows = FALSE),
  pch = 65:70,
  col = "black",
  type = "p",
  cex = 1.5)
  )

print(x1, position = c(0,0,1,1), more = TRUE)
print(x2, position = c(0,0,1,1), more = FALSE)


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Friday, 1 March 2019 02:39
To: Duncan Murdoch
Cc: r-help
Subject: Re: [R] add points to lattice cloud plot (3D scatter)

I see. I have been thinking of superimposing two plots with
par(new=TRUE), but how could I remove all the graphic parameters
(axes, background etc) keeping only the actual points in lattice? (if
possible).
Tx

On Thu, Feb 28, 2019 at 3:53 PM Duncan Murdoch 
wrote:
>
> On 28/02/2019 5:39 a.m., Luigi Marongiu wrote:
> > Dear all,
> > is it possible to add points to a lattice cloud plot (3D scatter)? I
> > can plot the main data, but what if I wanted to add another point. In
> > R there is the high level plotting function plot(), then the low level
> > points() or lines() etc. What is the equivalent for lattice?
>
> I don't know for sure, but I don't think you can do that in lattice.
> The scatterplot3d::scatterplot3d function returns enough information to
> do this, but I don't think lattice::cloud does.  But even
> scatterplot3d::scatterplot3d won't necessarily get it right if points
> hide others that are behind them.  It uses the "painter's algorithm",
> and that needs everything to be drawn in just the right order, which you
> probably won't get if you draw things in several calls.
>
> You can draw things in arbitrary order using rgl::plot3d or related
> functions, but you'll need to do more work yourself to get an array of
> plots like lattice gives.
>
> Duncan Murdoch
>
>
> >
> > Thank you
> >
> >
> 
> >
> > df = data.frame(Name = c("A", "B", "C", "D", "E"),
> >x_axis = c(-0.591, 0.384, -0.384, -0.032, 0.754),
> >y_axis = c(-1.302, 1.652, -1.652, 0.326, 0.652),
> >z_axis = c(1.33, 1.33, 2.213, 0.032, -0.754),
> >stringsAsFactors = FALSE)
> >
> > cloud(z_axis ~ x_axis * y_axis, data = df,
> >xlab = "X", ylab = "Y", zlab = "Z",
> >pch = 16, col = "red", type = "b", cex = 1.5,
> >ltext(x=df$x_axis, y=df$y_axis, z=df$z_axis,
> >  labels=df$Names, pos=1, offset=1, cex=0.8)
> > )
> >
> > df2 = data.frame(Name = "F",
> >  x_axis = 0.891,
> >  y_axis = 2.302
> >  z_axis = -1.83,
> >  stringsAsFactors = FALSE)
> >
>


-- 
Best regards,
Luigi

__
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-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] Printing standard notation and scientific notation in the same column of a dataframe

2018-09-27 Thread Duncan Mackay
Hi

If you do not require the zeros to the right in the scientific notation
  x
[1] 5.2e-01 1.7e-01 3.0e-02 1.0e-20
  zapsmall(x)
[1] 0.52 0.17 0.03 0.00

Then use format, formatC or  sprintf for character conversions

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350
 
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David
Winsemius
Sent: Friday, 28 September 2018 04:53
To: David Disabato
Cc: r-help@r-project.org
Subject: Re: [R] Printing standard notation and scientific notation in the
same column of a dataframe


> On Sep 27, 2018, at 9:35 AM, David Disabato  wrote:
> 
> Hi R-help,
> 
> I was wondering if it was possible for a column of a dataframe to print
> some numbers in standard notation and some in scientific notation. Say my
> column of data (i.e., dat$x) has numbers between 0 and 1 with a few
numbers
> very close to 0. When using the "scipen" argument in "options," R seems to
> print all numbers of a column in scientific notation if one number in the
> column is a decimal with a starting digit smaller than the "scipen"
> argument. It is annoying that is changes ALL numbers in that column to
> scientific notation though. For example, I do want .0001
in
> scientific notation, but I want .52 in standard form. Ideally, an example
> dataframe column would print as something like this:
> 
> print(dat$x)
> .52
> .17
> .03
> 1.0e-20
> 
> However, I cannot figure out how to do this. Any solutions people are
aware
> of?

Perhaps cat?

> cat(x)
0.52 0.17 0.03 1e-20

> 
> -- 
> David J. Disabato, M.A.
> Clinical Psychology Doctoral Student
> George Mason University
> ddisa...@gmu.edu
> 
> Email is not a secure form of communication as information and
> confidentiality cannot be guaranteed. Information provided in an email is
> not intended to be a professional service. In the case of a crisis or
> emergency situation, call 911.
> 
>   [[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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'
-Gehm's Corollary to Clarke's Third Law

__
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-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] Perform GEE regression in R with multiple dependent variables

2018-08-06 Thread Duncan Mackay
It is quite a while (years) since I used multgee.

There are several papers published by Agresti and ?Touloumis et al   1 in 
Biometrics in 2013  and another in JSS. I am unable to reference  them at the 
moment; you need to read them.

 

I cannot remember how the dependent variable (y) is formatted: ordered or 
numerical see package help.

 

The repeated argument is for longitudinal/ repeated measurements:

Country_ID if is refers to countries is therefore an x  variable (factor) 

 

How you set up you model depends on what your model is testing.

 

Remember ordinal GEE in unlike normal modelling

 

Regards

 

Duncan

 

From: euthymios kasvikis [mailto:euthymios.k.kasvi...@gmail.com] 
Sent: Tuesday, 7 August 2018 02:22
To: dulca...@bigpond.com
Cc: r-help@r-project.org
Subject: Re: [R] Perform GEE regression in R with multiple dependent variables

 

Or 

library(multgee)

fitord <- ordLORgee(Ideo_Ordinal~ Machiavellianism+Psychopathy+Narcissism, 
data=RightWomen,

id= Politician_ID,repeated=Country_ID)

summary(fitord)

 

Should I use dta$Ideo_Ordinal <- ordered(factor(dta$Ideo_Ordinal)) ?

 

 

Στις Δευ, 6 Αυγ 2018 στις 6:00 μ.μ., ο/η euthymios kasvikis 
 έγραψε:

First of all thanks for your advice. So suppose that I would like to use the 
multgee package. The model would be like: 

library(multgee)

fitord <- ordLORgee(Ideo_Ordinal~ Machiavellianism+Psychopathy+Narcissism, 
data=RightWomen,

id= ordered(factor(Country_ID)))

summary(fitord)

 

Στις Δευ, 6 Αυγ 2018 στις 7:29 π.μ., ο/η Duncan Mackay  
έγραψε:

Hi

Please read the geepack manual carefully.
GEE ordinal regression is not simple.
You need to format your data and do not use sample as a storage name. It is
the name of a function

dta is storage
dta$Ideo_Ordinal <- ordered(factor(dta$Ideo_Ordinal))

m0 <-
ordgee(Ideo_Ordinal ~ Machiavellianism+Psychopathy+Narcissism ,data = dta,
id = Country_ID,
   corstr = "independence")

You need to see if the model is appropriate first and whether the sandwich
errors are right before you go further

If this is your data you may not get credible results.
You need to read up on the requirements of GEEs and  ordinal GEEs in
particular
There are a number of packages with different data requirements and methods 
If you have repeated measurements   repolr; ?multgee (just from memory)
Small sample sizes are a problem there are a number of packages dealing with
this but you will have to see which is best for you
Many do not offer a method for ordinal or multinomial GEE.
One further question to ask  population specific or subject specific  ie to
GEE or not to GEE


Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of euthymios
kasvikis
Sent: Saturday, 4 August 2018 07:30
To: r-help@r-project.org
Subject: [R] Perform GEE regression in R with multiple dependent variables

Im trying to perform generalized estimating equation (GEE) on the (sample)
dataset below with R and I would like some little guidance. First of all I
will describe my dataset. As you can see below it includes 5 variables.
Country_ID shows the country of the politician, Ideo_Ordinal his poltical
belief from 1 to 7 (far left to far right). Then we have measurements
regarding three characteristics. I would like to run an analysis based on
the country and the political beliefs of every politician (dependent
variables) in relation with the 3 characteristics. I have used the geepack
package using:

library(geepack)

samplem<-coef(summary(geeglm(sample$Ideo_Ordinal
~Machiavellianism+Psychopathy+Narcissism ,data = sample, id =
sample$Ideo_Ordinal,
   corstr = "independence"))) %>%
  rownames_to_column() %>%
  mutate(lowerWald = Estimate-1.96*Std.err, # Lower Wald CI
 upperWald=Estimate+1.96*Std.err,   # Upper Wald CI
 df=1,
 ExpBeta = exp(Estimate)) %>%   # Transformed estimate
  mutate(lWald=exp(lowerWald),  # Upper transformed
 uWald=exp(upperWald))  # Lower transformed
samplem

I would like to know if it is valid to add in this method the Country_ID
simultaneously with Ideo_Ordinal and how to do it.

Country_ID Ideo_Ordinal Machiavellianism   Narcissism  Psychopathy
3 13  0.250895132  0.155238716  0.128683755
5 13 -0.117725000 -0.336256435 -0.203137879
7 13  0.269509029 -0.260728261  0.086819555
9 16  0.108873496  0.175528190  0.182884928
1413  0.173129951  0.054468468  0.155030794
1516 -0.312088872 -0.414358301 -0.212599946
17 

Re: [R] Perform GEE regression in R with multiple dependent variables

2018-08-05 Thread Duncan Mackay
Hi

Please read the geepack manual carefully.
GEE ordinal regression is not simple.
You need to format your data and do not use sample as a storage name. It is
the name of a function

dta is storage
dta$Ideo_Ordinal <- ordered(factor(dta$Ideo_Ordinal))
 
m0 <-
ordgee(Ideo_Ordinal ~ Machiavellianism+Psychopathy+Narcissism ,data = dta,
id = Country_ID,
   corstr = "independence")

You need to see if the model is appropriate first and whether the sandwich
errors are right before you go further

If this is your data you may not get credible results.
You need to read up on the requirements of GEEs and  ordinal GEEs in
particular
There are a number of packages with different data requirements and methods 
If you have repeated measurements   repolr; ?multgee (just from memory)
Small sample sizes are a problem there are a number of packages dealing with
this but you will have to see which is best for you
Many do not offer a method for ordinal or multinomial GEE.
One further question to ask  population specific or subject specific  ie to
GEE or not to GEE


Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of euthymios
kasvikis
Sent: Saturday, 4 August 2018 07:30
To: r-help@r-project.org
Subject: [R] Perform GEE regression in R with multiple dependent variables

Im trying to perform generalized estimating equation (GEE) on the (sample)
dataset below with R and I would like some little guidance. First of all I
will describe my dataset. As you can see below it includes 5 variables.
Country_ID shows the country of the politician, Ideo_Ordinal his poltical
belief from 1 to 7 (far left to far right). Then we have measurements
regarding three characteristics. I would like to run an analysis based on
the country and the political beliefs of every politician (dependent
variables) in relation with the 3 characteristics. I have used the geepack
package using:

library(geepack)

samplem<-coef(summary(geeglm(sample$Ideo_Ordinal
~Machiavellianism+Psychopathy+Narcissism ,data = sample, id =
sample$Ideo_Ordinal,
   corstr = "independence"))) %>%
  rownames_to_column() %>%
  mutate(lowerWald = Estimate-1.96*Std.err, # Lower Wald CI
 upperWald=Estimate+1.96*Std.err,   # Upper Wald CI
 df=1,
 ExpBeta = exp(Estimate)) %>%   # Transformed estimate
  mutate(lWald=exp(lowerWald),  # Upper transformed
 uWald=exp(upperWald))  # Lower transformed
samplem

I would like to know if it is valid to add in this method the Country_ID
simultaneously with Ideo_Ordinal and how to do it.

Country_ID Ideo_Ordinal Machiavellianism   Narcissism  Psychopathy
3 13  0.250895132  0.155238716  0.128683755
5 13 -0.117725000 -0.336256435 -0.203137879
7 13  0.269509029 -0.260728261  0.086819555
9 16  0.108873496  0.175528190  0.182884928
1413  0.173129951  0.054468468  0.155030794
1516 -0.312088872 -0.414358301 -0.212599946
1713 -0.297647658 -0.096523143 -0.228533352
1813 -0.020389157 -0.210180866 -0.046687695
2013 -0.523432382 -0.125114982 -0.431070629
2111  0.040304508  0.022743463  0.233657881
2213  0.253695988 -0.330825166  0.101122320
2313 -0.478673895 -0.421801231 -0.422894791
2716 -0.040856419 -0.566728704 -0.136069484
2813  0.240040249 -0.398404825  0.135603114
2916 -0.207631653 -0.005347621 -0.294935155
3013  0.458042533  0.462935386  0.586244831
3113 -0.259850232 -0.233074787 -0.092249465
3313  0.002164223 -0.637668706 -0.267158031
3416  0.050991955 -0.098030021 -0.043826848
3613 -0.338052871 -0.168894328 -0.230198200
3813  0.174382347  0.023807812  0.192963609
4123 -0.227322148 -0.010016330 -0.095576329
4223 -0.267514920  0.066108837 -0.218979873
4323  0.421277754  0.385223920  0.421274111
4423 -0.399592341 -0.498154998 -0.320402699
4521  0.162038344  0.328116118  0.104105963
4723 -0.080755709  0.003080287 -0.043568723
482 

Re: [R] Suggestions for scatter plot of many data

2018-07-19 Thread Duncan Mackay
Hi Rich

Try something like this

set.seed(1)
xy <- 
data.frame(x = rnorm(108),
   y = rnorm(108),
   gp = rep(1:9, ea = 12))


xyplot(y~x|gp, xy,
   as.table = TRUE,
   strip = F,
   strip.left = F,
   layout = c(3,3),
   par.settings= list(layout.heights = list(main = 0,
  axis.top = 0.3),
  plot.symbol = list(pch = ".",
 col = "#00",
 cex = 3)
   ),
   scales = list(x = list(alternating = FALSE,
  relation= "same"),
 y = list(alternating = FALSE,
  relation= "same")
 ),
   panel = function(x,y, ...){

 panel.xyplot(x,y, ...)
 panel.text(-1, 2, paste("Group", 1:9)[which.packet()])

   }
)

I have put over 60 panels on an A4 page.
You may have to put an if statement for the group names if they overlap
data.
Space is a premium - you can reduce the right margin similar to the top see
?trellis.par.get()

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350
 



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rich Shepard
Sent: Thursday, 19 July 2018 06:55
To: r-help@r-project.org
Subject: [R] Suggestions for scatter plot of many data

   I have daily precipitation data for 58 locations from 2005-01-01 through
2018-06-18. Among other plots and analyses I want to apply lattice's
xyplot() to illustrate the abundance and patterns of the data.

   I've used a vector of colors (and a key) when there were only eight
weather stations and the date range was three months. This was very
effective in communicating the amounts and patterns.

   I'm asking for ideas on how to best present these data in a scatter plot.

Regards,

Rich

__
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-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] ASExtras library

2018-07-10 Thread Duncan Mackay
Hi

I was trying to find a file on my computer when the ASReml directory showed
up on the directory tree. 

The ASExtras may be part of the R interface/standalone of ASReml available
in Splus as well.
I think the interface to Splus came first

>From what I can remember ASReml R extra packages had a different name than
ASExtras. Is it the Splus distributed package name?
There is an asremlPlus package that is still valid 

Regards

Duncan 

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of radmuzom .
Sent: Thursday, 5 July 2018 07:34
To: David Winsemius; Mehrshad Barary; r-help@r-project.org
Subject: Re: [R] ASExtras library

The package appears to be referenced in the package "agridat" -
ftp://cran.r-project.org/pub/R/web/packages/agridat/agridat.pdf (Pg 55).
However, even I tried searching for it and there seems to be no reference
other than this source.

Regards,
radmuzom

From: R-help  on behalf of David Winsemius

Sent: Wednesday, July 4, 2018 9:22 PM
To: Mehrshad Barary
Cc: r-help@r-project.org
Subject: Re: [R] ASExtras library
  


> On Jul 3, 2018, at 6:34 PM, Mehrshad Barary  wrote:
> 
> Hi Everyone,
> 
> Does anybody know how I can get ASExtras library?

It would be helpful if you would provide information about your reasons for
assuming this package's existence. Cannot find it in CRAN (including a
search for 'ASExtra'), BioConductor, GitHub, or the Archives, or even with
Google for that matter.

https://cran.r-project.org/src/contrib/Archive/

And within R parlance 'library' not a synonym for 'package'. Libraries are
where you store packages. And `library('pkg_name')` is a command for loading
a package.


> Thanks
> Mehrshad
> 
> -- 
> Mehrshad Barary
> Senior Lecturer in Crop Ecophysiology
> Department of Agronomy and Plant Breeding
> Faculty of Agriculture
> Ilam University
> Tel: (+98)8412227019-21
> Fax: (+98)8412227015
> 
>    [[alternative HTML version deleted]]

And R help is a plain-text mailing list. Please read the Posting Guide.

> 
> __
> 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.

David Winsemius
Alameda, CA, USA

'Any technology distinguishable from magic is insufficiently advanced.'  
-Gehm's Corollary to Clarke's Third Law

__
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-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-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] [FORGED] Extracting specified pages from a lattice ("trellis") object.

2018-04-27 Thread Duncan Mackay
Hi Paul, Rolf

I do not know how legal this is but this works if you have spaces around the 
ultimate plot due to changes in layout
Changing the layout parameters removes the unwanted space.

ap = dotplot(variety ~ yield | year * site, data=barley,layout = c(2,6))
apm = ap[1:2,3:4]
apm$layout <- c(2,2)
apm

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Paul Murrell
Sent: Friday, 27 April 2018 11:28
To: Rolf Turner
Cc: r-help@r-project.org; deepayan.sar...@r-project.org
Subject: Re: [R] [FORGED] Extracting specified pages from a lattice ("trellis") 
object.

Hi

Does this not do what you want ... ?

allpages <- dotplot(variety ~ yield | year * site, data=barley,
 layout=c(2,2))
page2 <- allpages[1:2, 3:4]
print(page2)

Paul

On 24/04/18 17:51, Rolf Turner wrote:
> 
> On 24/04/18 15:17, Paul Murrell wrote:
> 
>> Hi
>>
>> I think the subsetting works by giving you the panels for the 
>> corresponding levels of the conditioning variable(s).  Note that, if 
>> there is more than one conditioning variable, you will need more than 
>> one subsetting index.
>>
>> For example, taking this plot with two conditioning variables and 12 
>> panels in total ...
>>
>> dotplot(variety ~ yield | year * site, data=barley)
>>
>> ... this produces three pages ...
>>
>> dotplot(variety ~ yield | year * site, data=barley,
>>  layout=c(2,2))
>>
>> ... and this produces the second page (both panels for the first 
>> conditioning variable and the third and fourth panels for the second 
>> conditioning variable) ...
>>
>> dotplot(variety ~ yield | year * site, data=barley,
>>  layout=c(2,2))[1:2, 3:4]
>>
>> Hope that helps.
> 
> Hmm.  Thanks Paul.  I may be able to work with that.  But what I really 
> wanted was to take
> 
>  bar <- dotplot(variety ~ yield | year * site, data=barley)
> 
> and then do (something like)
> 
>  foo <- bar[]
> 
> so that foo contains only the second page of bar, and then do print(foo)
> to get a plot of (just) the second page.  Without re-issuing a 
> (modified) plot command.
> 
> Is that not at all possible?
> 
> cheers,
> 
> Rolf.
> 

-- 
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
p...@stat.auckland.ac.nz
http://www.stat.auckland.ac.nz/~paul/

__
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-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] Can't Get Lattice Histogram Minor Tick Marks to Work

2018-04-24 Thread Duncan Mackay
Hi

You may need to make a custom function for yscale.components; I think there
is an example in the help guides
Also have a look at
https://stat.ethz.ch/pipermail/r-help/2007-June/134524.html 

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350

 

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Donald
Macnaughton
Sent: Wednesday, 25 April 2018 14:13
To: 'Jeff Newmiller'; 'R-Help'
Subject: Re: [R] Can't Get Lattice Histogram Minor Tick Marks to Work

Thanks Jeff, 

I attached a file with the program to my earlier email because the posting
guide seemed to imply that non-binary attachments would work. But I see that
the file was stripped off. 

I installed the program file on a web site, but when I downloaded it, the
line breaks were stripped out. So I've included the program below:

---

# This R program illustrates a problem with the histogram function in 
# the lattice package.
# This program requires the  latticeExtra  package to be installed to
# generate the minor tickmarks.

library(lattice)
library(latticeExtra)  

# First, please run the program to see the problem.

# Note how the histogram shows minor tickmarks on the vertical axis. 
# I would like to show only a SINGLE minor tickmark between major tickmarks
on
# the vertical axis, which helps to show the viewer that all the bars
# in the left panel are at five percent.

# The yscale.components.subticks function in the latticeExtras package
# has arguments to contol the minor tickmarks, but I can't get them to work.
# How can a get a single minor tickmark between the major tickmarks on
# the vertical axis?

# Thanks for your help,

# Don Macnaughton don...@matstat.com


# Generate data in an 20 x 2 matrix for left panel. In my real application 
# the data file contains many more rows, but that's not necessary here.
for (i in 1:20) {
if (i == 1) {pmat = c(0.045,0)} else {
 pmat = rbind(pmat,c(i*0.05-0.001,0))}
}

# Generate data for the right panel in the same matrix.
counts = c(90, 12.5, 9, 8, 7, 6.5, 6, 5.5, 5, 4.5, 
   4, 3.5, 3, 2.8, 2.2, 2, 1.8, 1.6, 1.4, 1.0)
for (i in 1:20) {
maxCount = 100 * counts[i]
for (j in 1:maxCount){
pmat = rbind( pmat, c(i*0.05-0.001,2) )
 }
}

# Convert the matrix to a data frame and add column names.
pDat = data.frame(pmat)
colnames(pDat) = c("pValue","nonCent")


# Create a factor to enable titles on the two panels.
nonCent.f = factor(pDat$nonCent, 
  labels=c("Noncentrality = 0.0", "Noncentrality = 2.0"))

# Use the lattice histogram function to draw the histogram.
histogram( ~ pValue | nonCent.f, data = pDat, nint = 20,
   endpoints = c(0, 1), layout = c(2,1), 
   yscale.components=yscale.components.subticks,
   scales=list(alternating=FALSE,tck=c(1,0)),
   col="lightgray")

---


Don Macnaughton


-Original Message-
From: Jeff Newmiller  
Sent: Tuesday, April 24, 2018 11:28 PM
To: r-help@r-project.org; Donald Macnaughton ; R-Help

Subject: Re: [R] Can't Get Lattice Histogram Minor Tick Marks to Work

Per the Posting Guide, why didn't you post the reproducible R code example? 

On April 24, 2018 8:22:15 PM PDT, Donald Macnaughton 
wrote:
>I'm drawing a paneled histogram using the lattice package. I've 
>succeeded in adding minor tick marks to the vertical axis, but I can't 
>get the desired number of minor tick marks between the major tick 
>marks.
>
>I've attached a self-contained program to illustrate the problem.
>
>Thanks for your help,
>
>Don Macnaughton
>
>
>Here's my sessionInfo:
>
>R version 3.4.3 (2017-11-30)
>Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 
>(build 16299)
>
>Matrix products: default
>
>locale:
>[1] LC_COLLATE=English_United States.1252 
>[2] LC_CTYPE=English_United States.1252   
>[3] LC_MONETARY=English_United States.1252
>[4] LC_NUMERIC=C  
>[5] LC_TIME=English_United States.1252
>
>attached base packages:
>[1] graphics  grDevices utils datasets  stats methods   base   
> 
>
>other attached packages:
>[1] psych_1.7.8 latticeExtra_0.6-28 RColorBrewer_1.1-2 
>[4] Hmisc_4.0-3 ggplot2_2.2.1   Formula_1.2-2  
>[7] survival_2.41-3 lattice_0.20-35
>
>loaded via a namespace (and not attached):
> [1] Rcpp_0.12.14pillar_1.0.1compiler_3.4.3 
> [4] plyr_1.8.4  base64enc_0.1-3 tools_3.4.3
> [7] rpart_4.1-11digest_0.6.13   nlme_3.1-131   
>[10] tibble_1.4.1gtable_0.2.0checkm

Re: [R] [FORGED] Extracting specified pages from a lattice ("trellis") object.

2018-04-24 Thread Duncan Mackay
Hi Rolf

do you need to use the  layout argument?

The layout is conditioned by the levels of a or unique values if not a factor. 
easier with factor

unique(dta$a)
 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l"
data.frame( a= unique(dta$a), page = rep(1:3, ea = 4), col = 1:2,row  = 
rep(1:2, ea = 2))
   a page col row
1  a1   1   1
2  b1   2   1
3  c1   1   2
4  d1   2   2
5  e2   1   1
6  f2   2   1
7  g2   1   2
8  h2   2   2
9  i3   1   1
10 j3   2   1
11 k3   1   2
12 l3   2   2

I hope I have got the order right

full dataset
xyplot(y~x|a,data=dta)


 bar  = xyplot(y~x|a,data = subset(dta, a %in% c("e","f","g","h")) ))

print(bar)
(missed the dotplot requirement) but principle is the same.

you can use packet.number or which.packet if needed to make it simpler

use par.settings to do colours lines etc as well as spacing.

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rolf Turner
Sent: Tuesday, 24 April 2018 15:52
To: Paul Murrell
Cc: r-help@r-project.org; deepayan.sar...@r-project.org
Subject: Re: [R] [FORGED] Extracting specified pages from a lattice ("trellis") 
object.


On 24/04/18 15:17, Paul Murrell wrote:

> Hi
> 
> I think the subsetting works by giving you the panels for the 
> corresponding levels of the conditioning variable(s).  Note that, if 
> there is more than one conditioning variable, you will need more than 
> one subsetting index.
> 
> For example, taking this plot with two conditioning variables and 12 
> panels in total ...
> 
> dotplot(variety ~ yield | year * site, data=barley)
> 
> ... this produces three pages ...
> 
> dotplot(variety ~ yield | year * site, data=barley,
>  layout=c(2,2))
> 
> ... and this produces the second page (both panels for the first 
> conditioning variable and the third and fourth panels for the second 
> conditioning variable) ...
> 
> dotplot(variety ~ yield | year * site, data=barley,
>  layout=c(2,2))[1:2, 3:4]
> 
> Hope that helps.

Hmm.  Thanks Paul.  I may be able to work with that.  But what I really 
wanted was to take

 bar <- dotplot(variety ~ yield | year * site, data=barley)

and then do (something like)

 foo <- bar[]

so that foo contains only the second page of bar, and then do print(foo)
to get a plot of (just) the second page.  Without re-issuing a 
(modified) plot command.

Is that not at all possible?

cheers,

Rolf.

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

__
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-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] problem with the behaviour of dashed lines in R plots

2017-12-04 Thread Duncan Mackay
If you can change the line colour try this

options(mgp=c(2,0.5,0),cex.lab=1.6)

plot(df1$B, predict(regressor,df1),
 type="l",
 col="grey",
 lwd=2,
 lty=1,
 xlim=range(c(1.2,1.7)),
 ylim=rev(range(c(-19,-8
 
lines(df1$B,as.numeric(df1$A),
  type="p",
  col="black",
  cex=2,
  pch=17)

box(lwd=3)

Saves typing by using options

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of
jean-philippe
Sent: Tuesday, 5 December 2017 04:14
To: R mailing list
Subject: [R] problem with the behaviour of dashed lines in R plots

dear R users,

I am performing a linear regression with lm, and I would like to plot 
the regressor in dashed lines. I know that the lty=2 option is the way 
out, but it has a very strange behaviour: the line starts dashed but 
then the spaces between each dash becomes very tiny and so the line 
become somehow continuous for the human eye. Do you know how to fix that 
problem, in order to have a dashed line with big enough spaces between 
the dashes?
Here is a MWE (don't mind if clearly a linear model will not fit these 
"fake randomly generated" data).

Also, changing the plot(...,type="l") to abline(regressor,lty=2,...) 
helps and draw a pure dashed line but it is impossible to force it to 
stay in the bounds of the data.
Changing to line instead shows the same problem as mentioned here in the 
MWE.


pdf("reproducableex.pdf")
df1<-data.frame(B=runif(20,1.4,1.6),A=runif(20,-19.5,-9.8))
regressor<-lm(A~B,data = df1)
plot(df1$B,predict(regressor,df1),type="l", col="black", 
mgp=c(2,0.5,0),cex.lab=1.6, lwd=2, 
lty=2,xlim=range(c(1.2,1.7)),ylim=rev(range(c(-19,-8
par(new = TRUE)
plot(df1$B,as.numeric(df1$A),type="p", col="black", 
mgp=c(2,0.5,0),cex.lab=1.6,cex=2, xlab = "", ylab = 
"",xlim=range(c(1.2,1.7)),ylim=rev(range(c(-19,-8))),pch=17)
box(lwd=3)
dev.off()


Thanks in advance, best regards


Jean-Philippe Fontaine

-- 
Jean-Philippe Fontaine
PhD Student in Astroparticle Physics,
Gran Sasso Science Institute (GSSI),
Viale Francesco Crispi 7,
67100 L'Aquila, Italy
Mobile: +393487128593, +33615653774

__
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-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] Lattice stacked barplot vertical bars

2017-09-22 Thread Duncan Mackay
Hi Luigi

will this do

barchart(
D ~ A|E,
DF,
groups = C,
stack = TRUE,
horizontal = F,
main = "Comparison of test results",
xlab = "Count",
col = c("yellow", "orange"),
par.settings = list(
strip.background = list(col="light grey"),
superpose.polygon=list(col= c("yellow", "orange"))
),
scales = list(
alternating = FALSE
),
key = list(
space="top",
columns=2,
text=list(c("Single infections", "Multiple infections"),
col="black"),
rectangles=list(col=c("yellow", "orange"))
),
strip = strip.custom(factor.levels = c("Cases","Controls"),
 strip.levels=TRUE,
 strip.names=FALSE,
 par.strip.text = list(cex = 1)
)
)

Too late to do anything more

Regards 

Duncan Macka

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Friday, 22 September 2017 21:53
To: r-help
Subject: [R] Lattice stacked barplot vertical bars

Dear all,
I have made a barplot using lattice in which the bars are stacked
horizontally. I would like to stack them vertically, but if I use the
parameter 'horizontal = FALSE' I get the error: 'Error in FUN(X[[i]],
...) : invalid 'type' (character) of argument'. The problem I face is
that, in drawing the bars vertically, the y variable becomes numeric
rather than categorical and vice-versa for the x variable.
How can I solve this issue?
Thank you
Luigi

>>>

A <- c('a', 'b', 'c', 'd', 'a', 'b', 'c', 'd', 'b', 'c', 'd', 'b', 'c', 'd')
B <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)
C <- c(0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1)
D <- c(4, 120, 7, 23, 4, 24, 3, 12, 7, 1, 1, 5, 0, 0)
E <- c(0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1)
DF <- data.frame(A, B, C, D, E, stringsAsFactors = FALSE)
library(lattice)
barchart(
A ~ D|E,
DF,
groups = C,
stack = TRUE,
horizontal = TRUE,
main = "Comparison of test results",
xlab = "Count",
col = c("yellow", "orange"),
par.settings = list(
strip.background = list(col="light grey"),
superpose.polygon=list(col= c("yellow", "orange"))
),
scales = list(
alternating = FALSE
),
key = list(
space="top",
columns=2,
text=list(c("Single infections", "Multiple infections"),
col="black"),
rectangles=list(col=c("yellow", "orange"))
),
strip = strip.custom(factor.levels = c("Cases","Controls"),
 strip.levels=TRUE,
 strip.names=FALSE,
 par.strip.text = list(cex = 1)
)
)

__
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-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] show 0 at y axis in xyplot lattice

2017-09-11 Thread Duncan Mackay
Hi Maria

Rule 1 make sure your data is in the right format

dat <- source("G:/1/savedat.txt")
> dat
$value
 Location   Date  Zn2 upper.zn  lower.zn
1upstream 2016-04-27 29.92477 55.59800 13.912207
2   spill 2016-04-27 12.84040 22.07006  6.964934
3  downstream 2016-04-27 22.49673 41.60901 11.739109
4upstream 2016-06-28 23.98425 45.60219 10.690640
5   spill 2016-06-28 41.51336 77.99893 20.142426
6  downstream 2016-06-28 15.51232 26.94059  7.044781
7upstream 2016-08-25 21.73037 40.95852 10.354620
8   spill 2016-08-25 13.42082 22.96901  7.472893
9  downstream 2016-08-25 10.99209 20.17471  5.324318
10   upstream 2016-10-25 20.82462 40.60564  9.602007
11  spill 2016-10-25 14.01283 25.07032  7.830504
12 downstream 2016-10-25 15.67740 30.42278  6.971944
13   upstream 2016-12-21 28.14966 51.79390 14.384139
14  spill 2016-12-21 13.91587 23.94368  8.164688
15 downstream 2016-12-21 13.02749 24.46930  5.826650
16   upstream 2017-02-20 31.16736 55.51858 15.938211
17  spill 2017-02-20 12.47368 22.03830  6.725540
18 downstream 2017-02-20 17.65741 33.23577  8.519928

$visible
[1] TRUE
dat <- dat$value
dat$dDate <- as.Date(as.character(dat$Date))

str(dat)
'data.frame':   18 obs. of  6 variables:
 $ Location: Factor w/ 3 levels "downstream","spill",..: 3 2 1 3 2 1 3 2 1 3 ...
 $ Date: Factor w/ 6 levels "2016-04-27","2016-06-28",..: 1 1 1 2 2 2 3 3 3 
4 ...
 $ Zn2 : num  29.9 12.8 22.5 24 41.5 ...
 $ upper.zn: num  55.6 22.1 41.6 45.6 78 ...
 $ lower.zn: num  13.91 6.96 11.74 10.69 20.14 ...
 $ dDate   : Date, format: "2016-04-27" "2016-04-27" "2016-04-27" "2016-06-28" 
...

You code to reproduce the xyplot is not reproducible as it contains user 
defined objects which you have not included.
Here is something to get you started,
If you want the measurement dates on the x-axis you will need to put the  
required dates and format  in the scales argument.
Using par.settings for the symbols an lines will pass those values onto key

xyplot(upper.zn + Zn2 + lower.zn ~ dDate | Location, data=dat,
   type = "b",
   as.table = TRUE,
   par.settings = list(strip.background = list(col = "transparent"),
   superpose.symbol = list( col=c("red", "black", 
"red"),
  cex = 1,
  pch = c(22, 21, 22)),
   superpose.line = list (col=c("red", "black", "red"),
lty = c(2, 1, 2),
lwd = 1)
  ),
   auto.key = list(points = TRUE, lines = TRUE),
   scales   = list(x = list(alternating = FALSE,
at = seq(from = as.Date("2016-04-01"), to = 
as.Date("2017-04-01"), by = "quarter"),
label = format(seq(from = 
as.Date("2016-04-01"), to = as.Date("2017-04-01"), by = "quarter"), "%Y %b"),
relation= "same",
rot = 60),
   y = list(alternating = FALSE,
at =  seq(0,80,20),
relation= "same",
rot = 0)
  ),
#   pch=c(22, 21, 22),
#   lty=c(2, 1, 2),
   xlim = range(seq(from = as.Date("2016-04-01"), to = 
as.Date("2017-04-01"), by = "quarter")),
   ylim=c(-5, 80),
   index.cond=list(c(3, 1, 2)),
   ylab="Percent (%)",
#   par.strip.text=list(col="white", font=2, lines=1.5),
#   lattice.options = modifyList(lattice.options(), 
list(skip.boundary.labels = 0)),
#   par.settings=my.settings, col=c("red", "black", "red"), fill=c("red", 
"black", "red"),
#   key=dat_key,
#   scales = list(x = list(at = sdate, labels = format(sdate, "%b-%y"))), 
xlab="Date",
   panel = function(x, y, ...) {
 panel.grid(h = -1, v = 0, lwd=1, lty=3, col="grey")
 panel.abline(v=dat$dDate, lwd=1, lty=3, col="grey")
 panel.xyplot(x, y, ...)
 }
 )

As you have upper and lower levels of Zn you may want to look at ?panel.polygon 
 

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2350



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Maria Lathouri 
via R-help
Sent: Tuesday, 12 September 2017 05:33
To: R-help Mailing List
Subject: [R] show 0 at y axis in xyplot lattice

Dear all
I am trying

Re: [R] plotting gamm results in lattice

2017-06-12 Thread Duncan Mackay
ke a cross-section of data - reduces the amount of data to be plotted
mx = aggregate(Q95 ~ super.end.group, spring, max, na.rm=T)
newlst <-
do.call(rbind,
lapply(1:6, function(j) expand.grid(Q95 = seq(0,mx[j,2], length = 50), 
super.end.group = LETTERS[j])
Year =
Hms_Rsctned =
...))   # fill in yourself
newd <- data.frame(newlst)

and predict using newdata = newd

# starting with a smaller model
model2 <-
gamm4(LIFE.OE_spring~s(Q95, by=super.end.group), data=spring,
  random=~(1|WATERBODY_ID/SITE_ID))

newlst <-
do.call(rbind,
lapply(1:6, function(j) expand.grid(Q95 = seq(0,mx[j,2], length = 50), 
super.end.group = LETTERS[j])) )
newd <- data.frame(Q95 = newlst)
# The following is untested
# I have not used gamm4 for a while; is  model$gam correct? Had problems here - 
have no time to go into the help pages
M3 <- predict(model2$gamm, newdata = newd, type="response",se.fit=T)

# keep together 
newdat = cbind(newd, M3)

# If you want CIs
newdat <- within(newdat, {
lower = fit-1.96*se.fit
upper = fit+1.96*se.fit
})

# plot- something like
xyplot(fitted(model$gam) ~ Q95 |super.end.group, data = springP,
   Q2= newddat$Q95,
   lower = newdat$lower,
   upper = newdat$upper,
   subscripts = TRUE,
   panel = function(x,y, Q2, upper, lower, subscripts, ...){
  panel.xyplot(x,y, type="smooth")
  panel.xyplot(Q2, upper, lty=2, col="red")
  panel.xyplot(Q2, lower, lty=2, col="red")
  #panel.loess(x,y,...)
  #panel.rug(x = x[is.na(y)], y = y[is.na(x)])
}
)

If you are putting a key onto the plot see
? xyplot and par.settings and key 

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Maria Lathouri 
via R-help
Sent: Monday, 12 June 2017 20:57
To: R-help Mailing List
Subject: [R] plotting gamm results in lattice

Dear all, 
I hope that you can help me on this. I have been struggling to figure this out 
but I haven't found any solution.
I am running a generalised mixed effect model, gamm4, for an ecology project. 
Below is the code for the model:
model<-gamm4(LIFE.OE_spring~s(Q95, 
by=super.end.group)+Year+Hms_Rsctned+Hms_Poaching+X.broadleaved_woodland
 +X.urban.suburban+X.CapWks, data=spring, random=~(1|WATERBODY_ID/SITE_ID))
plot(model$gam, page=1, font.lab=2, xlab="Residual Q95")

I am trying to plot the results in lattice for publication purposes so I need 
to figure this out. I have been struggling but I think I have reached a dead 
end. 

Here is what I have been able to code:
M<-predict(model$gam,type="response",se.fit=T)
upr<- M$fit + (1.96 * M$se.fit)lwr<- M$fit - (1.96 * M$se.fit)
library(lattice)xyplot(fitted(model$gam) ~ Q95 |super.end.group, data = spring, 
gm=model,   prepanel=function (x,y,...)list(ylim=c(min(upr),max(lwr))), 
  panel = function(x,y, gm, ...){  panel.xyplot(x,y, type="smooth") 
panel.lines(upr,lty=2, col="red") panel.lines(lwr,lty=2, 
col="red") panel.loess(x,y,...) panel.rug(x = x[is.na(y)],  
 y = y[is.na(x)])   }   )
But, unfortunately, this is not what I get when I have the simple 
plot(model$gam). 

I have also attached a reproducible example in case you want to see for 
yourself. I hope that someone here has come up with a similar problem and can 
help me on this.
Thank you very much for your time.
Kind regards,Maria 

__
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] display double dot over character in plotmath?

2017-05-15 Thread Duncan Mackay
Hi

I looked up for the Unicode version at
http://www.utf8-chartable.de/unicode-utf8-table.pl
You might have to go to another page to find the Unicode equivalent.

You may not be able to get the right character showing  and get at square/s
instead - it all depends on the drivers and how many characters that make up
the Unicode character
I had a case of this recently and it did not make any difference using Cairo


Regards

Duncan

 

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ranjan
Maitra
Sent: Monday, 15 May 2017 01:44
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] display double dot over character in plotmath?

Thanks, Duncan!

This works for the particular case and is, to my mind, a great solution!

However, I was wondering: is it possible to use these double dots with
another character, such as omega?  

I apologize for changing the question somewhat, but I did not realize
earlier that there were separate codes for putting double dots over
different letters and I thought that figuring out the simpler question would
be enough for me to figure out the next step. 

Thanks again!

Best wishes,
Ranjan



On Sun, 14 May 2017 23:57:50 +1000 Duncan Mackay 
wrote:

> Hi
> 
> I just had to do something similar in windows with \"{u}. Try Unicode
symbol
> - see ?plotmath 
> 
> ggplot(data, aes(x=X)) + geom_line(aes(y = Z), size=0.43) +
> xlab(expression(atop(top,bold(Age~"\u00e4"
> 
> Regards
> 
> Duncan
> 
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
> 
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ranjan
> Maitra
> Sent: Saturday, 13 May 2017 22:48
> To: r-h...@stat.math.ethz.ch
> Subject: Re: [R] display double dot over character in plotmath?
> 
> On Fri, 12 May 2017 23:39:14 -0700 Daniel Nordlund 
> wrote:
> 
> > On 5/12/17 4:55 PM, Ranjan Maitra wrote:
> > > Hi,
> > > 
> > > Is it possible to display double dot (umlaut) over a character such as
> would be possible using \ddot x in LaTeX? I can do this using tikzDevice
but
> I wanted something simpler to point to.
> > > 
> > > Here is an example of what I would like to do, but it is not quite
> there:
> > > 
> > > require(ggplot2)
> > > data<-as.data.frame(c("a","b","c","a","b","c"))
> > > colnames(data)<-"Y"
> > > data$X<-c(1:6)
> > > data$Z<-c(1,2,3,1,2,3)
> > > 
> > > ggplot(data, aes(x=X)) + geom_line(aes(y = Z), size=0.43) +
> xlab(expression(atop(top,bold(Age~"à"
> > > 
> > > I would like to put in a double dot over the "a" in the x-axis instead
> of "`".
> > > 
> > > Many thanks for any suggestions and best wishes,
> > > Ranjan
> > > 
> > 
> > You haven't told what OS you are using, but with Windows OS, you can get

> > the 'ä' by making sure the NUMLOCK key is on, hold down the alt key and 
> > press 0228 on the numeric keypad.
> > 
> > 
> 
> I am sorry, I use a linux operating system. I use Fedora 25 but the
student
> I wanted to show this uses Ubuntu, though I don't know if the distribution
> matters.
> 
> Thanks again for your help, and best wishes,
> Ranjan
> 
> __
> 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-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.
> 


-- 
Important Notice: This mailbox is ignored: e-mails are set to be deleted on
receipt. Please respond to the mailing list if appropriate. For those
needing to send personal or professional e-mail, please use appropriate
addresses.

__
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-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] display double dot over character in plotmath?

2017-05-14 Thread Duncan Mackay
Hi

I just had to do something similar in windows with \"{u}. Try Unicode symbol
- see ?plotmath 

ggplot(data, aes(x=X)) + geom_line(aes(y = Z), size=0.43) +
xlab(expression(atop(top,bold(Age~"\u00e4"

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ranjan
Maitra
Sent: Saturday, 13 May 2017 22:48
To: r-h...@stat.math.ethz.ch
Subject: Re: [R] display double dot over character in plotmath?

On Fri, 12 May 2017 23:39:14 -0700 Daniel Nordlund 
wrote:

> On 5/12/17 4:55 PM, Ranjan Maitra wrote:
> > Hi,
> > 
> > Is it possible to display double dot (umlaut) over a character such as
would be possible using \ddot x in LaTeX? I can do this using tikzDevice but
I wanted something simpler to point to.
> > 
> > Here is an example of what I would like to do, but it is not quite
there:
> > 
> > require(ggplot2)
> > data<-as.data.frame(c("a","b","c","a","b","c"))
> > colnames(data)<-"Y"
> > data$X<-c(1:6)
> > data$Z<-c(1,2,3,1,2,3)
> > 
> > ggplot(data, aes(x=X)) + geom_line(aes(y = Z), size=0.43) +
xlab(expression(atop(top,bold(Age~"à"
> > 
> > I would like to put in a double dot over the "a" in the x-axis instead
of "`".
> > 
> > Many thanks for any suggestions and best wishes,
> > Ranjan
> > 
> 
> You haven't told what OS you are using, but with Windows OS, you can get 
> the 'ä' by making sure the NUMLOCK key is on, hold down the alt key and 
> press 0228 on the numeric keypad.
> 
> 

I am sorry, I use a linux operating system. I use Fedora 25 but the student
I wanted to show this uses Ubuntu, though I don't know if the distribution
matters.

Thanks again for your help, and best wishes,
Ranjan

__
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-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] Lattice xyplot

2017-05-01 Thread Duncan Mackay
In addition to Berts comments

Once you change the order you change the non factored  id' ordering. If you 
make it a factor it may be  easier to see what is going on
I think I have copied correctly - see the differences 

# original data
xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")
# order
dat2<-dat[order(dat$id, dat$time),]
xyplot(y ~ time, data=dat2, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")
# make ID a factor
dat3 <- dat1
xyplot(y ~ time, data=dat3, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")
# ordered + ID a factor
dat4 <- dat3
dat4<-dat[order(dat4$id, dat4$time),]
xyplot(y ~ time, data=dat4, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of array chip via 
R-help
Sent: Monday, 1 May 2017 11:07
To: r-help@r-project.org
Subject: [R] Lattice xyplot

Dear all, I am new to lattice, so would appreciate anyone's help on the 
questions below. I am using xyplot to plot some trend in my dataset. Using the 
example dataset attached, I am trying to plot variable "y" over variable "time" 
for each subject "id":
dat<-read.table("dat.txt",sep='\t',header=T,row.names=NULL)
xyplot(y ~ time, data=dat, groups=id, aspect = "fill", type = c("p", "l"),  
xlab = "Time", ylab = "Y")

It appears that it just worked fine. But if I sort the "dat" first, the plot 
will look somewhat different!
dat<-dat[order(dat$id, dat$time),]xyplot(y ~ time, data=dat, groups=id, aspect 
= "fill", type = c("p", "l"),  xlab = "Time", ylab = "Y")
Why is that? Do you need to sort the data first before using xyplot? Why xyplot 
can not understand the dataset unless it is sorted first?
Thanks,
John

__
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] Strip height in latticeExtra:::useOuterStrips

2017-04-17 Thread Duncan Mackay
Hi all

I use latticeExtra::useOuterStrips quite a bit.
The problem of strip height using useOuterStrips came up some time ago but
did not have the time then to work something out so made do with the
default layout.heights of strip = 1

#Data:

df2 <- structure(list(a = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L), .Label = c("1", "2"), class = "factor"), 
b = structure(c(1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 
2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 2L, 2L, 1L, 1L, 
2L, 2L, 1L, 1L, 2L, 2L), .Label = c("1", "2"), class = "factor"), 
c = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 
1L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor"), 
d = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor"), 
rep = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1", "2"), class = "factor"), 
x = c(-0.626453810742333, 0.183643324222082, -0.835628612410047, 
1.59528080213779, 0.329507771815361, -0.820468384118015, 
0.487429052428485, 0.738324705129217, 0.575781351653492, 
-0.305388387156356, 1.51178116845085, 0.389843236411431, 
-0.621240580541804, -2.2146998871775, 1.12493091814311,
-0.0449336090152308, 
-0.0161902630989461, 0.943836210685299, 0.821221195098089, 
0.593901321217509, 0.918977371608218, 0.782136300731067, 
0.0745649833651906, -1.98935169586337, 0.61982574789471, 
-0.0561287395290008, -0.155795506705329, -1.47075238389927, 
-0.47815005510862, 0.417941560199702, 1.35867955152904,
-0.102787727342996
)), .Names = c("a", "b", "c", "d", "rep", "x"), out.attrs =
structure(list(
dim = structure(c(2L, 2L, 2L, 2L, 2L), .Names = c("a", "b", 
"c", "d", "rep")), dimnames = structure(list(a = c("a=1", 
"a=2"), b = c("b=1", "b=2"), c = c("c=1", "c=2"), d = c("d=1", 
"d=2"), rep = c("rep=1", "rep=2")), .Names = c("a", "b", 
"c", "d", "rep"))), .Names = c("dim", "dimnames")), row.names = c(NA, 
-32L), class = "data.frame")

str(df2)

library(lattice)
library(laticeExtra)

# This is as per normal
xyplot(x~d|paste(a,b)*c, data = df2)

# Increase strip height to use atop later on for 2 lines of text/panel in
strip
# works OK
xyplot(x~d|paste(a,b)*c, data = df2, 
   par.settings = list(layout.heights = list(strip = 2.2)))
# no change in strip height
useOuterStrips(xyplot(x~d|paste(a,b)*c, data = df2, 
   par.settings = list(layout.heights = list(strip = 2.2

I have played around with various vector and list combinations for strip in
layout.heights to no avail
Does any one have an answer?

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

__
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] customize labels useOuterStrips lattice

2017-03-30 Thread Duncan Mackay
Hi  Luigi

You were nearly there!

Using Rich's factors

  useOuterStrips(strip = strip.custom(factor.levels =
c("much","more","interesting","names","here"),
  par.strip.text = list(cex = 0.75)),
 strip.left = strip.custom(factor.levels =
c("also","better"),
   par.strip.text = list(cex =
0.75)),
stripplot(
  average ~ type|target+cluster,
  panel = function(x,y,col,...)
panel.superpose(x,y,col=col,...),
  panel.groups = function(x,y,col,...){
panel.stripplot(x,y,col=col,...)
m <- median(y)
panel.segments(x0 = x[1] -.5, y0 = m,
   x1 = x[1] +.5, y1 = m,
   col=col, lwd=2
)
  },
  my.data,
  groups = type,
  pch=1,
  jitter.data = TRUE,
  main = "Group-wise",
  xlab = expression(bold("Target")), ylab = expression(bold("Reading")),
  col = c("grey", "green", "red"),
  par.settings = list(strip.background =
list(col=c("paleturquoise", "grey"))),
  scales = list(alternating = FALSE, x=list(draw=FALSE)),
  key = list(
space = "top",
columns = 3,
text = list(c("Blank", "Negative", "Positive"), col="black"),
rectangles = list(col=c("grey", "green", "red"))
  )
)
  )

Regards

Duncan


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan
Mackay
Sent: Friday, 31 March 2017 00:12
To: R; 'Luigi Marongiu'
Subject: Re: [R] customize labels useOuterStrips lattice

Hi Luigi

see
?strip.custom

too late to do any more

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Thursday, 30 March 2017 18:51
To: r-help
Subject: [R] customize labels useOuterStrips lattice

Dear all,
I am plotting some data using lattice and the function useOuterStrips
to make use of more labels. It is possible to customize the labels of
useOuterStrips so I can decide what to write in it? instead of having,
let's say, A and B I could put something more descriptive.
best regards
luigi


>>>
cluster <- c(rep("A", 90), rep("B", 100))
sample <- c(
  rep(c("cow-01", "cow-02", "cow-03", "cow-04", "cow-05", "cow-06",
"cow-07", "cow-08", "cow-09", "cow-10", "cow-11",
"cow-12", "cow-13", "cow-14", "cow-15", "cow-16", "cow-17",
"blank"), 5),
  rep(c("cow-26", "cow-35", "cow-36", "cow-37", "cow-38", "cow-39",
"cow-40", "cow-41", "cow-42", "cow-43", "cow-44", "cow-45",
"cow-46", "cow-47", "cow-48", "cow-49", "cow-50", "cow-51",
"cow-59", "blank"), 5)
)
type <- c(
  rep(c("negative", "negative", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "blank"), 5),
  rep(c("negative", "positive", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "positive", "positive", "blank"), 5)
)
target <- c(
c(rep("a", 18), rep("b", 18), rep("c", 18), rep("d", 18), rep("e", 18)),
c(rep("a", 20), rep("b", 20), rep("c", 20), rep("d", 20), rep("e", 20))
)
average <- c(88.5, 49, 41, 33, 35, 45, 95, 30, 41, 64, 22, 29, 59, 71,
128, 39, 42, 47, 86, 100,
 69, 44, 53, 66, 66, 71, 161, 69, 22.5, 30, 67, 99, 129,
94, 49, 33, 28, 31, 26, 23,
 30, 41, 35, 23, 38, 43, 15, 21, 45, 51.5, 34, 26, 43,
32.5, 59, 58.5, 61, 62.5, 58,
 59.5, 60.5, 60, 64, 110, 55, 66, 197, 83.5, 155, 76, 125,
90, 73, 84, 95.5, 62, 82, 1

Re: [R] customize labels useOuterStrips lattice

2017-03-30 Thread Duncan Mackay
Hi Luigi

see
?strip.custom

too late to do any more

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Thursday, 30 March 2017 18:51
To: r-help
Subject: [R] customize labels useOuterStrips lattice

Dear all,
I am plotting some data using lattice and the function useOuterStrips
to make use of more labels. It is possible to customize the labels of
useOuterStrips so I can decide what to write in it? instead of having,
let's say, A and B I could put something more descriptive.
best regards
luigi


>>>
cluster <- c(rep("A", 90), rep("B", 100))
sample <- c(
  rep(c("cow-01", "cow-02", "cow-03", "cow-04", "cow-05", "cow-06",
"cow-07", "cow-08", "cow-09", "cow-10", "cow-11",
"cow-12", "cow-13", "cow-14", "cow-15", "cow-16", "cow-17",
"blank"), 5),
  rep(c("cow-26", "cow-35", "cow-36", "cow-37", "cow-38", "cow-39",
"cow-40", "cow-41", "cow-42", "cow-43", "cow-44", "cow-45",
"cow-46", "cow-47", "cow-48", "cow-49", "cow-50", "cow-51",
"cow-59", "blank"), 5)
)
type <- c(
  rep(c("negative", "negative", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "blank"), 5),
  rep(c("negative", "positive", "negative", "negative", "negative",
"negative", "negative", "negative", "positive", "positive",
"positive", "positive", "positive", "positive", "positive",
"positive", "positive", "positive", "positive", "blank"), 5)
)
target <- c(
c(rep("a", 18), rep("b", 18), rep("c", 18), rep("d", 18), rep("e", 18)),
c(rep("a", 20), rep("b", 20), rep("c", 20), rep("d", 20), rep("e", 20))
)
average <- c(88.5, 49, 41, 33, 35, 45, 95, 30, 41, 64, 22, 29, 59, 71,
128, 39, 42, 47, 86, 100,
 69, 44, 53, 66, 66, 71, 161, 69, 22.5, 30, 67, 99, 129,
94, 49, 33, 28, 31, 26, 23,
 30, 41, 35, 23, 38, 43, 15, 21, 45, 51.5, 34, 26, 43,
32.5, 59, 58.5, 61, 62.5, 58,
 59.5, 60.5, 60, 64, 110, 55, 66, 197, 83.5, 155, 76, 125,
90, 73, 84, 95.5, 62, 82, 138,
 103.5, 57, 138, 149.5, 57, 54, 245.5, 191, 131, 96, 176,
45, 76, 33, 37, 51, 44, 50, 54,
 66, 49, 90, 66.5, 42.5, 67, 56, 54, 50, 45, 99, 50, 51.5,
212, 40, 68, 121, 80, 57,
 81.5, 128, 77, 119.5, 126, 184, 101, 103, 88, 100, 140,
186, 297, 32, 184, 36, 45, 45, 44,
 86, 65, 61, 76, 62, 136, 84, 80, 56, 109, 116, 54, 59,
79, 34, 74.5, 54, 49, 55, 56,
 59, 56, 56, 57, 67, 65, 63, 52, 58, 59, 56, 54, 66, 92,
87, 59, 33, 58, 51, 54,
 52, 47, 45, 42, 52, 57, 79, 42, 45.5, 47, 47, 36, 50, 53, 49 )
stdev <- c(17.85, 6.31, 3.42, 1.04, 0.51, 6.04, 38.43, 2.78, 5.55,
26.72, 1.83, 9.92, 4.59, 19, 7.96,
   7.5, 1.06, 9.66, 75.94, 36.79, 50.45, 9.79, 1.55,
11.42, 64.12, 0.79, 15.14, 16.15, 8.12, 4.04, 92.57, 35.35,
   42.28, 52.96, 7.06, 4.97, 1.15, 4.77, 6.59, 7.27, 0.75,
4.25, 9, 0.1, 1.14, 4.17, 6.73, 3.81, 3.27,
   97.44, 9.74, 0.45, 8.14, 5.91, 13.1, 98.22, 8.92,
72.62, 70.26, 59.46, 29.89, 56.35, 91.25, 49.94, 20.65, 62.04,
   95.13, 35.89, 99.64, 29.44, 33.12, 45.91, 96.69, 9.05,
38.56, 3.09, 0.6, 8.69, 16.95, 74.03, 84.05, 39.87, 15.52,
   27.92, 35.72, 80.26, 71.93, 66.73, 87.8, 5.43, 98.3,
7.41, 9.86, 63.64, 0.36, 5.84, 1.58, 20.1, 4.21, 82.12,
   19.29, 9.02, 22.12, 54.08, 74.95, 3.24, 9.67, 67.98,
9.92, 40.69, 6.24, 8.76, 74.25, 46.34, 25.69, 90.63, 83.71,
   73.53, 57.88, 15.84, 82.07, 67.45, 47.39, 98.77, 75.1,
64.9, 3.71, 87.44, 61.06, 4.77, 57.54, 7.68, 4.54, 6.15,
   3.32, 60.39, 33.78, 66.22, 18.67, 76.53, 63.54, 47.06,
38.47, 88.15, 18.25, 4.26, 67.19, 88.87, 29.65, 7.33, 68.18,
   28.03, 6.91, 77.82, 22.23, 73.23, 95.21, 27.11, 37.01,
34.88, 28.15, 11.27, 15.67, 96.08, 89.52, 28.6, 8.22, 23.55,
   59.2, 

Re: [R] add median value and standard deviation bar to lattice plot

2017-03-18 Thread Duncan Mackay
Hi Luigi

Try this

library(lattice)
library(latticeExtra)
with( dflu,
useOuterStrips(
  strip = strip.custom(par.strip.text = list(cex = 0.75)),
  strip.left = strip.custom(par.strip.text = list(cex = 0.75)),
  dotplot(
average ~ type|target+cluster,
my.data,
horizontal = FALSE,
groups = type,
   # pch=1,
jitter.data = TRUE,
main = "Group-wise",
xlab = expression(bold("Target")), ylab = expression(bold("Reading")),
col = c("grey", "green", "red"),
par.settings = list(strip.background =
list(col=c("paleturquoise","grey")),
superpose.symbol = list(col=c("grey", "green",
"red"),
pch = 1),
dot.line = list(col = "white")),
scales = list(alternating = FALSE, x=list(draw=FALSE)),
key = list(
  space = "top",
  columns = 3,
  text = list(c("Blank", "Negative", "Positive"), col="black"),
  rectangles = list(col=c("grey", "green", "red"))
),
lx = lower, ux = upper,
  panel = panel.superpose,
  panel.groups = function(x,y,horizontal, ..., group.number){
pnl = panel.number()
st <- boxplot.stats(y)
ly = st$conf[1]
uy = st$conf[2]
cat(pnl, ly, uy, "\n")

if (uy != ly){
panel.arrows(x-0.2, ly, x-0.2, uy, col =  c("grey",
"green", "red")[group.number],
 length = 0.1, unit = "in",
 lwd = 2,
 angle = 90, code = 3)

}
panel.xyplot(x, y,  ...)

  }
)
) )

or

with( dflu,
useOuterStrips(
  strip = strip.custom(par.strip.text = list(cex = 0.75)),
  strip.left = strip.custom(par.strip.text = list(cex = 0.75)),
  dotplot(
average ~ type|target+cluster,
my.data,
horizontal = FALSE,
groups = type,
   # pch=1,
jitter.data = TRUE,
main = "Group-wise",
xlab = expression(bold("Target")), ylab = expression(bold("Reading")),
col = c("grey", "green", "red"),
par.settings = list(strip.background =
list(col=c("paleturquoise","grey")),
superpose.symbol = list(col=c("grey", "green",
"red"),
pch = 1),
dot.line = list(col = "white")),
scales = list(alternating = FALSE, x=list(draw=FALSE)),
key = list(
  space = "top",
  columns = 3,
  text = list(c("Blank", "Negative", "Positive"), col="black"),
  rectangles = list(col=c("grey", "green", "red"))
),
lx = lower, ux = upper,
  panel = panel.superpose,
  panel.groups = function(x,y,horizontal, col, ... ){
pnl = panel.number()
st <- boxplot.stats(y)
ly = st$conf[1]
uy = st$conf[2]
cat(pnl, ly, uy, "\n")

if (uy != ly){
panel.arrows(x-0.2, ly, x-0.2, uy, col = col,
 length = 0.1, unit = "in",
 lwd = 2,
 angle = 90, code = 3)

}
    panel.xyplot(x, y,  ...)

  }
)
) )

panel.superpose avoids the needs for subscripts
Used dotplot as I could not get into panel.stripplot easily

made dot.lie white to avoid having lines all over. -- change to transparent

The transparency of the arrows can be added using alpha - need to check
device if can be used
Formula can be changed just used that in demos for lattice

Not sure what you mean by 2

Anyway you have all the right tools here to do it

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Wednesday, 15 March 2017 20:23
To: r-help
Subject: [R] add median value and standard deviation bar to lattice plot

Dear all,
I am analyzing some multivariate data that is organized like this:
1st variable = cluster (A or B)
2nd variable = target (a, b, c, d, e)
3rd variable = type (blank, negative, positive)
4th variable = sample (the actual name of the sample)
5th variable = average (the actual reading -- please not that this is the
mean of different measures with an assumed normal distribution, but the
assumption might not always be t

Re: [R] single strip for the same group in dotplot lattice

2017-02-22 Thread Duncan Mackay
Resending the previous email as the data = mdata2 is wrong for the first
plot should be mdata

dotplot(
  value ~ type|ct,
  mdata,
  groups = typeT,
  par.settings = list(strip.background = list(col="paleturquoise"),
  superpose.symbol = list(col = c(2:4),
  pch = rep(c(1,20),each = 3))),
# type
  scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
  main = "Luminex analysis MTb humans",
  xlab = "Target", 
  ylab = "Reading",
  auto.key = T
)


Adding:
Depending on preferences for cluster (run) and target the new columns could
be changed to suit.

With "duplication" pch and col, rather than arguments themselves can be
adjusted to suit in par.settings which makes doing the key easier

Regards

Duncan


-Original Message-
From: Duncan Mackay [mailto:dulca...@bigpond.com] 
Sent: Thursday, 23 February 2017 13:50
To: R; 'Luigi Marongiu'
Subject: RE: [R] single strip for the same group in dotplot lattice

Hi Liugi

Here are some ideas quickly

4 panels diagonals are blank

mdata = my.data
mdata$ct <- paste(target, "Run", rep(1:2, each = 6))
mdata$typeT <- paste(mdata$target,mdata$type)

dotplot(
  value ~ type|ct,
  mdata2,
  groups = typeT,
  par.settings = list(strip.background = list(col="paleturquoise"),
  superpose.symbol = list(col = c(2:4),
  pch = rep(c(1,20),each = 3))),
# type
  scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
  main = "Luminex analysis MTb humans",
  xlab = "Target", 
  ylab = "Reading",
  auto.key = T,
  panel = panel.superpose
)

# for when the 4 panels have plots not 2 as now
 mdata2 = mdata
 mdata2$target = rep(LETTERS[2:1], ea=6)
 mdata2$value= mdata2$value+0.1
 mdata2 <- rbind(mdata,mdata2)

mdata2$typeT <- paste(mdata2$target,mdata2$type)

 dotplot(
   value ~ type|target + cluster,
   mdata2,
   groups = typeT,
   par.settings = list(strip.background = list(col="paleturquoise"),
   superpose.symbol = list(col = c(2:4),
   pch = rep(c(1,20),each =
3))), # type
   scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
   main = "Luminex analysis MTb humans",
   xlab = "Target", 
   ylab = "Reading",
   auto.key = T,
   panel = panel.superpose
 )


 dotplot(
   value ~ type|ct,
   mdata2,
   groups = typeT,
   par.settings = list(strip.background = list(col="paleturquoise"),
   superpose.symbol = list(col = c(2:4),
   pch = rep(c(1,20),each =
3))), # type
   scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
   main = "Luminex analysis MTb humans",
   strip= strip.custom(factor.levels = paste("Run",1:2),
par.strip.text = list(cex = 1) ),
   xlab = "Target", 
   ylab = "Reading",
   auto.key = T,
   panel = panel.superpose
 )

dotplot(
  value ~ type|cluster,
  mdata2,
  groups = typeT,
  par.settings = list(strip.background = list(col="paleturquoise"),
  superpose.symbol = list(col = c(2:4),
  pch = rep(c(1,20),each = 3))),
# type
  scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
  main = "Luminex analysis MTb humans",
  xlab = "Target", 
  ylab = "Reading",
  auto.key = T,
  panel = panel.superpose
)


Regards

Duncan

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Wednesday, 22 February 2017 21:26
To: P Tennant; r-help
Subject: Re: [R] single strip for the same group in dotplot lattice

Dear Philip,
the data is indeed a toy data: the real one will have 15 panels (=targets)
and two or three clusters. this means that I will have 15 strips with the
label "run 1" = "cluster 1" etc. the point of the toy data is that I get a
4x4 panel plot with 8 strips labelled "run 1", "run 2", "A" and "B". What I
am looking for is to collapse the strips so to get only one label "run 1"
and only one with "run 2" in order to simplify the plot. Hope this helps.
Thanks
Luigi

On Wed, Feb 22, 2017 at 9:53 AM, P Tennant  wrote:

> Hi Luigi,
>
> I'm afraid I don't understand your toy data as you've described it, but if
> you really don't have run 2 for target A, and don't have run 1 for target
> B, why not just create another factor that reflects this, and plot that?
>
>  my

Re: [R] single strip for the same group in dotplot lattice

2017-02-22 Thread Duncan Mackay
Hi Liugi

Here are some ideas quickly

4 panels diagonals are blank

mdata = my.data
mdata$ct <- paste(target, "Run", rep(1:2, each = 6))
mdata$typeT <- paste(mdata$target,mdata$type)

dotplot(
  value ~ type|ct,
  mdata2,
  groups = typeT,
  par.settings = list(strip.background = list(col="paleturquoise"),
  superpose.symbol = list(col = c(2:4),
  pch = rep(c(1,20),each = 3))),
# type
  scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
  main = "Luminex analysis MTb humans",
  xlab = "Target", 
  ylab = "Reading",
  auto.key = T,
  panel = panel.superpose
)

# for when the 4 panels have plots not 2 as now
 mdata2 = mdata
 mdata2$target = rep(LETTERS[2:1], ea=6)
 mdata2$value= mdata2$value+0.1
 mdata2 <- rbind(mdata,mdata2)

mdata2$typeT <- paste(mdata2$target,mdata2$type)

 dotplot(
   value ~ type|target + cluster,
   mdata2,
   groups = typeT,
   par.settings = list(strip.background = list(col="paleturquoise"),
   superpose.symbol = list(col = c(2:4),
   pch = rep(c(1,20),each =
3))), # type
   scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
   main = "Luminex analysis MTb humans",
   xlab = "Target", 
   ylab = "Reading",
   auto.key = T,
   panel = panel.superpose
 )


 dotplot(
   value ~ type|ct,
   mdata2,
   groups = typeT,
   par.settings = list(strip.background = list(col="paleturquoise"),
   superpose.symbol = list(col = c(2:4),
   pch = rep(c(1,20),each =
3))), # type
   scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
   main = "Luminex analysis MTb humans",
   strip= strip.custom(factor.levels = paste("Run",1:2),
par.strip.text = list(cex = 1) ),
   xlab = "Target", 
   ylab = "Reading",
   auto.key = T,
   panel = panel.superpose
 )

dotplot(
  value ~ type|cluster,
  mdata2,
  groups = typeT,
  par.settings = list(strip.background = list(col="paleturquoise"),
  superpose.symbol = list(col = c(2:4),
  pch = rep(c(1,20),each = 3))),
# type
  scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
  main = "Luminex analysis MTb humans",
  xlab = "Target", 
  ylab = "Reading",
  auto.key = T,
  panel = panel.superpose
)


Regards

Duncan

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Wednesday, 22 February 2017 21:26
To: P Tennant; r-help
Subject: Re: [R] single strip for the same group in dotplot lattice

Dear Philip,
the data is indeed a toy data: the real one will have 15 panels (=targets)
and two or three clusters. this means that I will have 15 strips with the
label "run 1" = "cluster 1" etc. the point of the toy data is that I get a
4x4 panel plot with 8 strips labelled "run 1", "run 2", "A" and "B". What I
am looking for is to collapse the strips so to get only one label "run 1"
and only one with "run 2" in order to simplify the plot. Hope this helps.
Thanks
Luigi

On Wed, Feb 22, 2017 at 9:53 AM, P Tennant  wrote:

> Hi Luigi,
>
> I'm afraid I don't understand your toy data as you've described it, but if
> you really don't have run 2 for target A, and don't have run 1 for target
> B, why not just create another factor that reflects this, and plot that?
>
>  my.data$clus2 <- with(my.data, interaction(cluster, target))
>
>  and call: dotplot(value ~ type| clus2, ... )
>
>
> Philip
>
>
> On 22/02/2017 8:03 PM, Luigi Marongiu wrote:
>
>> dear all,
>> I have a set of data that is subdivided in cluster (run 1/run 2) and in
>> target (A/B). When plotting, I obtain a panel strip with "run 1" and "run
>> 2" for each "A" and "B" panel, so "run 1" appears twice and so does "run
>> 2". It is possible to merge the strip together so that I will have "run
1"
>> or "run 2" only once? this will reduce the complexity of the data and
>> allow
>> more space for more detailed information in the strip.
>> the data follows,
>> thank you
>> L
>>
>> cluster<- c(rep("run_1", 6), rep("run_2", 6))
>> type<- rep(c("blank", "positive", "negative"),2)
>> target<- c(rep("A", 6), rep("B", 6))
>> value<- c(0.01, 1.1, 0.5,
>> 0.02, 1.6, 0.8,
>> 0.07, 1.4, 0.7,
>> 0.03, 1.4, 0.4)
>> my.data<- data.frame(cluster, type, target, value)
>>
>> library(lattice)
>> dotplot(
>>value ~ type|target + cluster,
>>my.data,
>>groups = type,
>>pch=21,
>>main = "Luminex analysis MTb humans",
>>xlab = "Target", ylab = "Reading",
>>col = c("grey", "green", "red"),
>>par.settings = list(strip.background = list(col="paleturquoise")),
>>scales = list(alternating = FALSE, x = list(labels = c("", "", ""))),
>>key = list(
>>  space = "top",
>>  columns = 3,
>>  text = list(c("Blank", "Negative", "Positive"), col="black"),
>>  rectangle

Re: [R] cluster data in lattice dotplot and show stdev

2017-02-16 Thread Duncan Mackay
Hi Luigi

I think your data is duplicated

> xtabs(~cluster+type+target,my.data)
, , target = A

   type
cluster blank negative positive
  run_1 222
  run_2 000

, , target = B

   type
cluster blank negative positive
  run_1 000
  run_2 222

> xtabs(~cluster+target,my.data)
   target
cluster A B
  run_1 6 0
  run_2 0 6

I am not sure exactly what you want partly because what Jim has plotted.
I have thought of 2 ways. I have added columns coding the factors as numeric
to make it flexible

1. By runs
my.data$Target <- paste0(rep(LETTERS[1:2],each= 6),rep(1:2,each=3))
my.data$x <- rep(c(0.8,1.2),each=3)
my.data$xrun <- rep(1:3)

xyplot(value ~ x|target,my.data,
   groups = type,
   xlim = c(0.5,1.5),
   scales = list(x = list(at= c(0.8,1.2),
 label=paste("Run",1:2)),
 alternating = 1),
   auto.key = list(points = T,
   lines = F),
   pch=16,
   panel = panel.superpose,
   panel.groups = function(x,y,...){
   
panel.xyplot(x,y, ...)

   
   }
)

2. By type

xyplot(value ~ xrun|target,my.data,
   groups = run,
   xlim = c(0,4),   
  par.settings = list(strip.background = list(col = "transparent")),
   scales = list(x = list(at= c(1:3),
 label= unique(my.data$type),
 alternating = 1)),
   auto.key = list(points = T,
   lines = F),
   pch=16,
   panel = panel.superpose,
   panel.groups = function(x,y,...){

panel.xyplot(x,y, ...)


   }
)

If you want error bars use the functions in 
demo(lattice::intervals)
or use your own panel .segments

If you decide not to use default colours etc use 

panel.settings = list(superpose.symbol = list(pch = ... ,
  col = ... ,
  cex = 1))

makes keys easier

example by hand error bars

xyplot(value ~ xrun|target,my.data,
   groups = run,
   xlim = c(0,4),
   par.settings = list(strip.background = list(col = "transparent"),
  grid.pars = list(lineend =
"butt")),
   scales = list(x = list(at= c(1:3),
 label= unique(my.data$type),
 alternating = 1)),
   auto.key = list(points = T,
   lines = F),
   pch=16,
   panel = panel.superpose,
   panel.groups = function(x,y,...,group.number){

panel.xyplot(x,y, ...)

panel.arrows(group.number+0.3, group.number-0.6,
group.number+0.3, group.number-0.4,
  length = 0.04,
  unit = "inches",
  angle = 90,
      code = 3)

   }
)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Friday, 17 February 2017 02:31
To: r-help
Subject: [R] cluster data in lattice dotplot and show stdev

dear all,
i have a set of data that is separated in the variables: cluster (two
runs), type (blank, negative and positive) and target (A and B), each
duplicated. I am plotting it with lattice and the result is a 2x2 matrix
plot in which the top two cells (or panels) are relative to run 2, the
lower to run 2; each panel is then subdivided in target A or B and I have
colour-coded the dots to match the target.
However i would like to have a 1x2 panel plot representing the targets, and
within each panel having a cluster of 3 dots (representing the types) for
run 1 and another for run 2. I tried to represent such requirement in the
rough construction at the end of the example.
also, since each run is actually formed by duplicates, each dot should
indicate the standard deviation of the values.
How would I do that? any tips?
thanks
luigi

>>>
cluster <- c(rep("run_1", 6), rep("run_2", 6))
type <- rep(c("blank", "positive", "negative"),2)
target <- c(rep("A", 6), rep("B", 6))
value <- c(0.01, 1.1, 0.5,
   0.02, 1.6, 0.8,
   0.07, 1.4, 0.7,
   0.03, 1.4, 0.4)
my.data <- data.frame(cluster, type, target, value)

library(lattice)
dotplot(
  value ~ type|cluster + target,
  my.data,
  groups = type,
  pch=21,
  main = "Luminex analysis MTb humans",
  xlab = "Target", ylab = "Reading",
  col = c("grey", "green", "red"),
  par.se

Re: [R] Sweave: Incorporating warnings into a Sweave output chunck

2017-01-04 Thread Duncan Mackay
Hi Thierry

 

Thank you for your comments.

I had considered it in the past but decided against it. 

May think again about switching but would have to change a lot of macros in my 
text editor.

 

Regards

 

Duncan

 

 

From: Thierry Onkelinx [mailto:thierry.onkel...@inbo.be] 
Sent: Thursday, 5 January 2017 07:06
To: Duncan Mackay
Cc: R
Subject: Re: [R] Sweave: Incorporating warnings into a Sweave output chunck

 

Dear Duncan,

 

I'd recommend to switch from Sweave to knitr. Knitr has more options for 
handling warnings and errors than Sweave.

 

Best regards,




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and 
Forest 
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance 
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more than 
asking him to perform a post-mortem examination: he may be able to say what the 
experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner 
The combination of some data and an aching desire for an answer does not ensure 
that a reasonable answer can be extracted from a given body of data. ~ John 
Tukey

 

2017-01-04 4:07 GMT+01:00 Duncan Mackay :

Dear All

There are some occasions I have run code in R without warning.
After incorporating the code into an .Rnw file and running by Sweave I find
there are  warnings sent to the screen.

On some occasions when I use Sweave(...)  I would like to incorporate the
warnings into the resulting tex file.
Until now I have done it manually which is a bit of a pain.

Does anyone know of a way?  It would be nice to have a Sweave option to
include it.

The only reference I can find is

https://stat.ethz.ch/pipermail/r-help/2006-December/121892.html

which had no replies except this one on Nabble

http://r.789695.n4.nabble.com/R-Sweave-and-warning-messages-td814182.html

I have got the code from the attached Rnw file working in R version 3.3.1
But there are some problems with it.

Below is  the code including some of the options and setup with the function
in one chunck

<>=
  options(warn = 1)
  cons <- showConnections(all = TRUE)
 # .CurFileName <- get("file", env = parent.frame(3)) # modified by next
line
  .CurFileName <-
  as.vector(unlist(
  subset(data.frame(cons), class == "file" & nchar(description) > 0)[1]) )
  .PrefixName <- strsplit(.CurFileName, "\\.  ")[[1]][1]
  .LatexFileName <- paste(.PrefixName, "tex", sepo = ".")
  .LatexFileCon <-
  getConnection(what = as.integer(rownames(cons)[which(cons[,1] ==
.LatexFileName)]))
  sink(file = .LatexFileCon, append = TRUE, type = "message")

warningbck <- warning
warning <-
function (..., call. = TRUE, immediate. = FALSE, domain = NULL){

  args <- list(...)

  if (length(args) == 1 && inherits(args[[1]], "condition")) {

cond <- args[[1]]
message <- conditionMessage(cond)
call <- conditionCall(cond)

withRestarts({
  .Internal(.signalCondition(cond, message, call))
  .Internal(.dfltStop(message, call))
},
muffleWarning = function() NULL)

invisible(message)

  }  else {

if (length(args) > 0) {

  args <- lapply(list(...), as.character)

  if (is.null(domain) || !is.na(domain))
args <- .Internal(gettext(domain, unlist(args)))
message <- paste(args, collapse = "")

} else{

  message <- ""
}

writeLines(text = "\n\\end{Sinput}\n\\begin{Soutput}", con =
.LatexFileCon)
.Internal(warning(as.logical(call.), as.logical(immediate.), message))

writeLines(text = "\\end{Soutput}\n\\begin{Sinput} 
 ", con =
.LatexFileCon)
  }
}

This puts the warning into the input chunck directly after the R command
e.g. as shown below

\begin{Sinput}
  clust.hw <- svydesign(ids = ~Patient, data = hw.dat)Warning in
svydesign.default(ids = ~Patient, data = hwd) :
  No weights or probabilities supplied, assuming equal probability

\end{Sinput}

I think that there also needs to be an argument about closing connections
somewhere in the code.

 Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

__
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] Sweave: Incorporating warnings into a Sweave output chunck

2017-01-03 Thread Duncan Mackay
Dear All

There are some occasions I have run code in R without warning. 
After incorporating the code into an .Rnw file and running by Sweave I find
there are  warnings sent to the screen.  

On some occasions when I use Sweave(...)  I would like to incorporate the
warnings into the resulting tex file.
Until now I have done it manually which is a bit of a pain.

Does anyone know of a way?  It would be nice to have a Sweave option to
include it.

The only reference I can find is 

https://stat.ethz.ch/pipermail/r-help/2006-December/121892.html

which had no replies except this one on Nabble

http://r.789695.n4.nabble.com/R-Sweave-and-warning-messages-td814182.html

I have got the code from the attached Rnw file working in R version 3.3.1 
But there are some problems with it.

Below is  the code including some of the options and setup with the function
in one chunck
 
<>=
  options(warn = 1)
  cons <- showConnections(all = TRUE)
 # .CurFileName <- get("file", env = parent.frame(3)) # modified by next
line
  .CurFileName <-
  as.vector(unlist(
  subset(data.frame(cons), class == "file" & nchar(description) > 0)[1]) )
  .PrefixName <- strsplit(.CurFileName, "\\.")[[1]][1]
  .LatexFileName <- paste(.PrefixName, "tex", sepo = ".")
  .LatexFileCon <-
  getConnection(what = as.integer(rownames(cons)[which(cons[,1] ==
.LatexFileName)]))
  sink(file = .LatexFileCon, append = TRUE, type = "message")

warningbck <- warning
warning <-
function (..., call. = TRUE, immediate. = FALSE, domain = NULL){

  args <- list(...)

  if (length(args) == 1 && inherits(args[[1]], "condition")) {

cond <- args[[1]]
message <- conditionMessage(cond)
call <- conditionCall(cond)

withRestarts({
  .Internal(.signalCondition(cond, message, call))
  .Internal(.dfltStop(message, call))
},
muffleWarning = function() NULL)

invisible(message)

  }  else {

if (length(args) > 0) {

  args <- lapply(list(...), as.character)

  if (is.null(domain) || !is.na(domain))
args <- .Internal(gettext(domain, unlist(args)))
message <- paste(args, collapse = "")

} else{

  message <- ""
}

writeLines(text = "\n\\end{Sinput}\n\\begin{Soutput}", con =
.LatexFileCon)
.Internal(warning(as.logical(call.), as.logical(immediate.), message))

writeLines(text = "\\end{Soutput}\n\\begin{Sinput}", con =
.LatexFileCon)
  }
}

This puts the warning into the input chunck directly after the R command
e.g. as shown below

\begin{Sinput}
  clust.hw <- svydesign(ids = ~Patient, data = hw.dat)Warning in
svydesign.default(ids = ~Patient, data = hwd) :
  No weights or probabilities supplied, assuming equal probability

\end{Sinput}

I think that there also needs to be an argument about closing connections
somewhere in the code.

 Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

__
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] about data format in R

2016-12-30 Thread Duncan Mackay
Hi

Is this the output from Excel?
If so format it in Excel for a date format not a date-time format . 
Depending how the dates were inputted into Excel and the Excel setup a date
may not be a date format.
There are no rules with microsoft formatting so beware!


Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
Sent: Saturday, 31 December 2016 05:38
To: Rui Barradas
Cc: R mailing list
Subject: Re: [R] about data format in R

Hi Rui,

Thanks for your reply. When I read in data using my code, the first column
ranges from 0 to 1. So when I use the code you wrote, it shows the error
message:
Error in as.POSIXct.numeric(DF$Date, format = "%m/%d/%Y-%H:%M:%S") :
'origin' must be supplied


On Fri, Dec 30, 2016 at 11:23 AM, Rui Barradas  wrote:

> Hello,
>
> Have you tried
>
> df$date <- as.POSIXct(dat$date, format = "%m/%d/%Y-%H:%M:%S")
>
> ?
>
> Hope this helps,
>
> Rui Barradas
>
>
>
> Em 30-12-2016 17:40, lily li escreveu:
>
>> Hi R users,
>>
>> I'm trying to read in data, and then plot time series data. However, I
>> have
>> some problems. In my dataset, the first column represents time, and in
the
>> format:
>> mm/dd/-hr:min:sec; For example, 10/01/1995-00:00:00,
>> 10/01/1995-06:00:00, etc.
>>
>> df:
>> dateevap precipintercept
>> 10/01/1995-00:00:00   1.5  20.2
>> 10/01/1995-12:00:00   1.7  2.2 0.1
>> 10/02/1995-00:00:00   1.5  1.8 0.3
>> ...
>>
>> My code is like this
>> file1 = read.table('df', head=T)
>>
>> When I read in data, I found that it read incorrectly. How to format when
>> read in data? 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/posti
>> ng-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-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] \n and italic() in legend()

2016-12-29 Thread Duncan Mackay
Hi Marc

I forgot about the other things than atop in my reply. Others seem to have
exhausted base graphics options
Could using grid.text solve your problems ?

e.g. Guide code

plot(1,1)

grid.clip()

vp <- viewport(width = 1, height = 1)

 pushViewport(vp)

grid.text( "text", 0.25,0.25)
popViewport(0)

Regards

Duncan

-Original Message-
From: Marc Girondot [mailto:marc_...@yahoo.fr] 
Sent: Friday, 30 December 2016 08:46
To: Duncan Mackay; w...@caa.columbia.edu; R-help Mailing List
Subject: Re: [R] \n and italic() in legend()

Hi,
Thanks a lot to Duncan Mackay for the trick using atop() [but the 
legends are centered and not left aligned] and also for the suggestion 
of William Michels to use simply ",". However this last solution 
prevents to use several legends.

Here is a solution to allow both return within a legend and several legends:
plot(1, 1)
v1 <- c(expression(italic("p")*"-value"), expression("based on 
"*italic("t")*"-test"))
v2 <- c(expression(italic("w")*"-value for A"), expression("and B 
identical models"))
legend("topright", legend=c(v1, v2), lty=c(1, 0, 1, 0), y.intersp = 1, 
bty="n", col=c("black", "", "red", ""))

Thanks again

Marc


Le 29/12/2016 à 10:54, Duncan Mackay a écrit :
> Hi Marc
>
> Try atop
>
> plot(1, 1)
> v1 <- expression(atop(italic("p")*"-value","based on
"*italic("t")*"-test"))
> legend("topright", legend=v1, y.intersp = 3, bty="n")
>
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marc
> Girondot via R-help
> Sent: Thursday, 29 December 2016 20:35
> To: R-help Mailing List
> Subject: [R] \n and italic() in legend()
>
> Hi everyone,
>
> Could someone help me to get both \n (return) and italic() in a legend.
> Here is a little example showing what I would like (but without the
> italic) and second what I get:
>
> plot(1, 1)
> v1 <- "p-value\nbased on t-test"
> legend("topright", legend=v1, y.intersp = 3, bty="n")
>
> plot(1, 1)
> v1 <- expression(italic("p")*"-value\nbased on "*italic("t")*"-test")
> legend("topright", legend=v1, y.intersp = 3, bty="n")
>
> The second one shows :
>
> -value
> pbased on t-test
>
> rather than the expected:
>
> p-value
> based on t-test
>
> Thanks a lot,
>
> Marc
>
> __
> 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-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-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] \n and italic() in legend()

2016-12-29 Thread Duncan Mackay
Hi Marc

Try atop

plot(1, 1)
v1 <- expression(atop(italic("p")*"-value","based on "*italic("t")*"-test"))
legend("topright", legend=v1, y.intersp = 3, bty="n")


Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marc
Girondot via R-help
Sent: Thursday, 29 December 2016 20:35
To: R-help Mailing List
Subject: [R] \n and italic() in legend()

Hi everyone,

Could someone help me to get both \n (return) and italic() in a legend. 
Here is a little example showing what I would like (but without the 
italic) and second what I get:

plot(1, 1)
v1 <- "p-value\nbased on t-test"
legend("topright", legend=v1, y.intersp = 3, bty="n")

plot(1, 1)
v1 <- expression(italic("p")*"-value\nbased on "*italic("t")*"-test")
legend("topright", legend=v1, y.intersp = 3, bty="n")

The second one shows :

-value
pbased on t-test

rather than the expected:

p-value
based on t-test

Thanks a lot,

Marc

__
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-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] How to overlay lines and rectangles in lattice plot key

2016-12-28 Thread Duncan Mackay
I forgot to change the xyplot for the colours; if you want the same colours
in the key you need to use the par.settings argument or set the settings for
the device.

the xyplot becomes

xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
   iris,
   par.settings = list(superpose.symbol = list(col = 1:4,
   cex = 1,
   pch = 1:4),
   superpose.line = list(col = 1:4)
  ),
   type = c("p", "r"),
   jitter.x = TRUE,
   jitter.y = TRUE,
   factor = 5,
   legend = list(right = list(fun = XY04.fmG))
)
 
Duncan

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan
Mackay
Sent: Thursday, 29 December 2016 18:21
To: R
Subject: Re: [R] How to overlay lines and rectangles in lattice plot key

Hi 

It makes it easier

library(grid)
library(lattice)

# legend
XY04.glay <-
grid.layout(nrow = 4,
ncol = 2,
heights = unit(rep(1, 2), rep("cm", 2)),
widths  = unit(c(0.4, 0.8),
   c("in","in")),
just = "centre")

XY04.fmG <- frameGrob(layout = XY04.glay)

k <-0
for (j in seq_len(4)){

  XY04.fmG <-
  placeGrob(XY04.fmG, textGrob(lab = letters[j],
 just = 0,
 gp = gpar(cex = 0.8)), row = j, col = 1)
  XY04.fmG <-
  placeGrob(XY04.fmG, rectGrob(width = 0.6,
   gp = gpar(col=j,
 alpha = 0.25,
 fill = j)), row = j, col = 2)
  XY04.fmG <-
  placeGrob(XY04.fmG, linesGrob(c(0.2,0.8),  c(0.5, 0.5),
  gp = gpar(col = j)), row = j, col = 2)
  XY04.fmG <-
  placeGrob(XY04.fmG, pointsGrob(x = unit(1, "cm"), y = unit(0.5, "npc"),
  pch = j,
  #width = unit(2, "cm"),
  gp = gpar(cex = 0.7, col = j)), row = j, col =
2)
}

xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
   iris,
   type = c("p", "r"),
   jitter.x = TRUE,
   jitter.y = TRUE,
   factor = 5,
   legend = list(right = list(fun = XY04.fmG))
)

This gives 1 point instead of 2 or 3.
The OP needs to change the format and fix the heights of the rectangles etc.
I also fixed the colour vectors had j instead of k


Duncan

-Original Message-
From: Duncan Mackay [mailto:dulca...@bigpond.com] 
Sent: Thursday, 29 December 2016 16:17
To: R
Subject: RE: [R] How to overlay lines and rectangles in lattice plot key

Hi

Is this something like what you are looking for?
I have put it on the right and heights etc are just a quick guess. (all i
have time for)
It may be a little too complicated for what you want but I thought  of this
first based on your description rather than the plot.

library(grid)
library(lattice)

# legend
XY04.glay <-
grid.layout(nrow = 8,
ncol = 2,
heights = unit(rep(1, 2), rep("cm", 2)),
widths  = unit(c(0.4, 0.8),
   c("in","in")),
just = "centre")

XY04.fmG <- frameGrob(layout = XY04.glay)

k <-0
for (j in seq(1,8,2)){
  k = k+1
  
  XY04.fmG <-
  placeGrob(XY04.fmG, textGrob(lab = letters[1:4][k],
 just = 0,
 gp = gpar(cex = 0.8)), row = j, col = 1)
  XY04.fmG <-
  placeGrob(XY04.fmG, linesGrob(c(0.2,0.8),  c(0.5, 0.5),
  gp = gpar(col = c(1:4)[k])), row = j, col = 2)
  XY04.fmG <-
  placeGrob(XY04.fmG, pointsGrob(c(0.2,0.8),  c(0.5, 0.5),
  pch = j,
  gp = gpar(cex = 0.7, col = c(1:4)[k])), row =
j, col = 2)
}
k = 0
for (j in seq(2,8,2)){
  k = k+1
  XY04.fmG <-
  placeGrob(XY04.fmG, rectGrob(width = 0.6,
   gp = gpar(col=k,
 alpha = 0.25,
 fill = k)), row = j, col = 2)

}

xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
   iris,
   type = c("p", "r"),
   jitter.x = TRUE,
   jitter.y = TRUE,
   factor = 5,
   legend = list(right = list(fun = XY04.fmG))
)


Have a look at https://stat.ethz.ch/pipermail/r-help/2005-April/069459.html
and the following emails on the thread.

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of sbihorel
Sent: Thursday, 29 December 2016 13:51
To: r-help@r-project.org
Subject: [R] How to overlay lines and rectangles in lattice plot key

Hi,

I would like to create a custom key 

Re: [R] How to overlay lines and rectangles in lattice plot key

2016-12-28 Thread Duncan Mackay
Hi 

It makes it easier

library(grid)
library(lattice)

# legend
XY04.glay <-
grid.layout(nrow = 4,
ncol = 2,
heights = unit(rep(1, 2), rep("cm", 2)),
widths  = unit(c(0.4, 0.8),
   c("in","in")),
just = "centre")

XY04.fmG <- frameGrob(layout = XY04.glay)

k <-0
for (j in seq_len(4)){

  XY04.fmG <-
  placeGrob(XY04.fmG, textGrob(lab = letters[j],
 just = 0,
 gp = gpar(cex = 0.8)), row = j, col = 1)
  XY04.fmG <-
  placeGrob(XY04.fmG, rectGrob(width = 0.6,
   gp = gpar(col=j,
 alpha = 0.25,
 fill = j)), row = j, col = 2)
  XY04.fmG <-
  placeGrob(XY04.fmG, linesGrob(c(0.2,0.8),  c(0.5, 0.5),
  gp = gpar(col = j)), row = j, col = 2)
  XY04.fmG <-
  placeGrob(XY04.fmG, pointsGrob(x = unit(1, "cm"), y = unit(0.5, "npc"),
  pch = j,
  #width = unit(2, "cm"),
  gp = gpar(cex = 0.7, col = j)), row = j, col =
2)
}

xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
   iris,
   type = c("p", "r"),
   jitter.x = TRUE,
   jitter.y = TRUE,
   factor = 5,
   legend = list(right = list(fun = XY04.fmG))
)

This gives 1 point instead of 2 or 3.
The OP needs to change the format and fix the heights of the rectangles etc.
I also fixed the colour vectors had j instead of k


Duncan

-Original Message-
From: Duncan Mackay [mailto:dulca...@bigpond.com] 
Sent: Thursday, 29 December 2016 16:17
To: R
Subject: RE: [R] How to overlay lines and rectangles in lattice plot key

Hi

Is this something like what you are looking for?
I have put it on the right and heights etc are just a quick guess. (all i
have time for)
It may be a little too complicated for what you want but I thought  of this
first based on your description rather than the plot.

library(grid)
library(lattice)

# legend
XY04.glay <-
grid.layout(nrow = 8,
ncol = 2,
heights = unit(rep(1, 2), rep("cm", 2)),
widths  = unit(c(0.4, 0.8),
   c("in","in")),
just = "centre")

XY04.fmG <- frameGrob(layout = XY04.glay)

k <-0
for (j in seq(1,8,2)){
  k = k+1
  
  XY04.fmG <-
  placeGrob(XY04.fmG, textGrob(lab = letters[1:4][k],
 just = 0,
 gp = gpar(cex = 0.8)), row = j, col = 1)
  XY04.fmG <-
  placeGrob(XY04.fmG, linesGrob(c(0.2,0.8),  c(0.5, 0.5),
  gp = gpar(col = c(1:4)[k])), row = j, col = 2)
  XY04.fmG <-
  placeGrob(XY04.fmG, pointsGrob(c(0.2,0.8),  c(0.5, 0.5),
  pch = j,
  gp = gpar(cex = 0.7, col = c(1:4)[k])), row =
j, col = 2)
}
k = 0
for (j in seq(2,8,2)){
  k = k+1
  XY04.fmG <-
  placeGrob(XY04.fmG, rectGrob(width = 0.6,
   gp = gpar(col=k,
 alpha = 0.25,
 fill = k)), row = j, col = 2)

}

xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
   iris,
   type = c("p", "r"),
   jitter.x = TRUE,
   jitter.y = TRUE,
   factor = 5,
   legend = list(right = list(fun = XY04.fmG))
)


Have a look at https://stat.ethz.ch/pipermail/r-help/2005-April/069459.html
and the following emails on the thread.

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of sbihorel
Sent: Thursday, 29 December 2016 13:51
To: r-help@r-project.org
Subject: [R] How to overlay lines and rectangles in lattice plot key

Hi,

I would like to create a custom key for a lattice xyplot in which line 
elements are displayed on top of rectangle elements. In the example code 
below, the lines and rectangles are shown side by side (the legend 
itself is meaningless, but that is not the point). Is there a way to 
overlay these key elements (but not the text)?

Thanks

xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
   iris,
   type = c("p", "r"),
   jitter.x = TRUE,
   jitter.y = TRUE,
   factor = 5,
   key = list(
 column=4,
 text=list(lab=letters[1:4]),
 lines=list(col=1:4, pch=1:4, type='b'),
 rectangles=list(col=1:4, alpha=0.25, border=FALSE)
   )
)

__
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.htm

Re: [R] How to overlay lines and rectangles in lattice plot key

2016-12-28 Thread Duncan Mackay
Hi

Is this something like what you are looking for?
I have put it on the right and heights etc are just a quick guess. (all i
have time for)
It may be a little too complicated for what you want but I thought  of this
first based on your description rather than the plot.

library(grid)
library(lattice)

# legend
XY04.glay <-
grid.layout(nrow = 8,
ncol = 2,
heights = unit(rep(1, 2), rep("cm", 2)),
widths  = unit(c(0.4, 0.8),
   c("in","in")),
just = "centre")

XY04.fmG <- frameGrob(layout = XY04.glay)

k <-0
for (j in seq(1,8,2)){
  k = k+1
  
  XY04.fmG <-
  placeGrob(XY04.fmG, textGrob(lab = letters[1:4][k],
 just = 0,
 gp = gpar(cex = 0.8)), row = j, col = 1)
  XY04.fmG <-
  placeGrob(XY04.fmG, linesGrob(c(0.2,0.8),  c(0.5, 0.5),
  gp = gpar(col = c(1:4)[k])), row = j, col = 2)
  XY04.fmG <-
  placeGrob(XY04.fmG, pointsGrob(c(0.2,0.8),  c(0.5, 0.5),
  pch = j,
  gp = gpar(cex = 0.7, col = c(1:4)[k])), row =
j, col = 2)
}
k = 0
for (j in seq(2,8,2)){
  k = k+1
  XY04.fmG <-
  placeGrob(XY04.fmG, rectGrob(width = 0.6,
   gp = gpar(col=k,
 alpha = 0.25,
 fill = k)), row = j, col = 2)

}

xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
   iris,
   type = c("p", "r"),
   jitter.x = TRUE,
   jitter.y = TRUE,
   factor = 5,
   legend = list(right = list(fun = XY04.fmG))
)


Have a look at https://stat.ethz.ch/pipermail/r-help/2005-April/069459.html
and the following emails on the thread.

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of sbihorel
Sent: Thursday, 29 December 2016 13:51
To: r-help@r-project.org
Subject: [R] How to overlay lines and rectangles in lattice plot key

Hi,

I would like to create a custom key for a lattice xyplot in which line 
elements are displayed on top of rectangle elements. In the example code 
below, the lines and rectangles are shown side by side (the legend 
itself is meaningless, but that is not the point). Is there a way to 
overlay these key elements (but not the text)?

Thanks

xyplot(Sepal.Length + Sepal.Width ~ Petal.Length + Petal.Width,
   iris,
   type = c("p", "r"),
   jitter.x = TRUE,
   jitter.y = TRUE,
   factor = 5,
   key = list(
 column=4,
 text=list(lab=letters[1:4]),
 lines=list(col=1:4, pch=1:4, type='b'),
 rectangles=list(col=1:4, alpha=0.25, border=FALSE)
   )
)

__
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-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] data manipulation

2016-12-19 Thread Duncan Mackay
, 210.8, 203.6, 175.2, 
168.7, 155.9, 147.3, 137, 141.1, 167.4, 160.2, 191.9, 174.4, 
208.2, 159.4, 161.1, 172.1, 158.4, 114.6, 159.6, 159.7, 159.4, 
160.7, 165.5, 205, 205.2, 141.6, 148.1, 184.9, 132.5, 137.3, 
135.5, 121.7, 166.1, 146.8, 162.8, 186.8, 185.5, 151.5, 158.1, 
143, 151.2, 147.6, 130.7, 137.5, 146.1, 133.6, 167.9, 181.9, 
202, 166.5, 151.3, 146.2, 148.3, 144.7, 123.6, 151.6, 133.9, 
137.4, 181.6, 182, 190, 161.2, 155.5, 141.9, 164.6, 136.2, 126.8, 
152.5, 126.6, 150.1, 186.3, 147.5, 200.4, 177.2, 127.4, 177.1, 
154.4, 135.2, 126.4, 147.3, 140.6, 152.3, 151.2, 172.2, 215.3, 
154.1, 159.3, 160.4, 151.9, 148.4, 139.6, 148.2, 153.5, 145.1, 
183.7, 210.5, 203.3, 153.3, 144.3, 169.6, 143.7, 160, 135.5, 
141.7, 159.9, 145.6, 183.4, 198.1, 186.7, 171.9, 150.5, 163, 
153.6, 152.8, 135.4, 148.3, 148.3, 133.5, 193.8, 208.4, 197), 
elec = c(1497L, 1463L, 1648L, 1595L, 1777L, 1824L, 1994L, 
1835L, 1787L, 1699L, 1633L, 1645L, 1597L, 1577L, 1709L, 1756L, 
1936L, 2052L, 2105L, 2016L, 1914L, 1925L, 1824L, 1765L, 1721L, 
1752L, 1914L, 1857L, 2159L, 2195L, 2287L, 2276L, 2096L, 2055L, 
2004L, 1924L, 1851L, 1839L, 2019L, 1937L, 2270L, 2251L, 2382L, 
2364L, 2129L, 2110L, 2072L, 1980L, 1995L, 1932L, 2171L, 2162L, 
2489L, 2424L, 2641L, 2630L, 2324L, 2412L, 2284L, 2186L, 2184L, 
2144L, 2379L, 2383L, 2717L, 2774L, 3051L, 2891L, 2613L, 2600L, 
2493L, 2410L, 2390L, 2463L, 2616L, 2734L, 2970L, 3125L, 3342L, 
3207L, 2964L, 2919L, 2764L, 2732L, 2622L, 2698L, 2950L, 2895L, 
3200L, 3408L, 3679L, 3473L, 3154L, 3107L, 3052L, 2918L, 2786L, 
2739L, 3125L, 3033L, 3486L, 3661L, 3927L, 3851L, 3456L, 3390L, 
3280L, 3166L, 3080L, 3069L, 3340L, 3310L, 3798L, 3883L, 4191L, 
4213L, 3766L, 3628L, 3520L, 3322L, 3250L, 3287L, 3552L, 3440L, 
4153L, 4265L, 4655L, 4492L, 4051L, 3967L, 3807L, 3639L, 3647L, 
3560L, 3929L, 3858L, 4485L, 4697L, 4977L, 4675L, 4596L, 4491L, 
4127L, 4144L, 4014L, 3994L, 4320L, 4400L, 5002L, 5091L, 5471L, 
5193L, 4997L, 4737L, 4546L, 4498L, 4350L, 4206L, 4743L, 4582L, 
5191L, 5457L, 5891L, 5618L, 5158L, 5030L, 4800L, 4654L, 4453L, 
4440L, 4945L, 4788L, 5425L, 5706L, 6061L, 5846L, 5242L, 5408L, 
5114L, 5042L, 5008L, 4657L, 5359L, 5193L, 5891L, 5980L, 6390L, 
6366L, 5756L, 5640L, 5429L, 5398L, 5413L, 5141L, 5695L, 5554L, 
6369L, 6592L, 7107L, 6917L, 6353L, 6205L, 5830L, 5646L, 5379L, 
5489L, 5824L, 5907L, 6482L, 6795L, 7028L, 6776L, 6274L, 6362L, 
5940L, 5958L, 5769L, 5887L, 6367L, 6165L, 6868L, 7201L, 7601L, 
7581L, 7090L, 6841L, 6408L, 6435L, 6176L, 6138L, 6717L, 6470L, 
7312L, 7763L, 8171L, 7788L, 7311L, 6679L, 6704L, 6724L, 6552L, 
6427L, 7105L, 6869L, 7683L, 8082L, 8555L, 8386L, 7553L, 7398L, 
7112L, 6886L, 7077L, 6820L, 7426L, 7143L, 8261L, 8240L, 8977L, 
8991L, 8026L, 7911L, 7510L, 7381L, 7366L, 7414L, 7824L, 7524L, 
8279L, 8707L, 9486L, 8973L, 8231L, 8206L, 7927L, 7999L, 7834L, 
7521L, 8284L, 7999L, 8940L, 9381L, 10078L, 9796L, 8471L, 
8572L, 8150L, 8168L, 8166L, 7903L, 8606L, 8071L, 9178L, 9873L, 
10476L, 9296L, 8818L, 8697L, 8381L, 8293L, 7942L, 8001L, 
8744L, 8397L, 9115L, 9773L, 10358L, 9849L, 9083L, 9143L, 
8800L, 8741L, 8492L, 8795L, 9354L, 8796L, 10072L, 10174L, 
11326L, 10744L, 9806L, 9740L, 9373L, 9244L, 9407L, 8827L, 
9880L, 9364L, 10580L, 10899L, 11687L, 11280L, 10208L, 10212L, 
9725L, 9721L, 9846L, 9407L, 10265L, 9970L, 10801L, 11246L, 
12167L, 11578L, 10645L, 10613L, 10104L, 10348L, 10263L, 9973L, 
10803L, 10409L, 11458L, 11845L, 12559L, 12070L, 11221L, 11338L, 
10761L, 11012L, 10923L, 10790L, 11427L, 10788L, 11772L, 12104L, 
12634L, 12772L, 11764L, 11956L, 11646L, 11750L, 11485L, 11198L, 
12265L, 11704L, 12419L, 13259L, 13945L, 13839L, 12387L, 12546L, 
12038L, 11977L, 12336L, 11793L, 12877L, 11923L, 13306L, 13988L, 
14002L, 14338L, 12867L, 12761L, 12449L, 12658L)), .Names = c("choc", 
"beer", "elec"), class = "data.frame", row.names = c(NA, -396L
))

Regards

Duncan

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Monday, 19 December 2016 13:47
To: Duncan Mackay
Cc: R
Subject: Re: [R] data manipulation


> On Dec 18, 2016, at 5:39 PM, Duncan Mackay  wrote:
> 
> 
> Hi David
> 
> Thanks for the info. 
> As a test I am attaching it anyway

Nothing allowed as an attachment by the server.

--
David.
> 
> Regards
> 
> Duncan
> 
> -Original Message-
> From: David Winsemius [mailto:dwinsem...@comcast.net] 
> Sent: Monday, 19 December 2016 05:36
> To: Duncan Mackay
> Cc: R
> Subject: Re: [R] data manipulation
> 
> 
>> On Dec 17, 2016, at 7:57 PM, Duncan Mackay  wrote:
>> 
>> Hi 
>> 
>> Coming late to the discussion  - I deleted the original message
>> I found that I have a cbe.dat that I downloaded some years ago from
>> cowpertwaite's site

Re: [R] data manipulation

2016-12-18 Thread Duncan Mackay

Hi David

Thanks for the info. 
As a test I am attaching it anyway

Regards

Duncan

-Original Message-
From: David Winsemius [mailto:dwinsem...@comcast.net] 
Sent: Monday, 19 December 2016 05:36
To: Duncan Mackay
Cc: R
Subject: Re: [R] data manipulation


> On Dec 17, 2016, at 7:57 PM, Duncan Mackay  wrote:
> 
> Hi 
> 
> Coming late to the discussion  - I deleted the original message
> I found that I have a cbe.dat that I downloaded some years ago from
> cowpertwaite's site .
> 
> And have attached it

Experience has shown that when you attach a file that you hope to be
distributed to the list it needs to have a .txt extension. Leaving it with a
.csv, .tsv, or .dat extension will cause it to be dropped by the server,
even if the contents of the file are ASCII text.

The URL I offered earlier should have made the file available:
https://web.archive.org/web/20130501161812/http://staff.elena.aut.ac.nz/Paul
-Cowpertwait/ts/cbe.dat

... but if there is interest in having it in the Rhelp Archive, I can attach
it.



-- 
David.
> 
> If it does not get through will do a dput as the file is only 7K
> 
> Regards
> 
> Duncan
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
> 
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rui
Barradas
> Sent: Thursday, 15 December 2016 01:19
> To: Farshad Fathian; r-help
> Subject: Re: [R] data manipulation
> 
> Hello,
> 
> Please cc your mails to the list.
> As for your data, your url is wrong, you need to contact Massey or maybe 
> the source of your information and get a valid internet address.
> Without one there's not much we can do.
> 
> Rui Barradas
> 
> Em 14-12-2016 12:16, Farshad Fathian escreveu:
>> Hello,
>> 
>> Thanks for your e-mail. I was reading "Introductory Time Series with R"
>> by PS. Cowperwait. I am going to run the R codes in this book, but I
>> don't access to the input data from
>> ("http://massey.ac.nz/~pscoperwait/ts/cbe.dat
>> <http://massey.ac.nz/~pscoperwait/ts/cbe.dat>") website.
>> 
>> Regards,
>> 
>> On Wed, Dec 14, 2016 at 3:42 PM, Rui Barradas > <mailto:ruipbarra...@sapo.pt>> wrote:
>> 
>>Hello,
>> 
>>What do you mean by "gives me something"?
>> 
>>xx <- read.csv("http://massey.ac.nz/~pscoperwait/ts/cbe.dat
>><http://massey.ac.nz/~pscoperwait/ts/cbe.dat>")
>>Error in file(file, "rt") : cannot open the connection
>>In addition: Warning message:
>>In file(file, "rt") :
>>   cannot open URL 'http://massey.ac.nz/~pscoperwait/ts/cbe.dat
>><http://massey.ac.nz/~pscoperwait/ts/cbe.dat>': HTTP status was '404
>>Not Found'
>> 
>>Rui Barradas
>> 
>> 
>>Em 14-12-2016 11:56, John Kane via R-help escreveu:
>> 
>>xx <- read.csv("http://massey.ac.nz/~pscoperwait/ts/cbe.dat
>><http://massey.ac.nz/~pscoperwait/ts/cbe.dat>")
>>gives me something. Since we have no idea of what you are doing
>>I don't know if the data has downloaded correctly
>> 
>>  On Tuesday, December 13, 2016 1:38 PM, Farshad Fathian
>>mailto:farshad.fath...@gmail.com>>
>>wrote:
>> 
>> 
>>   Hi,
>> 
>> 
>> 
>>I couldn't access to data file about PSCoperwait by
>>http://massey.ac.nz/~pscoperwait/ts/cbe.dat
>><http://massey.ac.nz/~pscoperwait/ts/cbe.dat>.
>> 
>> 
>> 
>>Looking forward to hearing from you,
>> 
>> 
>>  [[alternative HTML version deleted]]
>> 
>>__
>>R-help@r-project.org <mailto:R-help@r-project.org> mailing list
>>-- To UNSUBSCRIBE and more, see
>>https://stat.ethz.ch/mailman/listinfo/r-help
>><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.
>> 
>> 
>> 
>> [[alternative HTML version deleted]]
>> 
>>__
>>R-help@r-project.org <mailto:R-help@r-project.org> 

Re: [R] data manipulation

2016-12-17 Thread Duncan Mackay
Hi 

Coming late to the discussion  - I deleted the original message
I found that I have a cbe.dat that I downloaded some years ago from
cowpertwaite's site .

And have attached it

If it does not get through will do a dput as the file is only 7K

Regards

Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rui Barradas
Sent: Thursday, 15 December 2016 01:19
To: Farshad Fathian; r-help
Subject: Re: [R] data manipulation

Hello,

Please cc your mails to the list.
As for your data, your url is wrong, you need to contact Massey or maybe 
the source of your information and get a valid internet address.
Without one there's not much we can do.

Rui Barradas

Em 14-12-2016 12:16, Farshad Fathian escreveu:
> Hello,
>
> Thanks for your e-mail. I was reading "Introductory Time Series with R"
> by PS. Cowperwait. I am going to run the R codes in this book, but I
> don't access to the input data from
> ("http://massey.ac.nz/~pscoperwait/ts/cbe.dat
> <http://massey.ac.nz/~pscoperwait/ts/cbe.dat>") website.
>
> Regards,
>
> On Wed, Dec 14, 2016 at 3:42 PM, Rui Barradas  <mailto:ruipbarra...@sapo.pt>> wrote:
>
> Hello,
>
> What do you mean by "gives me something"?
>
> xx <- read.csv("http://massey.ac.nz/~pscoperwait/ts/cbe.dat
> <http://massey.ac.nz/~pscoperwait/ts/cbe.dat>")
> Error in file(file, "rt") : cannot open the connection
> In addition: Warning message:
> In file(file, "rt") :
>cannot open URL 'http://massey.ac.nz/~pscoperwait/ts/cbe.dat
> <http://massey.ac.nz/~pscoperwait/ts/cbe.dat>': HTTP status was '404
> Not Found'
>
> Rui Barradas
>
>
> Em 14-12-2016 11:56, John Kane via R-help escreveu:
>
> xx <- read.csv("http://massey.ac.nz/~pscoperwait/ts/cbe.dat
> <http://massey.ac.nz/~pscoperwait/ts/cbe.dat>")
> gives me something. Since we have no idea of what you are doing
> I don't know if the data has downloaded correctly
>
>   On Tuesday, December 13, 2016 1:38 PM, Farshad Fathian
> mailto:farshad.fath...@gmail.com>>
> wrote:
>
>
>Hi,
>
>
>
> I couldn't access to data file about PSCoperwait by
> http://massey.ac.nz/~pscoperwait/ts/cbe.dat
> <http://massey.ac.nz/~pscoperwait/ts/cbe.dat>.
>
>
>
> Looking forward to hearing from you,
>
>
>   [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list
> -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> <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.
>
>
>
>  [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org <mailto:R-help@r-project.org> mailing list
> -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> <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.
>
>
>
>
>

__
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-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] How to create a list of trellis objects for grid.arrange()

2016-10-29 Thread Duncan Mackay
Hi

I did not have a look at this when it was sent as I thought it dealt with
ggplot objects 

If you have trellis objects (check by str())or ?class) try printing them 

print(p2, position = (c(0,0,1,0.5), more =T)
print(p1, position = (c(0,0.5,1,1), more = F)

The only other way that I can think of is using viewports
 ? grid::viewports

If it is base graphics then ? layout  may fix it

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Agustin Lobo
Sent: Thursday, 27 October 2016 23:58
To: r-help@r-project.org
Subject: [R] How to create a list of trellis objects for grid.arrange()

Given
require(raster)
require(sp)
require(gridExtra)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)
p1 <- spplot(r)
p2 <- spplot(r)

I would like to plot the equivalent to

grid.arrange(p1,p2,ncol=1,nrow=2)

but keeping the trellis objects p1 and p2 within one single object (as
in practice I have many objects generated within a for() loop).

The following used to work:
ps <- c(p1,p2)
grid.arrange(ps,ncol=1,nrow=2)

but does not work any more.

How should I combine p1 and p2 into one single object that would be
accepted by grid.arrange?

Thanks
-- 
Agustin Lobo
aloboa...@gmail.com

__
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-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] lattice: control panel extent on device

2016-10-25 Thread Duncan Mackay
Hi Ben

A bit kludgy but it works. Further refinement by eye

print(vol_p, position = c(0,0,1,0.5), more = TRUE)
print(xy_p, position = c(0.14,0.5,0.86,1), more = FALSE)

I do not know if viewports will be  any better

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ben Tupper
Sent: Tuesday, 25 October 2016 23:53
To: r-help
Subject: [R] lattice: control panel extent on device

Hello,

I am drawing a levelplot and an xyplot on a single device as shown in the
runnable example below.  I would like the x axes to align - that is for them
to cover the same extent left-to-right on the device. How do I go about
doing that?

###
# START
###
library(lattice)

d <- dim(volcano)
xy <- data.frame(x = 1:d[1], y = volcano[,30] )

vol_p <- levelplot(volcano)
xy_p <- xyplot(y ~ x, data = xy)

print(vol_p, split = c(1, 2, 1, 2), more = TRUE)
print(xy_p,  split = c(1, 1, 1, 2), more = FALSE)
##
#END
##


Thanks!
Ben


> sessionInfo()
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.6 (El Capitan)

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base 

other attached packages:
[1] lattice_0.20-33

loaded via a namespace (and not attached):
[1] tools_3.3.1 grid_3.3.1 



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

__
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-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] Lattice xyplot(): adding a legend

2016-10-19 Thread Duncan Mackay
I had not seen Davids reply so will add to my note

The legend is for special keys or multiple keys

eg
https://stat.ethz.ch/pipermail/r-help/2010-May/240341.html

It may involve draw.key()

Duncan

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan
Mackay
Sent: Thursday, 20 October 2016 16:11
To: R
Subject: Re: [R] Lattice xyplot(): adding a legend

Hi Rich

Without an example to check I think you need to fill in the arguments for
par.settings eg 

par.settings = list(plot.symbol = list(c("black","red","dark green","dark
blue","dark goldenrod","purple"),
pch
= 20,
   cex =
1),
if you have groups 

par.settings = list(superpose.symbol = list(c("black","red","dark
green","dark blue","dark goldenrod","purple"),
 
pch = 20,
 
cex = 1)),

For other types such as barchart  type 
barchart  and at the top there is

plot.symbol <- trellis.par.get("plot.symbol")
plot.line <- trellis.par.get("plot.line")
superpose.symbol <- trellis.par.get("superpose.symbol")
superpose.line <- trellis.par.get("superpose.line")

Similar occurs for panel.xyplot

I find that ? xyplot  and ?panel. ... give the most uptodate methods things
change overtime.
There are some words on how information is passed to the key in ?xyplot
You either have to set trellis.par.set() or use the par.settings arguments

For older versions things may be slightly different.

If in a hurry I try the easiest but if that fails on the first go I just use
key = list(text = ... etc
 
Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rich Shepard
Sent: Thursday, 20 October 2016 10:05
To: r-help@r-project.org
Subject: Re: [R] Lattice xyplot(): adding a legend

On Wed, 19 Oct 2016, Rich Shepard wrote:

>  I did read that but mis-applied what I read. Tried auto.key but that did
> not work as desired. Now I know to learn how to apply 'key'.

   Almost there after another careful reading Section 9.2.3 ff in the book.
Here's the command to produce the plot:

rainbyday <- xyplot(rain$amount ~ raindate, data = rain, main = "Area
Precipitation",
 ylab = "Daily Total Amount (in)", xlab = "Date",
 scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot = 90),
 y = list(at=c(min(rain$amount), max(rain$amount,
 pch = 20,
 col = c("black","red","dark green","dark blue","dark
goldenrod","purple"),
 key = simpleKey(text = levels(rain$station)[1:6],
   x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE))

   My question is how to pass pch = 20 to the key. simpleKey accepts only
the
logical TRUE as an argument and this produces a plot with filled circles for
the data but unfilled circles for the key. I find no example of specifying
pch for points in the key in either the book or ?xyplot, and I'm sure there
is a way of having the key symbols match both pch and color as the data
symbols.

   Is use of Rows() the solution?

Rich

__
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-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-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] Lattice xyplot(): adding a legend

2016-10-19 Thread Duncan Mackay
Hi Rich

Without an example to check I think you need to fill in the arguments for
par.settings eg 

par.settings = list(plot.symbol = list(c("black","red","dark green","dark
blue","dark goldenrod","purple"),
pch
= 20,
   cex =
1),
if you have groups 

par.settings = list(superpose.symbol = list(c("black","red","dark
green","dark blue","dark goldenrod","purple"),
 
pch = 20,
 
cex = 1)),

For other types such as barchart  type 
barchart  and at the top there is

plot.symbol <- trellis.par.get("plot.symbol")
plot.line <- trellis.par.get("plot.line")
superpose.symbol <- trellis.par.get("superpose.symbol")
superpose.line <- trellis.par.get("superpose.line")

Similar occurs for panel.xyplot

I find that ? xyplot  and ?panel. ... give the most uptodate methods things
change overtime.
There are some words on how information is passed to the key in ?xyplot
You either have to set trellis.par.set() or use the par.settings arguments

For older versions things may be slightly different.

If in a hurry I try the easiest but if that fails on the first go I just use
key = list(text = ... etc
 
Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rich Shepard
Sent: Thursday, 20 October 2016 10:05
To: r-help@r-project.org
Subject: Re: [R] Lattice xyplot(): adding a legend

On Wed, 19 Oct 2016, Rich Shepard wrote:

>  I did read that but mis-applied what I read. Tried auto.key but that did
> not work as desired. Now I know to learn how to apply 'key'.

   Almost there after another careful reading Section 9.2.3 ff in the book.
Here's the command to produce the plot:

rainbyday <- xyplot(rain$amount ~ raindate, data = rain, main = "Area
Precipitation",
 ylab = "Daily Total Amount (in)", xlab = "Date",
 scales = list(x=list(at=c(1,8,15,22,29,36,43,50,57,62), rot = 90),
 y = list(at=c(min(rain$amount), max(rain$amount,
 pch = 20,
 col = c("black","red","dark green","dark blue","dark
goldenrod","purple"),
 key = simpleKey(text = levels(rain$station)[1:6],
   x = 0.2, y = 0.6, corner = c(0, 0), points = TRUE))

   My question is how to pass pch = 20 to the key. simpleKey accepts only
the
logical TRUE as an argument and this produces a plot with filled circles for
the data but unfilled circles for the key. I find no example of specifying
pch for points in the key in either the book or ?xyplot, and I'm sure there
is a way of having the key symbols match both pch and color as the data
symbols.

   Is use of Rows() the solution?

Rich

__
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-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] suppress labels in lattice barchart

2016-10-16 Thread Duncan Mackay
Hi

Try

barchart(name ~ age, data = boy.age, scales = list(y = list(alternating =
FALSE, at = 1:4, labels = rep("",4

see ?lattice::xyplot for details 

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Naresh
Gurbuxani
Sent: Sunday, 16 October 2016 10:44
To: R-help@r-project.org
Subject: [R] suppress labels in lattice barchart

I would like to print a barchart without labels for categorical variables.
 What change should be made to below command?

Thanks,
Naresh

boy.age <- data.frame(name = c("alpha", "beta", "charlie", "gerald"), age =
c(7, 9, 6, 5))

boy.age$name <- with(boy.age, reorder(name, age))

# draws with names on labels
barchart(name ~ age, data = boy.age, scales = list(y = list(alternating =
FALSE)))

# draws with names on labels
barchart(name ~ age, data = boy.age, ylab = "")
__
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-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] can we visualize water flows with 3d in R?

2016-10-14 Thread Duncan Mackay
Hi Marna

 

These are a few suggestions for EDA of your data

 

Firstly check it – it is laborious work but it needs to be done – use a proper 
database if R is not suitable (memory,time)

 

dat <- read.csv("G:/1/example_subsetdata.csv")

dat <- subset(dat, !is.na(depth))

 

apply(dat,2,range,na.rm=T)

table(cut(dat$depth, breaks = seq(496.5, 498.5, 0.25), include.lowest = TRUE, 
labels = F)) # needs more groups to even out numbers 

# use hand drafted breaks

table(dat$Y)

 

dat$ldepth <- cut(dat$depth, breaks = seq(496.5, 498.5, 0.25), include.lowest = 
TRUE, labels = F)

xyplot(Y ~ X|factor(ldepth), subset(dat, Y > 400), pch = ".", as.table = TRUE)

xyplot(flow ~ X|factor(ldepth), subset(dat, Y > 400), pch = ".", as.table = 
TRUE, col =1)

xyplot(flow ~ Y|factor(ldepth), subset(dat, Y > 400), pch = ".", as.table = 
TRUE, col =1)

 

I have made pch = ‘.’ so that  points are not overtopping. increase by by units 
ie cex = 2 , cex =3 if you want to make them larger

 

Have a look a lattice::par.settings  and names(trellis.par.get()) these will 
make things easier if you you are using panel functions.

 

I did not go further but the next step in this would be lattice 3d plots 
contourplot wireframe etc.
You will get more information in working with the full dataset
 
I have not really gone into spatials  but you should look at the task view on 
spatial analysis.
and the spatial SIG
 
How you proceed will be partly determined by your future requirements of which 
I am not qualified.
 
Regards
 
Duncan

 

 

 

From: Marna Wagley [mailto:marna.wag...@gmail.com] 
Sent: Friday, 14 October 2016 03:13
To: Duncan Mackay
Subject: Re: [R] can we visualize water flows with 3d in R?

 

Hi Duncan, 

Thank you very much for the message. Indeed I do have a very big data set with 
a grid size of 10cm * 10 cm. Every 10 cm*10cm grid has the value of X,Y, depth 
and flow measurement. I have attached a subset of the data. 

Thanks 

 

 

On Wed, Oct 12, 2016 at 11:05 PM, Duncan Mackay  wrote:

Hi

With a small data set 3D is not really an option;  reduce the number of
dimensions-- 2D conditional

library(lattice)
xyplot(flow ~ depth|factor(long), dat1, groups = lat, type = c("p","r"), pch
= 16)

I had started with lat and long reversed doing EDA gave the above
? latitude effect

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marna Wagley
Sent: Wednesday, 12 October 2016 19:49
To: r-help mailing list
Subject: [R] can we visualize water flows with 3d in R?

Hi R Users,
Is it possible to visualize river flow in  3D (latitude, longitude with
respect to depth)?
The example of my data looks like. Any suggestions?

> dat1
long lat depth flow
1 1015.9 857  1.00 1.50
2 1015.9 857  1.25 1.23
3 1015.9 857  0.50 2.00
4 1015.9 858  0.10 1.95
5 1015.9 858  0.20 1.50
6 1025.0 858  0.30 1.20
7 1025.0 858  0.40 0.50
8 1025.0 858  0.35 0.70
9 1025.0 858  0.24 1.20

Thanks for your help.
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-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] can we visualize water flows with 3d in R?

2016-10-12 Thread Duncan Mackay
Hi

With a small data set 3D is not really an option;  reduce the number of
dimensions-- 2D conditional

library(lattice)
xyplot(flow ~ depth|factor(long), dat1, groups = lat, type = c("p","r"), pch
= 16)

I had started with lat and long reversed doing EDA gave the above
? latitude effect

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marna Wagley
Sent: Wednesday, 12 October 2016 19:49
To: r-help mailing list
Subject: [R] can we visualize water flows with 3d in R?

Hi R Users,
Is it possible to visualize river flow in  3D (latitude, longitude with
respect to depth)?
The example of my data looks like. Any suggestions?

> dat1
long lat depth flow
1 1015.9 857  1.00 1.50
2 1015.9 857  1.25 1.23
3 1015.9 857  0.50 2.00
4 1015.9 858  0.10 1.95
5 1015.9 858  0.20 1.50
6 1025.0 858  0.30 1.20
7 1025.0 858  0.40 0.50
8 1025.0 858  0.35 0.70
9 1025.0 858  0.24 1.20

Thanks for your help.
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-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] Output formatting in PDF

2016-10-11 Thread Duncan Mackay
Hi

There is also the basic option of using the grid package and viewports.
You can then place the plots where you want and annotate them

pdf(file= paste0("01", ".pdf"),
height  = 3.5,
width   = 7,
paper   = "special",
onefile = TRUE,
family  = "Helvetica",
pointsize = 12,
colormodel = "rgb")

vpl <- viewport(x = 0.25, y = 0.5, width = 0.45, height = 0.9)
pushViewport(vpl)
grid.rect(gp = gpar(lty = "dashed"))
popViewport()

vpr <- viewport(x = 0.75, y = 0.5, width = 0.45, height = 0.9)
pushViewport(vpr)
grid.rect(gp = gpar(lty = "dashed"))
grid.circle(x = 0.6, y = 0.4, r = 0.3)
popViewport()

dev.off()

In your case you may need to have a viewport of the whole page

see  http://www.amstat.org/publications/jse/v18n3/zhou.pdf for examples

also have a look at the grid.clip function

Regards

Duncan Mackay

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Preetam Pal
Sent: Tuesday, 11 October 2016 19:14
To: r-help@r-project.org
Subject: [R] Output formatting in PDF

Hi,

Can you please help me with the following output formatting:
I am planning to include 2 plots and some general description in a one-page
PDF document, such that

   - I'll leave some appropriate margin on the PDF- say, 1.5 inches
   top,right, bottom and left (will decide based on overall appearance)
   - the 2 plots are placed side-by-side (looks best for comparison)
   - the margins for each plot can be 4 lines on the top and the bottom &
2 lines on the left and the right
   - each of these 2 plots would have time (0 to 260) along x-axis and two
   time-series (daily USD-GBP and USD-EUR FX rates) on the y-axis, i.e. 2
   time-series would be plotted on each of the 2 graphs. I would need a
   different color for each plot to demarcate them
   - I need to add some text (eg: "Independent analysis of Exchange Rate
   dynamics") with reduced font size (not high priority though-just good to
   have a different size)
   - The general discussion (may be a paragraph) would come right below the
   2 plots - I can specify this text as an argument in a function, may be. I
   am not sure how to arrange the entire PDF as per the format I mentioned
   above

I shall really appreciate any help with this - the time series analysis is
not difficult, I can manage that - however, I don't know how to manage the
formatting part though, so that the 1-pager output looks decently
presentable. Thanks.

Regards,
Preetam

[[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-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] Adding loess lines subsetting to each panel in lattice plot

2016-08-14 Thread Duncan Mackay
Hi

A slightly different approach

xyplot(y~x|fac,
   groups = ifelse(age < 40,1,2),
   par.settings = list(strip.background = list(col = "transparent"),
   superpose.symbol = list(col = 
c("red","blue","green")),
   superpose.line = list(col = c("red","blue","green"))
   ),
   auto.key = TRUE,
   panel = function(x, y, ..., groups) {
   panel.superpose(x, y, ..., groups, panel = panel.points)
   panel.superpose(x, y, ..., groups, panel = panel.loess)
   panel.xyplot(x,y, type = "smooth", col = "green")
   }
)

This gives the colours to the panel function as well as the key

If you want a more elaborate key

xyplot(y~x|fac,
   groups = ifelse(age < 40,1,2),
   par.settings = list(strip.background = list(col = "transparent"),
   superpose.symbol = list(col = 
c("red","blue","green")),
   superpose.line = list(col = c("red","blue","green"))
   ),
   key = list(text = list(labels = c("young","old","all")),
   points = list(pch = 1, col = 
c("red","blue","transparent")),
   lines = list(col = c("red","blue","green"))),
   panel = function(x, y, ..., groups) {
       panel.superpose(x, y, ..., groups, panel = panel.points)
   panel.superpose(x, y, ..., groups, panel = panel.loess)
   panel.xyplot(x,y, type = "smooth", col = "green")
   }
)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Juan Perez via 
R-help
Sent: Saturday, 13 August 2016 23:32
To: Bert Gunter
Cc: r-help@r-project.org
Subject: Re: [R] Adding loess lines subsetting to each panel in lattice plot

Thanks Bert
I am not sure what you meant by reading though.
I managed to sort this out, although ideally would exist a better solution. I 
have created a column in my dataset, and given two codes depending whether 
older or younger than 40. Afterwards I have applied
xyplot(MOE~Age|Species, groups=Old,
   panel= function(x,y,...){  ## custom panel function to add an overall 
loess line
 panel.superpose(x,y,...)
 panel.loess(x,y,col="black",lwd=2,...)
   },
   panel.groups = function(x,y,...){
 panel.xyplot(x,y,...)
 panel.loess(x,y,...)
   }) 

This gives a loess line for data younger than 40, another for the ones older, 
and a third one for all the data. I hope this helps to someone else. 
Unfortunately, the dataset needs to be modified everytime we want to make a new 
or different subset.
Best regards
 

El Viernes 12 de agosto de 2016 21:10, Bert Gunter  
escribió:
 

 Try reading ?panel.loess. There is no "subset" argument, so it is of
course ignored.

-- Bert



Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Aug 12, 2016 at 9:10 AM, Juan Perez via R-help
 wrote:
> Hello, I've created an xyplot and I want to add a loess line for x (Age)  
> <=40 and another for values >40. In a way it is similar to this 
> https://stat.ethz.ch/pipermail/r-help/2009-May/390502.html but still not 
> succcessful.
> This is my try:
>
> xyplot(MOE~Age|Species, groups=Site,
>panel = function(x, y, groups=groups,...) {
>panel.xyplot(x, y, groups=groups,...)
>panel.loess(x,y,subset = x <= 40, col="black")
> panel.loess(x,y,subset = x >40, col="red")
>  })
> When I run the code it "works" but it plots the loess line for all the data, 
> without subsetting.Any suggestion?
> Thank 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.


  
[[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-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] how to plot annual values directly

2016-08-04 Thread Duncan Mackay
Hi

By coincidence I will very soon have to  do something similar. So I thought
this would be a practice run

Data is 10 years of daily rainfall data
str(arm)
'data.frame':   3640 obs. of  7 variables:
 $ date : Date, format: "1990-01-01" "1990-01-02" "1990-01-03" "1990-01-04"
...
 $ year : int  1990 1990 1990 1990 1990 1990 1990 1990 1990 1990 ...
 $ month: int  1 1 1 1 1 1 1 1 1 1 ...
 $ day  : int  1 2 3 4 5 6 7 8 9 10 ...
 $ rain : num  0 19 0 0 0 0 0 8.2 5.6 1 ...
 $ doy  : num  1 2 3 4 5 6 7 8 9 10 ...
 $ ym   : Date, format: "1990-01-01" "1990-01-01" "1990-01-01" "1990-01-01"
...

head(arm)
date year month day rain doy ym
48578 1990-01-01 1990 1   10   1 1990-01-01
48579 1990-01-02 1990 1   2   19   2 1990-01-01
48580 1990-01-03 1990 1   30   3 1990-01-01
48581 1990-01-04 1990 1   40   4 1990-01-01
48582 1990-01-05 1990 1   50   5 1990-01-01
48583 1990-01-06 1990 1   60   6 1990-01-01

The ym is calculated using ?as.yearmon from the zoo package. 
The zoo package may be useful because of its aggregating functions

Need mean daily rain - use whatever aggregation factor/function that you
need

arm.A <- aggregate(rain ~ year, arm, function(x) mean(x[x>0]) )

library(lattice)

xyplot(rain ~ date, arm,
   groups = factor(arm$year),
   ylim  = c(0,60),
   avg   = arm.A$rain, # 
   panel = panel.superpose,
   panel.groups = function(x, y,  type, col,group.number,avg, ...) {
  
 # plot daily values
  panel.xyplot(x, y, col = "grey80", type = "h") # delete if
necessary
 # plot average
      panel.xyplot(x, avg[group.number],  type = "l", col =
"black")

   }
)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
Sent: Wednesday, 3 August 2016 04:10
To: R mailing list
Subject: [R] how to plot annual values directly

Hi R users,

I have a dataframe, with daily precipitation data, is it possible to plot
annual mean or annual sum values directly? Thanks for your help.

df
year   month   day   precip   time
2010 1  10.5 2010-01-01
2010 1  20.8 2010-01-02
2010 1  31.0 2010-01-03
2010 1  40.9 2010-01-04
...

fig1 = ggplot()+ geom_path(data=df, aes(x=time, y= precip)
show(fig1)

[[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-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] font size in graphs...can R read Windows settings?

2016-07-29 Thread Duncan Mackay
Hi

 

There are some System commands that grab a computers settings to suit your 
purpose but I do not know what they are. 

May be tikz or Java or python based packages will improve things but I do not 
know them at all

 

Regards

 

Duncan

 

From: Dalthorp, Daniel [mailto:ddalth...@usgs.gov] 
Sent: Friday, 29 July 2016 11:49
To: Duncan Mackay
Cc: R
Subject: Re: [R] font size in graphs...can R read Windows settings?

 

The trouble is getting the figs to look right for different users who happen to 
have different display settings. Nearly all my users will be on MS Windows, 
and, for the parameter set you gave, the figs will look different, depending on 
which "display size" parameter value is active and the screen resolution (for 
Windows 7 --- Control Panel | Appearance and Personalization | Display | Make 
text and other items larger or smaller). 

 

For example, the following gives different look (for text(), mtext(), axis 
labels, etc.) "smaller" than for "larger" or for fine resolution vs. coarse 
resolution. Getting it wrong makes the figs look sloppy and hard to read. If I 
knew users' display parameters ahead of time, I could adjust the drawing 
algorithms using par parameters, but I don't know the display parameters. 'din' 
values at time of package attachment (and after closing of open devices) gives 
a reasonable proxy in a lot of cases but not always.

 

par(mfrow = c(1,1),

 las = 1,

 mai = c(0.85, 0.85, 0.32, 0.12),

 font.main = 1,

 cex.main = 1.0,

 cex.lab  = 1.0,

 cex.axis = 0.9)

plot(0,0)

plot(0,0, type='n')

text(0,0, 'junk')

mtext(side = 3, line = .5, "more junk")

 

 

On Thu, Jul 28, 2016 at 6:15 PM, Duncan Mackay  wrote:

Hi Dan

 

This is one of  the features/problems of proportional graphing – getting it 
exactly right.

 

Anyway good graphs usually take time

 

I wonder if aspect in both base and lattice may be of use.

Also I have a default par settings for base graphics where I sometimes change 
the mai command for multiple graphs and rarely the font size.

 

par(mfrow = c(1,1),

las = 1,

mai = c(0.85, 0.85, 0.32, 0.12),

font.main = 1,

cex.main = 1.0,

cex.lab  = 1.0,

cex.axis = 0.9)

 

Duncan

 

From: Dalthorp, Daniel [mailto:ddalth...@usgs.gov] 
Sent: Friday, 29 July 2016 09:22
To: Duncan Mackay
Cc: R
Subject: Re: [R] font size in graphs...can R read Windows settings?

 

Thanks, Duncan. This is close to what I was looking for. But I'm not using 
lattice. And the fontsize$text and fontsize$points are independent of display 
settings in Windows (screen resolution and 'size of objects').

 

I need to make my graphs [esp. placement and size of text(), mtext()] look good 
regardless of display settings.

 

Here's what I'm working with at the moment...

 

When package is loaded, I store the default graph size ('din') which is 
correlated with OS display parameters. Then, I simply multiple my current 'cex' 
values by the stored 'din' divided by 7 (which is the 'din' associated with the 
display parameters that I created the figs in initially). It seems to work just 
fine for my text() and mtext() text sizes. 

 

But some of my algorithms for placing text and subfigs in margins still need 
fixing...combinations of 'plt' and 'usr' seem to be working, but it's tedious.

 

-Dan

 

On Wed, Jul 27, 2016 at 8:43 PM, Duncan Mackay  wrote:

Hi  Dan

For devices png, pdf, postscript and ? others the pointsize argument
controls the font size which is modified by cex

For lattice there are the settings in trellis.par.get()

trellis.par.get()$fontsize
$text
[1] 12

$points
[1] 8

which you can set and there is no real need to change font size except if
you need to change main.
trellis.par.get()$grid.pars  are the settings for grid elements if used  eg
text

these could be set globally by trellis.par.set() or individually with
argument par.settings eg
xyplot(y ~ x, data = datm,
 par.settings = list(strip.background = list(col =
"transparent"),
 fontsize = list(text = 16,

points = 12),  # large size;  need to refine
superpose.polygon= list(col
= c("red","blue"),

border = c("red","blue"))),
type = "b")

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp,
Daniel
Sent: Thursday, 28 July 2016 07:02
To: r-help@R-project.org (r-help@r-project.org)
Subject: [R] font size in graphs...can R read Windows settings?

Hi All,
I am putting together a package that (among other th

Re: [R] font size in graphs...can R read Windows settings?

2016-07-28 Thread Duncan Mackay
Hi Dan

 

This is one of  the features/problems of proportional graphing – getting it 
exactly right.

 

Anyway good graphs usually take time

 

I wonder if aspect in both base and lattice may be of use.

Also I have a default par settings for base graphics where I sometimes change 
the mai command for multiple graphs and rarely the font size.

 

par(mfrow = c(1,1),

las = 1,

mai = c(0.85, 0.85, 0.32, 0.12),

font.main = 1,

cex.main = 1.0,

cex.lab  = 1.0,

cex.axis = 0.9)

 

Duncan

 

From: Dalthorp, Daniel [mailto:ddalth...@usgs.gov] 
Sent: Friday, 29 July 2016 09:22
To: Duncan Mackay
Cc: R
Subject: Re: [R] font size in graphs...can R read Windows settings?

 

Thanks, Duncan. This is close to what I was looking for. But I'm not using 
lattice. And the fontsize$text and fontsize$points are independent of display 
settings in Windows (screen resolution and 'size of objects').

 

I need to make my graphs [esp. placement and size of text(), mtext()] look good 
regardless of display settings.

 

Here's what I'm working with at the moment...

 

When package is loaded, I store the default graph size ('din') which is 
correlated with OS display parameters. Then, I simply multiple my current 'cex' 
values by the stored 'din' divided by 7 (which is the 'din' associated with the 
display parameters that I created the figs in initially). It seems to work just 
fine for my text() and mtext() text sizes. 

 

But some of my algorithms for placing text and subfigs in margins still need 
fixing...combinations of 'plt' and 'usr' seem to be working, but it's tedious.

 

-Dan

 

On Wed, Jul 27, 2016 at 8:43 PM, Duncan Mackay  wrote:

Hi  Dan

For devices png, pdf, postscript and ? others the pointsize argument
controls the font size which is modified by cex

For lattice there are the settings in trellis.par.get()

trellis.par.get()$fontsize
$text
[1] 12

$points
[1] 8

which you can set and there is no real need to change font size except if
you need to change main.
trellis.par.get()$grid.pars  are the settings for grid elements if used  eg
text

these could be set globally by trellis.par.set() or individually with
argument par.settings eg
xyplot(y ~ x, data = datm,
 par.settings = list(strip.background = list(col =
"transparent"),
 fontsize = list(text = 16,

points = 12),  # large size;  need to refine
superpose.polygon= list(col
= c("red","blue"),

border = c("red","blue"))),
type = "b")

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp,
Daniel
Sent: Thursday, 28 July 2016 07:02
To: r-help@R-project.org (r-help@r-project.org)
Subject: [R] font size in graphs...can R read Windows settings?

Hi All,
I am putting together a package that (among other things) draws some nice
graphs for users. I place some explanatory text on figs using "text" and
"mtext". But the size of the text depends on the Windows display settings:
Smaller (100%), medium (125%) or larger (150%) (In Windows 7... Control
panel | Appearance and personalization | Display | Make text and other
items smaller or larger). If I create figs that look good with one setting,
the text is too big (or too small) if another setting is used in Windows.
If I know the Windows setting, I can use cex in R to make the right sized
labels, but if I don't know a user's Windows display size setting...is
there a way for R to read the setting? Or is there another way to control
label size so that text labels on graphs look good regardless of WIndows
display size setting?

Many thanks for Ideas,

-Dan
--
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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.







-- 

Dan Dalthorp, PhD

USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way 
Corvallis, OR 97331 
ph: 541-750-0953
ddalth...@usgs.gov


[[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] font size in graphs...can R read Windows settings?

2016-07-27 Thread Duncan Mackay
Hi  Dan

For devices png, pdf, postscript and ? others the pointsize argument
controls the font size which is modified by cex

For lattice there are the settings in trellis.par.get()

trellis.par.get()$fontsize
$text
[1] 12

$points
[1] 8

which you can set and there is no real need to change font size except if
you need to change main.
trellis.par.get()$grid.pars  are the settings for grid elements if used  eg
text

these could be set globally by trellis.par.set() or individually with
argument par.settings eg
xyplot(y ~ x, data = datm,
 par.settings = list(strip.background = list(col =
"transparent"),
 fontsize = list(text = 16,
 
points = 12),  # large size;  need to refine   
superpose.polygon= list(col
= c("red","blue"),
 
border = c("red","blue"))),      
    type = "b")

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp,
Daniel
Sent: Thursday, 28 July 2016 07:02
To: r-help@R-project.org (r-help@r-project.org)
Subject: [R] font size in graphs...can R read Windows settings?

Hi All,
I am putting together a package that (among other things) draws some nice
graphs for users. I place some explanatory text on figs using "text" and
"mtext". But the size of the text depends on the Windows display settings:
Smaller (100%), medium (125%) or larger (150%) (In Windows 7... Control
panel | Appearance and personalization | Display | Make text and other
items smaller or larger). If I create figs that look good with one setting,
the text is too big (or too small) if another setting is used in Windows.
If I know the Windows setting, I can use cex in R to make the right sized
labels, but if I don't know a user's Windows display size setting...is
there a way for R to read the setting? Or is there another way to control
label size so that text labels on graphs look good regardless of WIndows
display size setting?

Many thanks for Ideas,

-Dan
-- 
Dan Dalthorp, PhD
USGS Forest and Rangeland Ecosystem Science Center
Forest Sciences Lab, Rm 189
3200 SW Jefferson Way
Corvallis, OR 97331
ph: 541-750-0953
ddalth...@usgs.gov

[[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-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] Lattice barchart legend with panel.barchart

2016-07-27 Thread Duncan Mackay
Hi

Following Pauls reply you may like to increase the panel space available by
using useOuterStrips which makes the smaller proportions easier to see and
compare
If you also wanted to change colours auto.key is the better option. Colours
are a bit garish 
See
 ?xyplot
and 
panel.barchart

library(latticeExtra) 

useOuterStrips(
barchart(Class~Freq|Sex + Age, Titan,
  groups=Survived,
  panel = titanpanel,
  par.settings = list(strip.background = list(col = "transparent"),
  superpose.polygon= list(col = c("red","blue"),
  border =
c("red","blue"))),
  stack=TRUE, layout=c(4,1),
  auto.key=list(title="Survived", text=levels(Titan$Survived),
rectangles=TRUE, points=FALSE, columns=2)
)
)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Seth Bigelow
Sent: Thursday, 28 July 2016 07:02
To: r-help@r-project.org
Subject: [R] Lattice barchart legend with panel.barchart

I have constructed a barchart that requires a panel call, but the panel
reduces the facsimiles of bars in the legend to small colored circles. You
can see this behavior in the following example:

Titan <- as.data.frame(Titanic)

titanpanel <- function(x,y,...){
panel.barchart(x,y,...)
}

barchart(Class~Freq|Sex + Age, Titan,
groups=Survived,
panel = titanpanel,
stack=TRUE, layout=c(4,1),
auto.key=list(title="Survived", columns=2))

...if you comment out the panel and run the barchart statement you will see
nice blocks displayed in the legend. Is there any easy way to retain these
blocks with panel.barchart?


-- 
Seth W. Bigelow, Ph.D.
Assistant Scientist of Forest Ecology
Joseph W. Jones Ecological Research Center
Newton, GA

[[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-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] pairs: adjusting margins and labeling axes

2016-07-19 Thread Duncan Mackay
Hi
Will doing in lattice suite

>From  https://stat.ethz.ch/pipermail/r-help/2007-October/142116.html and
https://stat.ethz.ch/pipermail/r-help/2007-October/142124.html]
This is a direct cut and paste from the last url to give you an idea of
Deepayan Sarkar's script

library(lattice)

panel.corval2 <- function(x, y, digits=2, prefix="", cex.cor, ...)
{
require(grid)
r <- abs(cor(x, y, use = "complete.obs"))
txt <- format(c(r, 0.123456789), digits=digits)[1]
txt <- paste(prefix, txt, sep="")
if (missing(cex.cor)) cex.cor <- 10 / nchar(txt)
grid.text(txt, 0.5, 0.5, gp = gpar(cex = cex.cor))
}

splom(iris[1:4], groups = iris$Species, pch = 16,
  lower.panel = function(...) {
  panel.xyplot(...)
  panel.loess(..., col = 1, lwd = 3)
  },
  upper.panel = panel.corval2)


Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of michael
young
Sent: Wednesday, 20 July 2016 03:30
To: r-help@r-project.org
Subject: [R] pairs: adjusting margins and labeling axes

The default shape for this correlation scatterplot is rectangle.  I changed
it to square, but then the x-axis spacing between squares are off.  Is
there an easy way to change x-axis spacing between squares to that of the
y-axis spacing size?

I decided to hide the name values of the diagonal squares.  I want them
along the x and y axis instead, outside of the fixed number scale I have.
I haven't seen any online example of 'pairs' with this and all my searches
have yielded nothing.  Any ideas?  Thanks

par(pty="s")
panel.cor <- function(x, y, digits = 2, prefix="", cex.cor, ...)
{
usr <- par("usr"); on.exit(par(usr))
par(usr = c(0, 1, 0, 1),xlog=FALSE,ylog=FALSE)
# correlation coefficient
r <- cor(x, y)
txt <- format(c(r, 0.123456789), digits = digits)[1]
txt <- paste("r= ", txt, sep = "")
if(missing(cex.cor)) cex.cor <- 0.8/strwidth(txt)
text(0.5, 0.6, txt, cex=cex.cor * r)

# p-value calculation
p <- cor.test(x, y)$p.value
txt2 <- format(c(p, 0.123456789), digits = digits)[1]
txt2 <- paste("p= ", txt2, sep = "")
if(p<0.01) txt2 <- paste("p= ", "<0.01", sep = "")
text(0.5, 0.4, txt2)
}

pairs(iris, upper.panel = panel.cor,xlim=c(0.1,10),
ylim=c(0.1,10),log="xy",text.panel = NULL,pch=".")

[[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-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] > Understanding strip.default & strip.custom

2016-06-29 Thread Duncan Mackay
Patrick

Have a look at 
https://stat.ethz.ch/pipermail/r-help/2006-August/110621.html
and
https://stat.ethz.ch/pipermail/r-help/2008-June/165279.html

I remember working it out with an example but I cannot remember any of the
details

Regards

Duncan


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Patrick
Connolly
Sent: Wednesday, 29 June 2016 18:30
To: Bert Gunter
Cc: r-h...@stat.math.ethz.ch
Subject: Re: [R] > Understanding strip.default & strip.custom

On Mon, 27-Jun-2016 at 10:17PM -0700, Bert Gunter wrote:

[...]

|> 
|> You seem to be making this way more difficult than you should.

Though I didn't get any closer to an understanding of which.panel, the
question I asked was simply answered by

panel.custom(factor.levels = )

Thanks to Duncan Mackay also.

-- 
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.   
   ___Patrick Connolly   
 {~._.~}   Great minds discuss ideas
 _( Y )_ Average minds discuss events 
(:_~*~_:)  Small minds discuss people  
 (_)-(_)  . Eleanor Roosevelt
  
~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.

__
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-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] > Understanding strip.default & strip.custom

2016-06-27 Thread Duncan Mackay
Hi Patrick

does this help?

  dat <-
  data.frame(x = rnorm(12*5,0,1),
 y = rnorm(12*5,0,1),
 gp = factor(1:12))
  dat$NS = ifelse(sapply(dat$gp, pmatch,flN, nomatch = 0) > 0, 
"Needles","Stems")
   dat = dat[order(dat[,"NS"]),]
  dat$GP = factor(1:6)

xyplot(y ~ x|gp, data = dat,
  par.settings = list(strip.background = list(col = "transparent")
 ),
  strip= strip.custom(factor.levels = expression(Needles~ "::"~alpha 
-pinene,
 Stems~ "::"~alpha -pinene,
 Needles~ "::"~beta -pinene,
 Stems~ "::"~beta -pinene,
 Needles~ ":: B?Phellandrene",
 Stems~ ":: B?Phellandrene",
 Needles~ ":: Camphene",
 Stems~ ":: Camphene",
 Needles~ ":: Myrcene",
 Stems~ ":: Myrcene",
 Needles~ ":: Limonene",
 Stems~ "::Limonene"),
   par.strip.text = list(cex = 0.65) ))
   
library(latticeExtra)
  useOuterStrips(strip= strip.custom(factor.levels = expression("::"~alpha 
-pinene,
   "::"~beta -pinene,
   ":: B?Phellandrene",
   ":: Camphene",
   ":: Myrcene",
   ":: Limonene")),
 xyplot(y ~ x|GP*NS, data = dat,
  drop.unused = T,
  par.settings = list(strip.background = list(col = "transparent")
 ),
 par.strip.text = list(cex = 0.65) )
 ) 
   
If you want to change the order of the factors assign the factor levels to a 
vector and order accordingly

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of p_connolly
Sent: Tuesday, 28 June 2016 12:59
To: r-h...@stat.math.ethz.ch
Subject: [R] > Understanding strip.default & strip.custom

I'm having difficulty following the help for those functions.

My plot has a single conditioning factor with 12 levels.  My
factor.levels in a call to strip.default looks like this:

  factor.levels = expression(Needles~ "::"~alpha -pinene,
 Stems~ "::"~alpha -pinene,
 Needles~ "::"~beta -pinene,
 Stems~ "::"~beta -pinene,
 Needles~ ":: B−Phellandrene",
 Stems~ ":: B−Phellandrene",
 Needles~ ":: Camphene",
 Stems~ ":: Camphene",
 Needles~ ":: Myrcene",
 Stems~ ":: Myrcene",
 Needles~ ":: Limonene",
 Stems~ "::Limonene")

Since there is only one factor, which.given must be 1.
Likewise, var.name must be of length 1.

What I can't understand is the argument which.panel.  The help says:

which.panel: vector of integers as long as the number of conditioning
   variables. The contents are indices specifying the current
   levels of each of the conditioning variables (thus, this
   would be unique for each distinct packet).  This is identical
   to the return value of ‘which.packet’, which is a more
   accurate name.

So, that must be of length 1 also, according to the first sentence,
but if I set it to 1, I get the first strip label repeated 12 times.
Set it to 2, I get the second one 12 times.  Set it to 1:2, it
attempts to squash 2 strips in the space of 1, labelling the first
one.   I don't understand the second sentence at all.

What do I do to get all 12 in their correct order?

I couldn't find an example remotely like what I'm trying to do.  Are
there any pointers?

TIA
Patrick

__
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-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] graphic device Windows tickmarks

2016-05-30 Thread Duncan Mackay
Hi 

Without looking at the help guide I think there are restrictions on
resolution
and just in case of unit problems I worked in the default units

> png("test.png",units="in",width=12,height=12,res=300)
Error in png("test.png", units = "in", width = 12, height = 12, res = 300) :

  unable to start png() device
In addition: Warning messages:
1: In png("test.png", units = "in", width = 12, height = 12, res = 300) :
  unable to allocate bitmap
2: In png("test.png", units = "in", width = 12, height = 12, res = 300) :
  opening device failed
> 12*72
[1] 864
> png("test.png",width=864,height=834,res=150)
> plot(seq(0,1000),rep(10,1001),xaxt="n")
> axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
> axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)
> dev.off()

Check ?postscript and the options as eps and pdf require different
arguments.
> postscript("test.eps", paper = "special", width = 12,height = 12)
> plot(seq(0,1000),rep(10,1001),xaxt="n")
> axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
> axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)
> dev.off()

> pdf("test.pdf", paper = "special", width = 12,height = 12)
> plot(seq(0,1000),rep(10,1001),xaxt="n")
> axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
> axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)
> dev.off()

All the above work for me on Win 7 32

platform   i386-w64-mingw32   
arch   i386   
os mingw32
system i386, mingw32

Similar to the above has worked on Win 64

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Christian
Brandstätter
Sent: Tuesday, 31 May 2016 05:24
To: r-help@r-project.org
Subject: [R] graphic device Windows tickmarks

Dear List,

I discovered an issue; when plotting (base) in R, the tickmark-labels 
are slightly off (Windows machine).

Thus, when saving the plot in R with x11() and dev(...) the 
plot-tickmarks shift, see the example below.

Session Info:

R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

With savePlot it works, but the graph quality is not as nice. Am I 
missing something here?


Example:
thickticks <- 
c(0,40,90,140,200,260,320,380,440,500,560,620,680,740,800,860,920,980)

x11(width=12,height=12)
plot(seq(0,1000),rep(10,1001),xaxt="n")
axis(1,seq(0,1000,by=10),at=seq(0,1000,by=10),tick=TRUE)
axis(1, at = thickticks, labels=FALSE, las = 1,lwd.ticks=2)

# plots
dev.print(device=png,"test.png",units="in",width=12,height=12,res=500) # 
won't display prop.
dev.print(device=postscript,"test.eps",width=12,height=12)  # won't 
display prop.
dev.print(device=pdf,"test.pdf",width=12,height=12)  # won't display prop.
savePlot("test_2.png",type="png") # displays prop.

__
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-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] Scale y-labels based on a value with 'lattice'

2016-05-26 Thread Duncan Mackay
Hi

If you want to change the cex of the labels see

library(lattice)
 ?yscale.components.default

Possibly an easier way is to size the symbols

I will use Jims data.frame to plot with lattice
dotplot(Group.2 ~ x, data = kedf, 
 scales = list(y = list(labels = kedf[,"Group2"], cex = = 
kedf[,"Freq"]))) 

 If you want to magnify the size of the symbol according to Freq

dotplot(Group.2 ~ x, data = kedf, 
cex = kedf[,"Freq"])

or with modifications
dotplot(Group.2 ~ x, data = kedf, 
col = "black",
   pch = 15,
cex = kedf[,"Freq"])

If you wanted to go further

dotplot(Group.2 ~ x, data = kedf,
par.settings = list(dot.symbol = list(col = "black",
  pch = 15)  ),
cex = kedf[,"Freq"])

without further work cex will not work as it is in par settings

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of K. Elo
Sent: Friday, 27 May 2016 00:52
To: r-help@r-project.org
Subject: [R] Scale y-labels based on a value with 'lattice'

Dear R-helpers!

I have a data frame storing data for word co-occurrences, average 
distances and co-occurence frequency:

   Group.1Group.2 x Freq
1 deutschland  achtziger  2.001
2 deutschlandalt  1.254
3 deutschland anfang -2.001
4 deutschlandansehen  1.002
5 deutschland arbeit  0.502
6 deutschland arbeitslos -2.001

Now I want to plot a lattice 'dotplot' with the formula 'Group.2~x'. 
This works fine.

However, I would like to scale the y-label (based on 'Group.2' according 
the 'Freq' value using a log-scaled value (log(Freq+.5)). In other 
words: the higher the 'Freq' value of a term, the bigger its label 
should be printed in my dotplot.

The problem is that I cannot figure out how to tell lattice to scale 
each y-label with according 'Freq' value. I am quite sure I should build 
a function for scales=list(y=...), but I don't know how to it.

Many thanks in advance for your help!

Best,
Kimmo Elo

--
Åbo Akademi University / German studies
Turku, Finland

__
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-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] plot numeric vs character

2016-03-18 Thread Duncan Mackay
I haven't been following the thread but!
If you want to use lattice xyplot

# create x values in their right position -- 
# assuming equal spacing
mydf$x = rep(1:3, each = 3)

library(lattice)
xyplot(num ~ x, mydf,
 scales = list(x = list(at = 1:3, label = letters[1:3])),
 xlab = "")

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Ivan
Calandra
Sent: Thursday, 17 March 2016 23:26
To: R list
Cc: Anne CANER
Subject: Re: [R] plot numeric vs character

So it looks like there is no better "base" solution than Petr's code...
Thank you for your input anyway!

Ivan

--
Ivan Calandra, PhD
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calan...@univ-reims.fr
--
https://www.researchgate.net/profile/Ivan_Calandra
https://publons.com/author/705639/

Le 17/03/2016 13:04, John Kane a écrit :
> Another approach using ggplot2 and shamelessly swiped from
>
http://www.sthda.com/english/wiki/ggplot2-dot-plot-quick-start-guide-r-softw
are-and-data-visualization.
>
> library(ggplot2)
> ggplot(mydf, aes(x=let, y=num)) +
>geom_dotplot(binaxis='y', stackdir='center', dotsize = 0.5)
>
>
>
>
> John Kane
> Kingston ON Canada
>
>
>> -Original Message-
>> From: ivan.calan...@univ-reims.fr
>> Sent: Thu, 17 Mar 2016 11:29:52 +0100
>> To: r-help@r-project.org
>> Subject: [R] plot numeric vs character
>>
>> Dear useRs,
>>
>> I would like to plot data points in a simple scatterplot. I don't have a
>> lot of data per category, so a boxplot does not make sense.
>>
>> Here are some sample data:
>> mydf <- data.frame(let=rep(letters[1:3],each=3), num=rnorm(9),
>> stringsAsFactors=FALSE)
>>
>> I would like to do that, which throws an error, most likely because x is
>> character:
>> plot(mydf$let, mydf$num)
>>
>> If I convert to factor(), it plots a boxplot with no possibility (AFAIK)
>> to plot points:
>> mydf$let <- factor(mydf$let)
>> plot(mydf$let, mydf$num, type='p')
>>
>> I know I can use the function points() in a somewhat convoluted manner:
>> plot(mydf$num, xlim=c(1,3), type='n', xaxt='n')
>> axis(side=1, at=1:3, labels=levels(mydf$let))
>> points(as.numeric(mydf$let), mydf$num)
>>
>> Isn't there a simple(r) way? Maybe I just missed something obvious...
>>
>> Thank you in advance for your help,
>> Ivan
>>
>> --
>> Ivan Calandra, PhD
>> University of Reims Champagne-Ardenne
>> GEGENAA - EA 3795
>> CREA - 2 esplanade Roland Garros
>> 51100 Reims, France
>> +33(0)3 26 77 36 89
>> ivan.calan...@univ-reims.fr
>> --
>> https://www.researchgate.net/profile/Ivan_Calandra
>> https://publons.com/author/705639/
>>
>> __
>> 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.
> 
> Can't remember your password? Do you need a strong and secure password?
> Use Password manager! It stores your passwords & protects your account.
> Check it out at http://mysecurelogon.com/manager
>
>
>

__
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-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] specify size of box around legend

2016-03-12 Thread Duncan Mackay
Hi

If you cannot get anything right in base graphics 
You could plot the graph and then use 
library(grid)
viewport()
etc
for each of the legends

or even lattice and grid

xyplot(...,
  legend =  list( ),
)

see https://stat.ethz.ch/pipermail/r-help/2005-April/069459.html

for one way with grid package,  other ways may be using lattice and
lattice::draw.key

I' m a bit rusty on the actual workings

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rainer M
Krug
Sent: Saturday, 12 March 2016 01:02
To: r-help@r-project.org
Subject: [R] specify size of box around legend

Hi

assume the following code:

--8<---cut here---start->8---
plot(1,1)
legend(x="topleft", legend = LETTERS[1:10], title = "L 1")
legend(x="bottomleft", legend = paste(LETTERS[1:10],
letters[1:12],LETTERS[1:10]), title = "L 2")
legend(x="topright", legend = LETTERS[1:15], title = "L 3")
--8<---cut here---end--->8---

The box around L 1 is less wide than the box around L 2 due to automatic
sizing of the box.

Is there a way of specifying the width of the box, so that L 1 and L 2
have the same width?

In the same sense: can I also specify the height of the legend, so that
L 1 and L 3 have the same height?

Thanks,

Rainer
-- 
Rainer M. Krug
email: Rainerkrugsde
PGP: 0x0F52F982

__
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] FW: dotplot

2016-02-26 Thread Duncan Mackay
Forgot to send to list

-Original Message-
From: Duncan Mackay [mailto:dulca...@bigpond.com] 
Sent: Sunday, 17 May 2015 10:49
To: R
Subject: RE: [R] dotplot

if this is using lattice panel.dotplot gives the clues
The vertical lines are inserted by panel abline.

You can make your own panel.dotplot function by removing panel.abline which
uses col.line for the vertical line colour
 
A quick fix is by making col.line = "transparent". If you want to add lines
this may cause trouble for you

dotplot(val ~ lot, tmp,
col.line = "transparent",
ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
pch=tmp$sybm, col=tmp$color)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Daniel
Nordlund
Sent: Sunday, 17 May 2015 06:45
To: r-help@r-project.org
Cc: sa...@listserv.uga.edu
Subject: Re: [R] dotplot

On 5/16/2015 1:19 PM, Daniel Nordlund wrote:
> On 5/16/2015 12:32 PM, li li wrote:
>> Hi all,
>>I wrote the following code and have two questions:
>>(1) As you can see, I would like different colors for different
>> types. It does not come out that way in the graph from this code.
>> Anyone know how to fix this?
>> (2) How do I made the lots number on x axis eligible to read?
>> (3) How do I remove the verticle line in the graph.
>>  Thanks for your help.
>>Hanna
>>
>>
>> lot <- as.character(c("D130" ,"D135" ,"D1300010", "D1300015",
>> "D1300020",
>>   "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045",
>>   "D130" ,"D135" ,"D1300010", "D1300015",  "D1300020",
>>   "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045",
>>   "D130" ,"D135" ,"D1300010", "D1300015",  "D1300020",
>>   "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045"))
>>
>> val <- rnorm(30)
>> type <- rep(1:3,each=10)
>> tmp <- as.data.frame(cbind(val, type, lot))
>> tmp$sybm <- rep(c(1, 12, 16), each=10)
>> tmp$color <- rep(c("blue", "red", "green"), each=10)
>> tmp$val <- as.numeric(tmp$val)
>> dotplot(val ~ lot, tmp,
>>  ylab = "values", xlab="lot", aspect=1,
>>  pch=tmp$sybm, color=tmp$color)
>>
>
> Li Li,
>
> 1. if the dotplot function you are referring to is from the lattice
> package, then the correct name for the "color" parameter is col.  You
> could just use col=type to get different colors but you won't have
> control over the colors chosen.  I created a vector, color, specifying
> the colors and the order they will be applied.
>
> 2.  the scales parameter is what you are looking for.  The parameter is
> looking for a list which consists of name=value pairs. You can rotate
> the labels by a specified number of degrees.  In my example, I chose 30
> degrees, rot=30.
>
> 3. I don't know how to eliminate the vertical lines, but if you read the
> lattice documentation, you will find it (if it is possible).
>
> color=c("blue", "red", "green")
> dotplot(val ~ lot, tmp,
>  ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
>  pch=tmp$sybm, col=color)
>
>
> Hope this is helpful,
>
> Dan
>

I apologize; my use of the color vector was incorrect.  You could just 
use the tmp$color values with the correct color parameter name.  Like

dotplot(val ~ lot, tmp,
 ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
 pch=tmp$sybm, col=tmp$color)


Dan



-- 
Daniel Nordlund
Bothell, WA USA

__
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-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] Condition layer across panels in lattice

2016-02-15 Thread Duncan Mackay
Adding a condition column in the summary_data simplifies things a bit

summary_data$cond3 <- sapply(summary_data$cond2, pmatch, LETTERS)

mypanel <-
function(x, y, ..., lci, uci, scond1, scond3, groups, type, lty){

pnl = panel.number()

panel.xyplot(x, y, ..., groups = groups, type = type, lty = lty)

panel.average(x, y, horizontal = FALSE,
 col = "black",

  lwd = 3)

panel.segments(x0 = scond1[scond3 == pnl],
   y0 = lci[scond3 == pnl],
   x1 = scond1[scond3 == pnl],
   y1 = uci[scond3 == pnl])
}

with(summary_data,
stripplot(response ~ cond1 | cond2, data = raw_data,
  groups = subject,
  lci = lci,
  uci = uci,
  scond1 = summary_data$cond1,
  scond3 = cond3,
  type = "b",
  lty = 2,
  panel = mypanel

))

Regards

Duncan


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan
Mackay
Sent: Tuesday, 16 February 2016 15:16
To: R
Subject: Re: [R] Condition layer across panels in lattice

Sorry forgot to reply to list.

In addition (untested) modifying demo(lattice::intervals) to suit may help

Duncan 

-Original Message-
From: Duncan Mackay [mailto:dulca...@bigpond.com] 
Sent: Tuesday, 16 February 2016 12:12
To: 'Jeff Stevens'
Subject: RE: [R] Condition layer across panels in lattice

Hi Jeff

Try this

mypanel <-
function(x, y, ...,  groups, type, lty){

pnl = panel.number()

panel.xyplot(x, y, ..., groups = groups, type = type, lty = lty)

panel.average(x, y, horizontal = FALSE,
  col = "black", lwd = 3)

   # print(summary_data[,"lci"][summary_data$cond2==LETTERS[1:2][pnl]])
   # print(summary_data[,"uci"][summary_data$cond2==LETTERS[1:2][pnl]])

panel.segments(x0 =
summary_data[,"cond1"][summary_data$cond2==LETTERS[1:2][pnl]],
   y0 =
summary_data[,"lci"][summary_data$cond2==LETTERS[1:2][pnl]],
   x1 =
summary_data[,"cond1"][summary_data$cond2==LETTERS[1:2][pnl]],
   y1 =
summary_data[,"uci"][summary_data$cond2==LETTERS[1:2][pnl]])
panel.segments(x0 =
summary_data[,"cond1"][summary_data$cond2==LETTERS[1:2][pnl]],
   y0 =
summary_data[,"lci"][summary_data$cond2==LETTERS[1:2][pnl]],
   x1 =
summary_data[,"cond1"][summary_data$cond2==LETTERS[1:2][pnl]],
   y1 =
summary_data[,"uci"][summary_data$cond2==LETTERS[1:2][pnl]])

}

stripplot(response ~ cond1 | cond2, data = raw_data,
  groups = subject,
  #lci = summary_data$lci,
  #uci = summary_data$uci,
  #scond1 = summary_data$cond1,
  type = "b",lty = 2,
  panel = mypanel

)

It's a bit kludgy - I need some coffee to sort out the subscripting.

I used the panel.number to group the panels because the grouping factor for
the raw_data (subjects) is different from the summary_data (cond2)

I tried to keep it within lattice itself without having to go to
latticeExtra:::layer as you had. layering can have adverse changes to the
graphics appearance sometimes.

For the basis on why I did it this way see
 https://stat.ethz.ch/pipermail/r-help/2009-November/412966.html

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Stevens
Sent: Tuesday, 16 February 2016 03:59
To: R-help Forum
Subject: [R] Condition layer across panels in lattice

I would like to plot individual subject means for two different
conditions in a lattice stripplot with two panels. I would also like
to add within-subject confidence intervals that I have calculated and
stored in separate data frame. I am trying to overlay these confidence
intervals with latticeExtra's layer function. When I add the layer,
either both sets of intervals display on both panels (as illustrated
in code) or both sets of intervals display on only the first panel if
I add [subscripts] to the x's and y's in the layer command
(illustrated in second code clip). How do I get the appropriate
intervals to display on the appropriate panel?

Produces stripplot with both sets of intervals on both panels:
raw_data <- data.frame(subject = rep(1:6, 4), cond1 =
as.factor(rep(1:2, each = 12)), cond2 = rep(rep(c("A", "B"), each =
6), 2), response = c(2:7, 6:11, 3:8, 7:12))
summary_data <- data.frame(cond1 = as.factor(rep(1:2, each = 2)),
cond2 = rep(c("A", "B"), times = 2), mean = aggregate(response ~ cond2
* cond1, raw_data, mea

Re: [R] Condition layer across panels in lattice

2016-02-15 Thread Duncan Mackay
Sorry forgot to reply to list.

In addition (untested) modifying demo(lattice::intervals) to suit may help

Duncan 

-Original Message-
From: Duncan Mackay [mailto:dulca...@bigpond.com] 
Sent: Tuesday, 16 February 2016 12:12
To: 'Jeff Stevens'
Subject: RE: [R] Condition layer across panels in lattice

Hi Jeff

Try this

mypanel <-
function(x, y, ...,  groups, type, lty){

pnl = panel.number()

panel.xyplot(x, y, ..., groups = groups, type = type, lty = lty)

panel.average(x, y, horizontal = FALSE,
  col = "black", lwd = 3)

   # print(summary_data[,"lci"][summary_data$cond2==LETTERS[1:2][pnl]])
   # print(summary_data[,"uci"][summary_data$cond2==LETTERS[1:2][pnl]])

panel.segments(x0 =
summary_data[,"cond1"][summary_data$cond2==LETTERS[1:2][pnl]],
   y0 =
summary_data[,"lci"][summary_data$cond2==LETTERS[1:2][pnl]],
   x1 =
summary_data[,"cond1"][summary_data$cond2==LETTERS[1:2][pnl]],
   y1 =
summary_data[,"uci"][summary_data$cond2==LETTERS[1:2][pnl]])
panel.segments(x0 =
summary_data[,"cond1"][summary_data$cond2==LETTERS[1:2][pnl]],
   y0 =
summary_data[,"lci"][summary_data$cond2==LETTERS[1:2][pnl]],
   x1 =
summary_data[,"cond1"][summary_data$cond2==LETTERS[1:2][pnl]],
   y1 =
summary_data[,"uci"][summary_data$cond2==LETTERS[1:2][pnl]])

}

stripplot(response ~ cond1 | cond2, data = raw_data,
  groups = subject,
  #lci = summary_data$lci,
  #uci = summary_data$uci,
  #scond1 = summary_data$cond1,
  type = "b",lty = 2,
  panel = mypanel

)

It's a bit kludgy - I need some coffee to sort out the subscripting.

I used the panel.number to group the panels because the grouping factor for
the raw_data (subjects) is different from the summary_data (cond2)

I tried to keep it within lattice itself without having to go to
latticeExtra:::layer as you had. layering can have adverse changes to the
graphics appearance sometimes.

For the basis on why I did it this way see
 https://stat.ethz.ch/pipermail/r-help/2009-November/412966.html

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jeff Stevens
Sent: Tuesday, 16 February 2016 03:59
To: R-help Forum
Subject: [R] Condition layer across panels in lattice

I would like to plot individual subject means for two different
conditions in a lattice stripplot with two panels. I would also like
to add within-subject confidence intervals that I have calculated and
stored in separate data frame. I am trying to overlay these confidence
intervals with latticeExtra's layer function. When I add the layer,
either both sets of intervals display on both panels (as illustrated
in code) or both sets of intervals display on only the first panel if
I add [subscripts] to the x's and y's in the layer command
(illustrated in second code clip). How do I get the appropriate
intervals to display on the appropriate panel?

Produces stripplot with both sets of intervals on both panels:
raw_data <- data.frame(subject = rep(1:6, 4), cond1 =
as.factor(rep(1:2, each = 12)), cond2 = rep(rep(c("A", "B"), each =
6), 2), response = c(2:7, 6:11, 3:8, 7:12))
summary_data <- data.frame(cond1 = as.factor(rep(1:2, each = 2)),
cond2 = rep(c("A", "B"), times = 2), mean = aggregate(response ~ cond2
* cond1, raw_data, mean)$response, within_ci = c(0.57, 0.54, 0.6,
0.63))
summary_data$lci <- summary_data$mean - summary_data$within_ci
summary_data$uci <- summary_data$mean + summary_data$within_ci

subject_stripplot <- stripplot(response ~ cond1 | cond2, groups =
subject, data = raw_data,
  panel = function(x, y, ...) {
panel.stripplot(x, y, type = "b", lty = 2, ...)
panel.average(x, y, fun = mean, lwd = 2, col = "black", ...)#
plot line connecting means
  }
)
addWithinCI <- layer(panel.segments(x0 = cond1, y0 = lci, x1 = cond1,
y1 = uci, subscripts = TRUE), data = summary_data, under = FALSE)
plot(subject_stripplot + addWithinCI)

Produces stripplot with both sets of intervals on only the first panel:
addWithinCI2 <- layer(panel.segments(x0 = cond1[subscripts], y0 =
lci[subscripts], x1 = cond1[subscripts], y1 = uci[subscripts],
subscripts = TRUE), data = summary_data, under = FALSE)
plot(subject_stripplot + addWithinCI2)

Thanks,
Jeff

__
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.htm

Re: [R] tikzDevice and Sweave

2016-01-17 Thread Duncan Mackay
Hi 

I use Sweave  and some tikz in latex but not in Sweave

Your problem is that you left out Sweave in the preamble
It must be in the preamble of any Sweave document

I added sizing so that it is not off the page. 
I do not know if Sweave options will cover this or you have to set it.
eg
\setkeys{Gin}{width=1.0\textwidth}   

\documentclass{article}
\usepackage{tikz}
\usepackage{Sweave}

\begin{document}

Figure~\ref{tikzExampleFig} is an example of \texttt{tikzDevice} package. 

\begin{figure}
\begin{center}

<>=
# % <>=

# %<>=
# setwd("/Users/nareshgurbuxani/Documents/tex/tikz")
library(tikzDevice)

# added height and width
tikz(console = TRUE, width = 4, height = 3)
plot(sin, -pi, 2*pi, main = "A stand alone TikZ plot", xlab = "x", ylab =
"sin(x)")
dummy <- dev.off()
@

\caption{Example of tikz graph}
\label{tikzExampleFig}
\end{center}
\end{figure}

\end{document}

If this is an example for a larger document then have a look at the latex
hyperref package

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Naresh
Gurbuxani
Sent: Monday, 18 January 2016 06:54
To: R-help@r-project.org
Subject: Re: [R] tikzDevice and Sweave

Resending as a useable example

\documentclass{article}
\usepackage{tikz}

\begin{document}

Figure~\ref{tikzExampleFig} is an example of \texttt{tikzDevice} package. 

\begin{figure}
\begin{center}

<>=
# % <>=

# %<>=
# setwd("/Users/nareshgurbuxani/Documents/tex/tikz")
library(tikzDevice)

tikz(console = TRUE)
plot(sin, -pi, 2*pi, main = "A stand alone TikZ plot", xlab = "x", ylab =
"sin(x)")
dummy <- dev.off()
@

\caption{Example of tikz graph}
\label{tikzExampleFig}
\end{center}
\end{figure}

\end{document}


> Subject: Re: [R] tikzDevice and Sweave
> To: naresh_gurbux...@hotmail.com; r-help@r-project.org
> From: murdoch.dun...@gmail.com
> Date: Sun, 17 Jan 2016 15:40:24 -0500
>
> On 17/01/2016 3:25 PM, Naresh Gurbuxani wrote:
>> I want to use tikz() function in tikzDevice package so that it generates
a pdf file to be included in the bigger tex file. Below code works, but
directly inserts tikz commands in the output tex file.
>> This works:
>> <>=
>> This does not work:
>> <>=
>> Full code is given below:
>> \documentclass{article}\usepackage{tikz}
>> Figure~\ref{tikzExampleFig} is and an example of \texttt{tikzDevice}
package.
>> \begin{figure}\begin{center}
>> <>=
>> library(tikzDevice)tikz(console = TRUE)plot(sin, -pi, pi, main = "A stand
alone TikZ plot", xlab = "x", ylab = "sin(x)")dummy <- dev.off()@
>> \caption{Example of tikz
graph}\label{tikzExampleFig}\end{center}\end{figure}
>> \end{document}
>
> Your example isn't usable -- please post in plain text, not HTML.
>
> I can't tell whether you are trying to use Sweave or knitr. If you're
> using knitr, see the discussion of dev = "tikz" in
> <http://yihui.name/knitr/>. If you're using Sweave, you probably need
> pgfSweave.
>
> Duncan Murdoch
>
  
__
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-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] rjags loading error

2016-01-16 Thread Duncan Mackay
Hi

What version of JAGS are you using

JAGS 4.0.0 is current

library(rjags)
Loading required package: coda
Linked to JAGS 4.0.0
Loaded modules: basemod,bugs

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Dalthorp,
Daniel
Sent: Saturday, 16 January 2016 08:24
To: r-help@r-project.org
Subject: [R] rjags loading error

What has happened?!

I get the following error message when I try to load rjags package (w/
Windows 7)...


> require(rjags)
Loading required package: rjags
Error in get(method, envir = home) :
  lazy-load database 'C:/Program Files/R/R-3.2.3/library/rjags/R/rjags.rdb'
is corrupt
In addition: Warning messages:
1: In .registerS3method(fin[i, 1], fin[i, 2], fin[i, 3], fin[i, 4],  :
  restarting interrupted promise evaluation
2: In get(method, envir = home) :
  restarting interrupted promise evaluation
3: In get(method, envir = home) : internal error -3 in R_decompress1

I was able to use this package successfully a few months ago. Has something
changed?

Yes, I upgraded to R 3.2.3, but would that break the package?

Any help would be greatly appreciated!

Thanks.

-Dan

[[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-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] Panel plots for means of cyclical observations

2016-01-16 Thread Duncan Mackay
Hi

Continuing on from the data.frame code for z that you supplied
Using the data without summarizing first

z$mth = format(date "%m")
z$mth = format(date, "%m")

xyplot(rainfall ~ as.numeric(mth), z,
   groups = yr,
   type = "l",
   auto.key = T,
   scales = list(x = list(at = 1:12,
  labels = month.abb,
  rot = 60)),
   panel = panel.superpose,
   panel.groups = function(x,y, ...){
panel.average(x,y, fun = mean, horizontal = FALSE,
...)
  }
) ## xyplot

You may want to look into the zoo package as it has several date grouping
functions.

untested
z.tom <- aggregate(rainfall ~ year +month, z, mean, na.rm = T)

xyplot(rainfall ~ month, z.tom, groups = year, 
  scales = ... ,
 panel = panel.superpose)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Kieran
Sent: Friday, 15 January 2016 22:16
To: R-help@r-project.org
Subject: [R] Panel plots for means of cyclical observations

I want to create a panel plot using xyplot of a line graph whose
x-axis is months of the year and y-axis is the average rainfall in a
given month over the 6 years the data spans.

There should be two levels in this panel plot: odd and even months.

Creating this plot without splitting it into levels is quite
straightforward (creating a for loop to compute a vector of averages)
but the approach is not useful if you want to split the plots into
different levels.

Here is the code:

dfmt <- "%d/%m/%Y"
date <- seq(as.Date("01/01/2010", dfmt), as.Date("31/12/2015", dfmt),
"day")
month <- months(date)
rainfall <- runif(2191, 0, 150)
monthsOfYear <- c("January", "February", "March", "April",
"May", "June", "July", "August", "September", "October",
"November", "December")

parity <- match(month, monthsOfYear) %% 2
# even parity = 0, odd parity = 1

z <- data.frame(rainfall, date, month, parity)

The problem with using xyplot( y ~ x | f, data=z .. ) is the x and y I
want to plot are not columns in z but rather some kind of statistical
summary of columns.

__
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-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] Ordinal regression with some categories combined for some data

2016-01-16 Thread Duncan Mackay
Hi

I have never seen germination experiments carried out as ordinal regression.
Most germination tests are done using a nls model.
For some species germination may only start a week after planting and then
germinate over 2 or 3 days.
If all germinated over the experimental period and  there is no change in
germination between readings then read them accordingly. 
If there are ungerminated seeds at the end; have these then had germinable
tests been applied to them?.

I agree with Thierry about survival analysis.
If however you are wanting to get into latency then ordinal models may be OK
Another package to do ordinal regression is VGAM 

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Bob O'Hara
Sent: Saturday, 16 January 2016 01:49
To: r-help
Subject: [R] Ordinal regression with some categories combined for some data

Hi!

I've been asked about a problem where I think I can see how to write
the model, but don't know if it's been implemented in R. It's not
something I work on a lot, so I'm hoping someone else can point me to
an answer straight away.

The researcher has been carrying out germination experiments: lost of
seeds are put in several conditions (temperature humidity etc.), and
every few days they are checked to see if they have germinated.
Because the days are discrete I think it makes sense to view this as
an ordinal regression problem (rather than as an interval censored
survival analysis). But what makes this tricky is that there are days
when the researcher only checked some seeds. So for some seeds the
germination might fall into more than one category.

Is there a package in R that can handle this, i.e. do an ordinal
regression where for some observations the categories are interval
censored? Or is it easier to go straight to a full interval-censored
survival analysis?

Bob

-- 
Bob O'Hara

Biodiversity and Climate Research Centre
Senckenberganlage 25
D-60325 Frankfurt am Main,
Germany

Tel: +49 69 798 40226
Mobile: +49 1515 888 5440
WWW:   http://www.bik-f.de/root/index.php?page_id=219
Blog: http://occamstypewriter.org/boboh/
Journal of Negative Results - EEB: www.jnr-eeb.org

__
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-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] introduce axis break lattice plot multipanel

2015-12-20 Thread Duncan Mackay
Hi Luigi

 

If you went down the relation = “free” road you could change the panel widths 
to reflect the scales 

eg if lhs was 1:200 and rhs was 1:100 then the lhs panel would be twice as wide 
as the rhs.

 

I have some code reasonably handy I could send it to you if needed.

 

Regards

 

Duncan

 

From: Luigi Marongiu [mailto:marongiu.lu...@gmail.com] 
Sent: Sunday, 20 December 2015 20:35
To: Duncan Mackay
Subject: RE: [R] introduce axis break lattice plot multipanel

 

thank you duncan,
but in that case the scale of the two panel would be different. i think ill 
keep it as it comes.
best wishes of a merry xmas
luigi

On 19 Dec 2015 13:42, "Duncan Mackay"  wrote:

Hi Luigi

I suppose a cheats way out would be to put

scales = list(alternating = FALSE,
  x = list(relation = "free") ),

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Saturday, 19 December 2015 06:32
To: r-help
Subject: [R] introduce axis break lattice plot multipanel

Dear all,
I am plotting some data using lattice's barchart. One of the counts I
am plotting has a very large value with respect to the other variables
and I would like to introduce a break in the axis to compensate for
this 'anomaly' and give more breath to the other bars. In this example
the high count is for the variable 'b' and I would like to introduce a
break of 50-100 in the x axis.
I have seen from the internet that the common approach is to stack
together two figures but in my case I am using a multipanel plot and I
think this way won't work for my plot.
Is there a simple way to introduce a break in the axis of a multipanel
lattice plot?
Thank you
L

the example:
>>>
A <- c('a','b','c','d','a','b','c','d',
'b','c','d','b','c','d')
B <- c(1,1,1,1,1,1,1,1,1,1,1,
  1,1,1)
C <- c(0,0,0,0,1,1,1,1,0,0,0,
  1,1,1)
D <- c(4,120,7,23,4,24,3,12,7,1,
 1,5,0,0)
E <- c(0,0,0,0,0,0,0,0,1,1,1,
  1,1,1)
DF <- data.frame(A, B, C, D, E, stringsAsFactors = FALSE)
library(lattice)
barchart(
A ~ D|E,
DF,
groups = C,
stack = TRUE,
main = "Comparison of test results",
xlab = "Count",
col = c("yellow", "orange"),
par.settings = list(
strip.background = list(col="light grey"),
superpose.polygon=list(col= c("yellow", "orange"))
),
scales = list(
alternating = FALSE
),
key = list(
space="top",
columns=2,
text=list(c("Single infections", "Multiple infections"),
col="black"),
rectangles=list(col=c("yellow", "orange"))
),
)

__
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] introduce axis break lattice plot multipanel

2015-12-19 Thread Duncan Mackay
Hi Luigi

I suppose a cheats way out would be to put

scales = list(alternating = FALSE,
  x = list(relation = "free") ),

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Saturday, 19 December 2015 06:32
To: r-help
Subject: [R] introduce axis break lattice plot multipanel

Dear all,
I am plotting some data using lattice's barchart. One of the counts I
am plotting has a very large value with respect to the other variables
and I would like to introduce a break in the axis to compensate for
this 'anomaly' and give more breath to the other bars. In this example
the high count is for the variable 'b' and I would like to introduce a
break of 50-100 in the x axis.
I have seen from the internet that the common approach is to stack
together two figures but in my case I am using a multipanel plot and I
think this way won't work for my plot.
Is there a simple way to introduce a break in the axis of a multipanel
lattice plot?
Thank you
L

the example:
>>>
A <- c('a','b','c','d','a','b','c','d',
'b','c','d','b','c','d')
B <- c(1,1,1,1,1,1,1,1,1,1,1,
  1,1,1)
C <- c(0,0,0,0,1,1,1,1,0,0,0,
  1,1,1)
D <- c(4,120,7,23,4,24,3,12,7,1,
 1,5,0,0)
E <- c(0,0,0,0,0,0,0,0,1,1,1,
  1,1,1)
DF <- data.frame(A, B, C, D, E, stringsAsFactors = FALSE)
library(lattice)
barchart(
A ~ D|E,
DF,
groups = C,
stack = TRUE,
main = "Comparison of test results",
xlab = "Count",
col = c("yellow", "orange"),
par.settings = list(
strip.background = list(col="light grey"),
superpose.polygon=list(col= c("yellow", "orange"))
),
scales = list(
alternating = FALSE
),
key = list(
space="top",
columns=2,
text=list(c("Single infections", "Multiple infections"),
col="black"),
rectangles=list(col=c("yellow", "orange"))
),
)

__
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-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] filled circle with a black line on the rim in pch function

2015-12-01 Thread Duncan Mackay
This seems to get the colours for the legend correctly

xyplot(Abun~Date1|Station, data=Raw,
groups = Year,
par.settings = list(strip.background = list(col = "transparent"),
  superpose.symbol = list(pch =
rep(21,2),
   col=c(1,1),
   fill=c("gray","black"))),
type="p",
xlab=list("Month",cex=1.5),
ylab=list("Abundance",cex=1.5),
index.cond=list(c(1,2,3,4)),
auto.key = T,
layout=c(4,1))

If you use auto.key things get a bit tricky and need values from
trellis.par.set() ie par.settings within xyplot

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au





-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Jim Lemon
Sent: Tuesday, 1 December 2015 18:01
To: Christine Lee
Cc: r-help mailing list
Subject: Re: [R] filled circle with a black line on the rim in pch function

Hi Christine,
When I try to run your script, the plot fails:

Error in eval(expr, envir, enclos) : object 'culr' not found
> names(Raw)
[1] "Date""Year""Station" "Abun""Date1"

so I changed the second line to:

groups=Year,

and it did work. The default (pink, gray) background colors for the symbols
do appear when the symbol is changed to pch=21. The arguments

col="black",bg=c("gray","black"),

would produce the symbols you want in base graphics, but do not seem to do
so in lattice. I do get sort of what you want by modifying your code pretty
radically:

xyplot(Abun~Date1|Station, data=Raw,
groups = Year,
par.settings = list(strip.background = list(col = "transparent")),
type="p",
pch = rep(21,2),
col="black",
fill=c("gray","black"),
xlab=list("Month",cex=1.5),
ylab=list("Abundance",cex=1.5),
index.cond=list(c(1,2,3,4)),
auto.key = T,
layout=c(4,1))

Jim


On Tue, Dec 1, 2015 at 5:20 PM, Christine Lee via R-help <
r-help@r-project.org> wrote:

> Dear All,
>
> I have an embarssing question, I want to put a black line as a rim on the
> grey symbol in the xyplot, to no avail.
> .  I thought it was easy, by changing the pch code from 16 to 21.  I was
> surpised that I ran into difficulty.
>
> My original script is as follows:
> library(lattice)
> xyplot(Abun~Date1|Station, data=Raw,
> groups = culr,
> par.settings = list(strip.background = list(col = "transparent"),
> superpose.symbol = list(cex = rep(2, 2),
> col=c("grey","black"),
> pch = rep(16,2))),
> type="p",
> xlab=list("Month",cex=1.5),
> ylab=list("Abundance",cex=1.5),
> index.cond=list(c(1,2,3,4)),
> auto.key = T,
> layout=c(4,1))
>
>
> I have changed pch number into 21, the symbols did show a black rim, but
> the filled circle colours became blue and pink, instead of the designated
> grey and black.  This puzzles me.
>
> My data is as follows:
> Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L,
> 2L, 4L, 12L, 6L, 15L, 14L, 3L, 6L, 1L, 16L, 5L, 11L, 8L, 4L,
> 10L, 13L, 6L, 1L, 16L, 5L, 11L, 8L, 4L, 10L, 13L, 6L, 1L, 16L,
> 5L, 11L, 8L, 4L, 10L, 13L, 11L, 8L, 4L, 10L, 13L), .Label = c("1/10",
> "1/11", "11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9",
> "26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class =
> "factor"),
> Year = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
> 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Y2002", "Y2014"), class =
> "factor"),
> Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
> 2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
> 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
> 3L, 3L, 4L, 4L, 4L, 4L, 4L), .Label = c("E", "F", "H", "I"
> ), class = "factor"), Abun = c(3.42, 1.33, 3.67, 3.67, 3.92,
> 2.17, 2.5, 1.67, 6.33, 0.67, 1, 1, 1.33, 2.

Re: [R] [lattice::xyplot] Using (panel:.)abline with panel.superpose?

2015-10-07 Thread Duncan Mackay
Forgot to send to list

-Original Message-
From: Duncan Mackay [mailto:dulca...@bigpond.com] 
Sent: Thursday, 8 October 2015 08:44
To: 'Szumiloski, John'
Subject: RE: [R] [lattice::xyplot] Using (panel:.)abline with
panel.superpose?

Hi John

I only got grid lines on your # code 2 with same lattice version on win 7
and blank for the first code

Try

xyplot(Y~X|Trt, data=dat,
   groups=Sbj,
   type='b',
   lty=1,
   cex=2,
   lwd=3,
   scales=list(x=list(at=xgrid), y=list(at=ygrid)),
   col=c('red', 'blue'),
   pch=c(16,17),
   panel= panel.superpose,
   panel.groups = function(x,y, ...){

panel.abline(h=ygrid, v=xgrid, col = gray(0.9) )

panel.xyplot(x,y, ...)

  }# panel
) # xyplot

It produces grid lines over the lines and points so one way around it is to
use alpha settings.
Not all devices will accept alpha.

xyplot(Y~X|Trt, data=dat,
   groups=Sbj,
   type='b',
   lty=1,
   cex=2,
   lwd=3,
   alpha = 1,
   scales=list(x=list(at=xgrid), y=list(at=ygrid)),
   col=c('red', 'blue'),
   pch=c(16,17),
   panel= panel.superpose,
   panel.groups = function(x,y,alpha, ...){

panel.abline(h=ygrid, v=xgrid, col=1, alpha = 0.1)

panel.xyplot(x,y, alpha = 1, ...)
   
  }# panel
) # xyplot

If you use par.settings it will give correct colours lines etc to auto key

xyplot(Y~X|Trt, data=dat,
   groups=Sbj,
   type='b',
   par.settings = list(strip.background = list(col = "transparent"),
   superpose.line = list(col = c('red', 'blue'),
 alpha = 1,
 lty=1,lwd=3),
   superpose.symbol = list(col=c('red', 'blue'),
   alpha = 1,
   pch=c(16,17),
   cex=2)),
   scales=list(x=list(at=xgrid), y=list(at=ygrid)),
 auto.key = T,
   panel= panel.superpose,
   panel.groups = function(x,y,alpha, ...){

panel.abline(h=ygrid, v = xgrid, col=1, alpha = 0.1)

    panel.xyplot(x,y, alpha = 1, ...)

  }# panel
) # xyplot

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Szumiloski,
John
Sent: Thursday, 8 October 2015 03:40
To: r-help@r-project.org
Subject: [R] [lattice::xyplot] Using (panel:.)abline with panel.superpose?

Dear useRs,

I recently had a query concerning how to customize the graphics parameters
in lattice::xyplot to change not only the color but also the pch symbols,
lty and lwd line parameters, etc., within each grouping variable in the
plot.  (https://stat.ethz.ch/pipermail/r-help/2015-July/430285.html).  Many
thanks to Mark Leeds who described the solution using panel.superpose as the
panel function and defining a custom panel.groups function using the
subscripts argument.

Here is a crude example.  Note how the pch parameter varies with grouping
variable as well as color.  I have commented out two lines which are not
important for the example but are for my main question.

 begin code 1

# R version 3.2.2 release, lattice version 0.20-33, Windows 7.

dat <- data.frame(Trt=rep(c('1','2'), each=10),
  Sbj=rep(c('1','2'), each=5),
  X=rep(c(0,1,2,3,4), times=4),
  Y=c(1,3,3,3,1, 2,4,4,4,2,
  3,1,1,1,3, 4,2,2,2,4)
 )

xgrid <- seq(0L, 4L)
ygrid <- seq(0L, 5L)

require(lattice)
xyplot(Y ~ X | Trt, data=dat, groups=Sbj, type='b', lty=1, cex=2, lwd=3,
   scales=list(x=list(at=xgrid), y=list(at=ygrid)),
   ### abline=list(h=ygrid, v=xgrid, col=gray(0.8)),
   mycol=c('red', 'blue'), mypch=c(16,17),
   panel=panel.superpose,
   panel.groups=function(x, y, subscripts,
  mycol, mypch, col.line, col.symbol, pch,
...) {
 ### panel.abline(h=ygrid, v=xgrid,
col=gray(0.8))
 panel.xyplot(x, y, ...,
 pch =
mypch[dat[['Sbj']][subscripts]],
  col.symbol =
mycol[dat[['Sbj']][subscripts]],
col.line =

Re: [R] lattice plot: points and lines for different variables in same plotlattice plot

2015-10-04 Thread Duncan Mackay
Hi Naresh

Try

xyplot(y + y.fit ~ x | name, data = my.df,
 type = c("p","l"),
 distribute.type = TRUE,
 panel = panel.superpose
)

Your code seems to be a direct copy from the command line; sometimes it
makes it clearer to arguments and functions within the panel function on
their own line

Regards
Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Naresh
Gurbuxani
Sent: Monday, 5 October 2015 05:30
To: r-help@r-project.org
Subject: [R] lattice plot: points and lines for different variables in same
plotlattice plot

I want to draw scatter plot and a fitted line in the same lattice plot.  My
problem is that either both can be plotted as points or both as lines.  The
code that attempts to plot points for data and lines for fitted line does
not work.  

Thanks,
Naresh

library(lattice)
library(plyr)

my.df <- data.frame(x = rnorm(100), y = rnorm(100), name = "A")

temp.df <- data.frame(x = rnorm(100), name = "B")
temp.df <- within(temp.df, {y <- x + 0.2 * rnorm(100)})
my.df <- rbind(my.df, temp.df)

temp.df <- data.frame(x = rnorm(100), name = "C")
temp.df <- within(temp.df, {y <- x + 0.5 * x^2 + 0.2 * rnorm(100)})
my.df <- rbind(my.df, temp.df)

my.df <- ddply(my.df, c("name"), mutate, y.fit = lm(y ~ x +
I(x^2))$fitted.values)

my.df <- my.df[order(my.df$name, my.df$x),]

# This works
xyplot(y + y.fit ~ x | name, data = my.df, type = c("l"))

# This does not work.  Line plot seems wrong.
xyplot(y + y.fit ~ x | name, data = my.df, type = c("l"), y.prime =
my.df$y.fit, panel = function(x, y, y.prime, ...){panel.xyplot(x, y);
panel.lines(x, y.prime, type = "l")})


  
[[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-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] Count number of rain more than zero in matrix form

2015-10-01 Thread Duncan Mackay
Hi

Assuming you data.frame is dat
then you have to restrict the data going to a function to be counted so that it 
counts values > 0

with(dat, tapply(Amount, list(Year, Month), function(x) length(x[x > 0])) )
gives

  1  2  3  4  5  6  7  8  9 10 11 12
1960 24 15  2 12 19 22 18 24 22 20 30 29
1961 26  9 10 18 18 11 18 14 24 28 30 31
1962 22 14 19  2 18 19 27 26 26 29 15 28
1963 27 17 15  4  9 23 16 24 19 28 30 22
1964 15 25  9 13 19 14 23 20 24 30 25 27
1965 13 21 12 10 21 24 22 21 28 23 28 31

If you want to have years and months in date format you could use
the as.yearmon function from library(zoo) after converting year month day to a 
date format with as.Date
and go on from there

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of smart hendsome
Sent: Thursday, 1 October 2015 12:47
To: r-help@r-project.org
Subject: [R] Count number of rain more than zero in matrix form

Hello R-users,
I want to ask how to count the number of daily rain data.  My data using dput() 
as below:
structure(list(Year = c(1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 1960L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 1961L, 
1961L, 1961L, 1961L,

Re: [R] 回覆︰ adding a line across plots in xy plot with panel.abline

2015-09-14 Thread Duncan Mackay
forgot to send to list

 

From: Duncan Mackay [mailto:dulca...@bigpond.com] 
Sent: Tuesday, 15 September 2015 01:47
To: 'Christine Lee'
Subject: RE: 回覆︰ [R] adding a line across plots in xy plot with panel.abline

 

Hi

 

If your panel function was like this (just adding to plot the points with the 
argument panel.xyplot  

 

panel= function(Date1,DI){

 panel.xyplot(Date1,DI)

 panel.abline(h=1,lty=2,lwd=3)

}

 

and this would cause an error see ? panel.xyplot

you can test it by replacing the lines  and see what happens

 

Now with the panel function like this 

panel = function(x, y, ...){



  panel.xyplot(x,y, ...)

  panel.abline(h=1,lty=2,lwd=3)

}

 

it will “carry” the parameters in par.settings to the functions within the 
panel function.

One advantage of this is that you do not have to finish panel.xplot with what 
you want eg

 

panel.xyplot(x,y,  pch = 16, col = c(1,2), cex = 2)

 

In some contexts you can get away with just

   panel = function(...){



but in this case there is an error message in each panel saying y cannot be 
found

 

I cannot think of a good example at the moment run

 

demo(lattice::intervals )

and look at the code output

 

see also ? panel.superpose

 

 

Regards

 

Duncan

 

 

 

From: Christine Lee [mailto:leptostra...@yahoo.com] 
Sent: Monday, 14 September 2015 19:30
To: Duncan Mackay; R
Subject: 回覆︰ [R] adding a line across plots in xy plot with panel.abline

 

Thanks, Duncan,

 

I am confused by the function(x,y, ...) and panel.xyplot(x,y,...).  Is this a 
must to put in "..."? I knew this may be a stupid question.  I am sorry.

 

Christine

 

 

Duncan Mackay  於 2015年09月14日 (週一) 3:56 PM 寫道﹕

 

Hi 

As Bert has intimated there was a misspelling in panel.abline

To get points as well you need the appropriate arguments for a panel
function otherwise you would only get a line.
You only had a function for  a line in panel function so adding panel.xyplot
will give you points as well.


xyplot(DI~Date1|Station, data=Raw,
groups = culr,
par.settings = list(strip.background = list(col = "transparent"),
superpose.symbol = list(cex = rep(2, 2),
col=c("grey","black"),
pch = rep(16,2))),
type="p",
xlab=list("Month",cex=1.5),
ylab=list("Dispersion index",cex=1.5),
index.cond=list(c(1,2,3,4)),
auto.key = T,
layout=c(4,1),
panel = function(x, y, ...){

  panel.xyplot(x,y, ...)
  panel.abline(h=1,lty=2,lwd=3)
}

)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Christine
Lee via R-help
Sent: Monday, 14 September 2015 13:43
To: r-help@r-project.org
Subject: [R] adding a line across plots in xy plot with panel.abline

Dear all,

I want to draw a line at DI=1 across all four graphs in the xy plot, I have
used panel.abline, but I failed to do so, does any one has an idea of what
has went wrong?

structure(list(Date = structure(c(6L, 7L, 2L, 4L, 13L, 17L, 5L, 
12L, 4L, 11L, 14L, 9L, 7L, 2L, 4L, 13L, 10L, 17L, 5L, 12L, 8L, 
4L, 11L, 14L, 9L, 16L, 15L, 3L, 10L, 1L, 17L, 5L, 12L, 8L, 4L, 
11L, 14L, 12L, 8L, 4L, 11L, 14L), .Label = c("1/10", "1/11", 
"11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", "23/9", 
"26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class =
"factor"), 
Year = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L), .Label = c("Y2002", "Y2014"), class = "factor"), 
Station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 
4L, 4L, 4L), .Label = c("E", "F", "H", "I"), class = "factor"), 
DI = c(13.4, 7, 12.6, 12.6, 5.2, 2.2, 1, 1, 1.2, 0.8, 2.3, 
3.8, 5.4, 4.6, 5, 3.2, 3.1, 8.7, 2.1, 2.7, 4.9, 4, 2.2, 5.3, 
5.6, 4.8, 4, 8.6, 1.9, 2.9, 5.9, 2.6, 8.9, 4, 13.5, 15.3, 
12.8, 3.4, 4.7, 1.7, 0.9, 1.7), Date1 = structure(c(16697, 
16710, 16740, 16751, 16768, 16714, 16721, 16737, 16751, 16765, 
16769, 16698, 16710, 16740, 16751, 16768, 16701, 16714, 16721, 
16737, 167

Re: [R] adding a line across plots in xy plot with panel.abline

2015-09-14 Thread Duncan Mackay
Hi 

As Bert has intimated there was a misspelling in panel.abline

To get points as well you need the appropriate arguments for a panel
function otherwise you would only get a line.
You only had a function for  a line in panel function so adding panel.xyplot
will give you points as well.


xyplot(DI~Date1|Station, data=Raw,
groups = culr,
par.settings = list(strip.background = list(col = "transparent"),
superpose.symbol = list(cex = rep(2, 2),
col=c("grey","black"),
pch = rep(16,2))),
type="p",
xlab=list("Month",cex=1.5),
ylab=list("Dispersion index",cex=1.5),
index.cond=list(c(1,2,3,4)),
auto.key = T,
layout=c(4,1),
panel = function(x, y, ...){

  panel.xyplot(x,y, ...)
  panel.abline(h=1,lty=2,lwd=3)
}

 )

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Christine
Lee via R-help
Sent: Monday, 14 September 2015 13:43
To: r-help@r-project.org
Subject: [R] adding a line across plots in xy plot with panel.abline

Dear all,

I want to draw a line at DI=1 across all four graphs in the xy plot, I have
used panel.abline, but I failed to do so, does any one has an idea of what
has went wrong?

structure(list(Date = structure(c(6L, 7L, 2L, 4L, 13L, 17L, 5L, 
12L, 4L, 11L, 14L, 9L, 7L, 2L, 4L, 13L, 10L, 17L, 5L, 12L, 8L, 
4L, 11L, 14L, 9L, 16L, 15L, 3L, 10L, 1L, 17L, 5L, 12L, 8L, 4L, 
11L, 14L, 12L, 8L, 4L, 11L, 14L), .Label = c("1/10", "1/11", 
"11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", "23/9", 
"26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class =
"factor"), 
Year = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 
1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L), .Label = c("Y2002", "Y2014"), class = "factor"), 
Station = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 
4L, 4L, 4L), .Label = c("E", "F", "H", "I"), class = "factor"), 
DI = c(13.4, 7, 12.6, 12.6, 5.2, 2.2, 1, 1, 1.2, 0.8, 2.3, 
3.8, 5.4, 4.6, 5, 3.2, 3.1, 8.7, 2.1, 2.7, 4.9, 4, 2.2, 5.3, 
5.6, 4.8, 4, 8.6, 1.9, 2.9, 5.9, 2.6, 8.9, 4, 13.5, 15.3, 
12.8, 3.4, 4.7, 1.7, 0.9, 1.7), Date1 = structure(c(16697, 
16710, 16740, 16751, 16768, 16714, 16721, 16737, 16751, 16765, 
16769, 16698, 16710, 16740, 16751, 16768, 16701, 16714, 16721, 
16737, 16741, 16751, 16765, 16769, 16698, 16712, 16739, 16750, 
16701, 16709, 16714, 16721, 16737, 16741, 16751, 16765, 16769, 
16737, 16741, 16751, 16765, 16769), class = "Date")), .Names = c("Date",

"Year", "Station", "DI", "Date1"), row.names = c(NA, -42L), class =
"data.frame")
Raw$Date1<-as.Date(Raw$Date,"%d/%m")
culr<-ifelse(Raw$Year=="Y2002","Year 2002","Year 2014")
library(lattice)
xyplot(DI~Date1|Station, data=Raw,
groups = culr,
par.settings = list(strip.background = list(col = "transparent"),
superpose.symbol = list(cex = rep(2, 2),
col=c("grey","black"),
pch = rep(16,2))),
type="p",
xlab=list("Month",cex=1.5),
ylab=list("Dispersion index",cex=1.5),  
index.cond=list(c(1,2,3,4)),
auto.key = T,
layout=c(4,1),
panel=function(Date1,DI){
panel.labline(h=1,lty=2,lwd=3)
})

Many thanks.

Regards,
Christine

 

__
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-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] Adding a second Y axis on a dotplot

2015-09-12 Thread Duncan Mackay

I forgot to put a line about latticeExtra's doubleYScale
library(latticeExtra)
? doubleYScale
Duncan


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Duncan
Mackay
Sent: Sunday, 13 September 2015 00:56
To: R
Subject: Re: [R] Adding a second Y axis on a dotplot

Hi

see https://stat.ethz.ch/pipermail/r-help/2007-June/134524.html

to get you started. Its toolate or too early here

Regards

Duncan 

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of li li
Sent: Saturday, 12 September 2015 03:30
To: r-help
Subject: [R] Adding a second Y axis on a dotplot

Hi all,
  I plotted a dotplot based on the data below and code below. I would
like to add another yaxis on the right with a different col, different
tickmarks and a different label. Can anyone give some help?Thanks very
much!!
 Hanna


> tmp1
   result  lot  trt trtsymb trtcol
1  98 lot1 trt1   1   blue
2  99 lot2 trt1   1   blue
3  98 lot3 trt1   1   blue
4 100 lot4 trt1   1   blue
5 100 lot5 trt1   1   blue
6 101 lot6 trt1   1   blue
7 101 lot7 trt1   1   blue
8  99 lot8 trt1   1   blue
9 100 lot9 trt1   1   blue
10 94 lot1 trt2  16red
11105 lot2 trt2  16red
12 87 lot3 trt2  16red
13119 lot4 trt2  16red
14 96 lot5 trt2  16red
15113 lot6 trt2  16red
16106 lot7 trt2  16red
17 71 lot8 trt2  16red
18 95 lot9 trt2  16red


library(lattice)
dotplot(result ~ lot, tmp1, cex=1.1,  ylab = "values", xlab="lot",
jitter.y = F, aspect=1.0,
pch=tmp1$trtsymb, col=tmp1$trtcol, scales=list(rot=30),
main="", key = list(text = list(labels = c("trt1", "trt2"),cex=c(0.9,0.9)),
points = list(pch =c(1,12), col =c("blue", "red")),
space = "right"))

__
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-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-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] Adding a second Y axis on a dotplot

2015-09-12 Thread Duncan Mackay
Hi

see https://stat.ethz.ch/pipermail/r-help/2007-June/134524.html

to get you started. Its toolate or too early here

Regards

Duncan 

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of li li
Sent: Saturday, 12 September 2015 03:30
To: r-help
Subject: [R] Adding a second Y axis on a dotplot

Hi all,
  I plotted a dotplot based on the data below and code below. I would
like to add another yaxis on the right with a different col, different
tickmarks and a different label. Can anyone give some help?Thanks very
much!!
 Hanna


> tmp1
   result  lot  trt trtsymb trtcol
1  98 lot1 trt1   1   blue
2  99 lot2 trt1   1   blue
3  98 lot3 trt1   1   blue
4 100 lot4 trt1   1   blue
5 100 lot5 trt1   1   blue
6 101 lot6 trt1   1   blue
7 101 lot7 trt1   1   blue
8  99 lot8 trt1   1   blue
9 100 lot9 trt1   1   blue
10 94 lot1 trt2  16red
11105 lot2 trt2  16red
12 87 lot3 trt2  16red
13119 lot4 trt2  16red
14 96 lot5 trt2  16red
15113 lot6 trt2  16red
16106 lot7 trt2  16red
17 71 lot8 trt2  16red
18 95 lot9 trt2  16red


library(lattice)
dotplot(result ~ lot, tmp1, cex=1.1,  ylab = "values", xlab="lot",
jitter.y = F, aspect=1.0,
pch=tmp1$trtsymb, col=tmp1$trtcol, scales=list(rot=30),
main="", key = list(text = list(labels = c("trt1", "trt2"),cex=c(0.9,0.9)),
points = list(pch =c(1,12), col =c("blue", "red")),
space = "right"))

__
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-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] modify strip labels with given text using lattice package

2015-08-31 Thread Duncan Mackay
Hi Luigi

add strip.custom argument

barchart(test ~ count|assay, df,
  groups = res,
  stack = TRUE,
  main = "Comparison of test results",
  xlab = "Count",
  col = c("yellow", "blue"),
  strip= strip.custom(factor.levels = c("molecular
test","serological test"),
  par.strip.text = list(cex = 1) ),
   par.settings = list(
  strip.background = list(col="light grey"),
  superpose.polygon=list(col= c("yellow", "blue"))
  ),
  scales = list(alternating = FALSE),
 key = list(
space="top",
columns=2,
text=list(c("Negative", "Positive"), col="black"),
rectangles=list(col=c("yellow", "blue"))
)
 )


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Tuesday, 1 September 2015 06:18
To: r-help
Subject: [R] modify strip labels with given text using lattice package

Dear all,
I am drawing a barchart plot with lattice and the resulting strips are
taking the value of the variable being compared (in this example
"assay"). However I would like to write myself the value to place into
the strips, let's say I want to call the variables as "molecular test"
and "serological test" the values "a" and "b" respectively within
"assay". I have tried different approaches taken from the web but
nothing worked.
Would you have any tip?
Best regards
Luigi

>>>
test <- rep(c("Adenovirus", "Rotavirus", "Norovirus", "Rotarix",
"Sapovirus"), 2)
res <- c(0, 1, 0, 1,0, 1,0, 1,0, 1, 0, 1, 0, 1,0, 1,0, 1,0, 1)
count <- rnorm(20)
assay <- c(rep("a", 10), rep("b", 10))

df <- data.frame(test, res, count, assay, stringsAsFactors = FALSE)

library(lattice)
barchart(
test ~ count|assay,
df,
groups = res,
stack = TRUE,
main = "Comparison of test results",
xlab = "Count",
col = c("yellow", "blue"),
par.settings = list(
strip.background = list(col="light grey"),
superpose.polygon=list(col= c("yellow", "blue"))
),
scales = list(
alternating = FALSE
),
key = list(
space="top",
columns=2,
text=list(c("Negative", "Positive"), col="black"),
rectangles=list(col=c("yellow", "blue"))
)
)

__
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-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] Piecewise regression using segmented package plotted in xyplot

2015-08-28 Thread Duncan Mackay
Hi

Without a reproducible example I am only guessing 

Try this 

xyplot(threshold ~ age |frequency.a, data=subset(rage !is.na(threshold} &
!is.na(age)),
   groups = HL,
   cex=0.5,
   layout=c(7,4),
   par.strip.tex=list(cex=0.8),
   xlab="Age (years)",
   ylab="Threshold (dB SPL)",
   # na.rm="TRUE", # see above
   type = c("p","l"),  # re-read ?xyplot: from the panel section:
panel.abline(lm(threshold~age))
   panel = panel.superpose,
   panel.groups =function(x,y,groups,...) {

panel.xyplot(x,y,...)
# panel.abline(segmented(lm(threshold~age),seg.Z =
~age, psi = NA, control = seg.control(K=1)))

  },
)

I do not know what the commented line means-- you may need to look at the
subscripts section as well as panel.groups of ?xyplot
and ?panel.xyplot

Regards

Duncan

Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Sumitrajit
Dhar
Sent: Friday, 28 August 2015 14:12
To: r-help@r-project.org
Subject: [R] Piecewise regression using segmented package plotted in xyplot

Hi,

xyplot(threshold ~ age |frequency.a, data=rage,
groups=HL,
  cex=0.5,
  layout=c(7,4),
par.strip.tex=list(cex=0.8),
  xlab="Age (years)",
  ylab="Threshold (dB SPL)",
  na.rm="TRUE",
  panel=function(x,y,groups,...) {
panel.superpose(x,y,groups=HL,...)
# panel.abline(segmented(lm(threshold~age),seg.Z = ~age, psi = NA, control =
seg.control(K=1)))
panel.abline(lm(threshold~age))
  },
  )

Is there anyway to make the commented line work in lattice? I need to fit my
data in each panel using piecewise regression. Being able to use segmented
would make it easy.

The code above works to give me a linear fit.

Thanks for your help in advance.

Regards,
Sumit



[[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-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] xyplot colour points and layout

2015-08-27 Thread Duncan Mackay
Hi 

Following on from Davids reply you can do the following if you want a key or
legend.
By putting the colour scheme in par.settings the "local" equivalent of
setting trellis.par.set() for that plot
you can get things right for the key without having to have add arguments to
key

  culr<-ifelse(Raw$Year=="Y2002","Year 2002","Year 2014")

  xyplot(Abun~Date1|Station, data=Raw,
groups = culr,
par.settings = list(strip.background = list(col = "transparent"),
superpose.symbol = list(cex = rep(2, 2),
col=c("grey","black"),
pch = rep(16,2))),
type="p",
xlab=list("Month",cex=1.5),
ylab=list("Abundance",cex=1.5),
    auto.key = T)

see 
names(trellis.par.get())
for a list of the settings

Regards

Duncan
Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Christine
Lee via R-help
Sent: Thursday, 27 August 2015 13:41
To: r-help@r-project.org
Subject: [R] xyplot colour points and layout

Dear All,

I have tried to plot graphs of one row of four figures for each station.  In
each graph, black points indicate data in the year of 2002, denoted as
Y2002, whereas grey points indicate data in the year of 2014, denoted as
Y2014.  I ended up with 2x2 plots with all data points in black.  Can anyone
find out what has gone wrong by any chance please?

Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L, 
2L, 4L, 12L, 6L, 15L, 14L, 3L, 6L, 1L, 16L, 5L, 11L, 8L, 4L, 
10L, 13L, 6L, 1L, 16L, 5L, 11L, 8L, 4L, 10L, 13L, 6L, 1L, 16L, 
5L, 11L, 8L, 4L, 10L, 13L, 11L, 8L, 4L, 10L, 13L), .Label = c("1/10", 
"1/11", "11/11", "12/11", "13/10", "19/9", "2/10", "2/11", "20/9", 
"26/11", "29/10", "29/11", "30/11", "31/10", "4/10", "6/10"), class =
"factor"), 
Year = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L), .Label = c("Y2002", "Y2014"), class =
"factor"), 
Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
2L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 4L, 4L, 4L, 4L, 4L), .Label = c("E", "F", "H", "I"
), class = "factor"), Abun = c(3.42, 1.33, 3.67, 3.67, 3.92, 
2.17, 2.5, 1.67, 6.33, 0.67, 1, 1, 1.33, 2.08, 0, 0, 0.33, 
0.08, 0.08, 0, 0.5, 0.17, 0.67, 0.67, 0, 1, 0.58, 1.5, 2.67, 
0.67, 1.33, 3, 0.58, 1.17, 1.25, 0.75, 1.25, 1.75, 0.92, 
1.5, 0.83, 0.75, 2.33, 0.67, 1.33, 1.58), Date1 = structure(c(16697, 
16710, 16740, 16751, 16768, 16698, 16710, 16740, 16751, 16768, 
16697, 16712, 16739, 16750, 16697, 16709, 16714, 16721, 16737, 
16741, 16751, 16765, 16769, 16697, 16709, 16714, 16721, 16737, 
16741, 16751, 16765, 16769, 16697, 16709, 16714, 16721, 16737, 
16741, 16751, 16765, 16769, 16737, 16741, 16751, 16765, 16769
), class = "Date")), .Names = c("Date", "Year", "Station", 
"Abun", "Date1"), row.names = c(NA, -46L), class = "data.frame")
Raw$Date1<-as.Date(Raw$Date,"%d/%m")
library(lattice)
par(mfrow=c(1,4))
culr<-ifelse(Raw$Year=="Y2002","Black","Grey")
xyplot(Abun~Date1|Station,Raw,type="p",xlab=list("Month",cex=1.5),ylab=list(
"Abundance",cex=1.5),cex=2,pch=16,col=culr,strip=strip.custom(bg='white'))


Many thanks.

Regards,
Christine

__
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-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] date format in xyplot

2015-08-18 Thread Duncan Mackay
Hi

I forgot to change the format and put the panel back in - I was trying to get 
the data right

see ? strptime for a list of all the combinations for dates.

Have a look at 
http://lmdvr.r-forge.r-project.org/figures/figures.html
which may give you some ideas.

If you want  to restrict data to a certain period you will have to put limits 
on the x axis and you do that in the scales argument ie x =list(limits = c(min 
date, max date) )  NB date format
For one panel it is easy but for 2+ it can be tricky as you will be working 
with a list. 
Then the code would be something like

xyplot(Abun~Date2|Year, Raw, 
scales = list(x = list(limits = list(c(min y1, max y1), c(min y2, 
max y2))) 
..
)
where y[1...] is the applicable year 
have a look at aspect which may improve things for the final plot if desired.

If you want to space groups of years-- see between 
 
Regards

Duncan

-Original Message-
From: Christine Lee [mailto:leptostra...@yahoo.com] 
Sent: Wednesday, 19 August 2015 00:26
To: R; Duncan Mackay
Subject: RE: [R] date format in xyplot

Thank you Duncan,

I have tried the scales function.  It ends up with 2015-09-15, which is 
acceptable. It is far much better than "09 15" shown on the axis.  The problem 
is the data were obtained in different years.  This makes "2015" shown in 
lattice plots of different years.  I have tried to put in the year in the raw 
data (such as "1/10/2013"), but the plot is really bizzard, with the 2002 plots 
have all the points on the left of the plot whereas 2013 plots have all the 
data points on the right of the plots because the x-axis shows data from 2001 
to 2013.  I feel like hopeless to insist to have the axis label shown as "Sep 
15" because it seems to be the problem of my computer setting.  Is there a way 
to shows graphs in different years, but with the same scale beginning from 
September to December?

Regards,
Christine


--------
2015年8月18日 星期二,Duncan Mackay  寫道﹕

 主題: RE: [R] date format in xyplot
 收件人: "R" 
 副本(CC): "'Christine Lee'" 
 日期: 2015年8月18日,星期二,下午4:08

 Hi Christine

 If somethings go wrong:
 1 first check your data

 str(Raw)
 'data.frame':   10 obs. of 
 5 variables:
  $ Date   : Factor
 w/ 16 levels "1/10","1/11",..: 6 7 2 4
 12 9 7 2 4 12
  $ Year   : int 
 2002 2002 2002 2002 2002 2002 2002 2002 2002 2002
  $ Station: Factor w/ 4 levels
 "E","F","H","I": 1 1
 1 1 1 2 2 2 2 2
  $ Abun   : num 
 3.42 1.33 3.67 3.67 3.92 2.17 2.5 1.67 6.33 0.67
  $ Date1  : Date, format:
 "2015-09-19" "2015-10-02"
 "2015-11-01"
 "2015-11-12" ...

 Raw$Date2 <- as.character(Raw$Date1)
 Raw$Date2
 [1]
 "2015-09-19" "2015-10-02"
 "2015-11-01" "2015-11-12"
 "2015-11-29"
 "2015-09-20" "2015-10-02"
 "2015-11-01" "2015-11-12"
 "2015-11-29"
 Raw$Date2 <-
 as.Date(Raw$Date2, "%Y-%m-%d")

 2 read the help guide again if not done
 recently ?lattice::xyplot or ?xyplot
 3 start
 with a minimum number of arguments

 xyplot(Abun~Date2|as.factor(Year), Raw)
 or 
 xyplot(Abun~Date2, Raw)
 if you are still having problems

 Dates are hard work in any
 language as they are not consistent so:
 a. 
 use  default
 b.  use your own 

 This works

 xyplot(Abun~Date2|as.factor(Year), Raw,
par.settings =
 list(stripbackground = "transparent"), #
 background
 colour controlled here
type="p",
scales = list(x = list(at =
 sort(c(seq(as.Date(Raw$Date2[1]-4), by =
 "months", length = 4),

seq(as.Date(Raw$Date2[1]+12),
 by
 = "months", length = 3))),

labels =
 format(sort(c(seq(as.Date(Raw$Date2[1]-4), by =
 "months", length = 4),
  
 seq(as.Date(Raw$Date2[1]+12), by =
 "months", length = 3))), "%m-%d") )
 ),

xlab=list("Month",cex=1.5),

ylab=list("Abundance",cex=1.5),
cex=2,
  
  pch=c(16,16,21),

col=c("Black","Grey","Black")
 )

 par.settings
 is confining the parameters set by trellis.par.set()  to
 the
 function
 to get them

 names(trellis.par.get() )
 and going further
 trellis.par.get()$superpose.symbol
 will give you the values for
 superpose.symbol

 Beware: Do
 not make the labels etc so big that the axis labels are hard
 to
 read. Think of final size

 Regards

 Duncan

 Duncan
 Mackay
 Department of Agronomy and Soil
 Science
 University of New England
 Armidale NSW 2351
 Email: home:
 mac...@northnet.com.au

 -Original Message-
 From: R-help [mailto:r-help-boun...@r-project.org]
 On Behalf Of Christine
 Lee via R-help
 Sent: Tuesday, 18 August 2015 14:16
 To: r-help@r-pr

Re: [R] date format in xyplot

2015-08-18 Thread Duncan Mackay
Hi Christine

If somethings go wrong:
1 first check your data

str(Raw)
'data.frame':   10 obs. of  5 variables:
 $ Date   : Factor w/ 16 levels "1/10","1/11",..: 6 7 2 4 12 9 7 2 4 12
 $ Year   : int  2002 2002 2002 2002 2002 2002 2002 2002 2002 2002
 $ Station: Factor w/ 4 levels "E","F","H","I": 1 1 1 1 1 2 2 2 2 2
 $ Abun   : num  3.42 1.33 3.67 3.67 3.92 2.17 2.5 1.67 6.33 0.67
 $ Date1  : Date, format: "2015-09-19" "2015-10-02" "2015-11-01"
"2015-11-12" ...

Raw$Date2 <- as.character(Raw$Date1)
Raw$Date2
[1] "2015-09-19" "2015-10-02" "2015-11-01" "2015-11-12" "2015-11-29"
"2015-09-20" "2015-10-02" "2015-11-01" "2015-11-12" "2015-11-29"
Raw$Date2 <- as.Date(Raw$Date2, "%Y-%m-%d")

2 read the help guide again if not done recently ?lattice::xyplot or ?xyplot
3 start with a minimum number of arguments

xyplot(Abun~Date2|as.factor(Year), Raw)
or 
xyplot(Abun~Date2, Raw)
if you are still having problems

Dates are hard work in any language as they are not consistent so:
a.  use  default
b.  use your own 

This works

xyplot(Abun~Date2|as.factor(Year), Raw,
   par.settings = list(stripbackground = "transparent"), # background
colour controlled here
   type="p",
   scales = list(x = list(at = sort(c(seq(as.Date(Raw$Date2[1]-4), by =
"months", length = 4),
   seq(as.Date(Raw$Date2[1]+12), by
= "months", length = 3))),
   labels =
format(sort(c(seq(as.Date(Raw$Date2[1]-4), by = "months", length = 4),
 
seq(as.Date(Raw$Date2[1]+12), by = "months", length = 3))), "%m-%d") ) ),
   xlab=list("Month",cex=1.5),
   ylab=list("Abundance",cex=1.5),
   cex=2,
   pch=c(16,16,21),
   col=c("Black","Grey","Black")
)

par.settings is confining the parameters set by trellis.par.set()  to the
function
to get them

names(trellis.par.get() )
and going further
trellis.par.get()$superpose.symbol
will give you the values for superpose.symbol

Beware: Do not make the labels etc so big that the axis labels are hard to
read. Think of final size

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Christine
Lee via R-help
Sent: Tuesday, 18 August 2015 14:16
To: r-help@r-project.org
Subject: [R] date format in xyplot

To whom it may concern,

I have tried to plot some numbers against time with the time on the X-axis
shown as "Jan", "Feb", etc.

I used the following commands:
Raw<-structure(list(Date = structure(c(6L, 7L, 2L, 4L, 12L, 9L, 7L, 
2L, 4L, 12L), .Label = c("1/10", "1/11", "11/11", "12/11", "13/10", 
"19/9", "2/10", "2/11", "20/9", "26/11", "29/10", "29/11", "30/11", 
"31/10", "4/10", "6/10"), class = "factor"), Year = c(2002L, 
2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L, 2002L
), Station = structure(c(1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
2L), .Label = c("E", "F", "H", "I"), class = "factor"), Abun = c(3.42, 
1.33, 3.67, 3.67, 3.92, 2.17, 2.5, 1.67, 6.33, 0.67), Date1 =
structure(c(16697, 
16710, 16740, 16751, 16768, 16698, 16710, 16740, 16751, 16768
), class = "Date")), .Names = c("Date", "Year", "Station", "Abun", 
"Date1"), row.names = c(NA, 10L), class = "data.frame")

Raw$Date1<-as.Date(Raw$Date,"%d/%m")
xyplot(Abun~Date1|as.factor(Year),Raw,type="p",xlab=list("Month",cex=1.5),yl
ab=list("Abundance",cex=1.5),cex=2,pch=c(16,16,21),col=c("Black","Grey","Bla
ck"),strip=strip.custom(bg='white'),format="%B-%d")

The date format shown on X-axis was just "10-1", "10-15"

I should be grateful if any one could help indicating what has gone wrong?

Regards,
Christine

__
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-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] Lattice: raw data and prediction of a non linear fitted function

2015-08-05 Thread Duncan Mackay
Sending again as I pressed the wrong button

Hi

Your model is overfitted for the number of points - the fitted values bear
no resemblance to a line fitting the data - ?too many x values to properly
predict
? splines etc
 library(locfit)
?locfit
If you want coefs of sort.

You have to do a nls on each group to get the values. 
You have 2 ways to do this 
1 do nls and predict y values separately as below an plot them in a panel
function
2 do nls and predict within the panel function 

> res_nlsA <-
+ nls(y ~ SSgompertz(time, Asym = 100, b2, b3), data = subset(foo, char ==
"A"),
+ start = list( b2 = c(7,7), b3 = c(0.9, 0.9)))
There were 50 or more warnings (use warnings() to see the first 50)
> res_nlsA
Nonlinear regression model
  model: y ~ SSgompertz(time, Asym = 100, b2, b3)
   data: subset(foo, char == "A")
   b21b22b31b32 
4.6761 7.6280 0.9111 0.9000 
 residual sum-of-squares: 10.59

Number of iterations to convergence: 32 
Achieved convergence tolerance: 8.001e-06
> res_nlsB <-
+ nls(y ~ SSgompertz(time, Asym = 100, b2, b3), data = subset(foo, char ==
"B"),
+ start = list( b2 = c(7,7), b3 = c(0.9, 0.9)))
> res_nlsB
Nonlinear regression model
  model: y ~ SSgompertz(time, Asym = 100, b2, b3)
   data: subset(foo, char == "B")
b21 b22 b31 b32 
 9.5231 86.6421  0.8164  0.6582 
 residual sum-of-squares: 36.26

Number of iterations to convergence: 10 
Achieved convergence tolerance: 1.37e-06
> 
> predict(res_nlsB, newdata = list(time = seq(5,60,2.5)))
 [1]   3.162527   2.321040  28.575719  62.814774  63.489626  94.416582
84.809570  99.292612  94.199502  99.912322  97.856129  99.989162  99.217093
99.998661  99.715346
[16]  99.999835  99.896669  99.80  99.962512  99.97  99.986402
100.00  99.995068
Warning messages:
1: In b3^x :
  longer object length is not a multiple of shorter object length
2: In -b2 * .expr2 :
  longer object length is not a multiple of shorter object length
> predict(res_nlsB, newdata = list(time = seq(5,60,5)))
 [1]   3.162527  26.638924  63.489626  98.000694  94.199502  99.969171
99.217093  99.999529  99.896669  99.93  99.986402 100.00
> predict(res_nlsA, newdata = list(time = seq(0,55,5)))
 [1]  0.9314904  1.1062577 15.8281748 20.7951276 48.3512870 57.8358643
75.0914782 82.6202586 89.3216331 93.5601696 95.6459638 97.7058236

xyplot(y ~ time, data = foo,
   groups = char,
   panel = panel.superpose,
   panel.groups = function(x, y, ...,group.number){
   
 panel.xyplot(x,y, ...);

 xy.nls <-
 nls(y ~ SSgompertz(x, Asym = 100, b2, b3),
 start = list( b2 =7, b3 =  0.9))

 #print(summary(xy.nls))
 
 if (group.number == 1){
   xy.pre <- predict(xy.nls, newdata = list(time =
seq(0,55,5)))
   print(xy.pre)
   llines( seq(5,60,5), xy.pre, col = "blue")
 } else {
   xy.pre <- predict(xy.nls, newdata = list(time =
seq(5,60,5)))
   print(xy.pre)
   llines( seq(5,60,5), xy.pre, col = "magenta")
 }
   
   })

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of François
Collin
Sent: Wednesday, 5 August 2015 22:24
To: r-help@r-project.org
Subject: [R] Lattice: raw data and prediction of a non linear fitted
function

Dear all,

I have a question about lattice use. I would like to use it to represent:
- my raw data as points,
- and the results of a non linear fit as a line,
- having 2 groups data (and so 2 colors).

However, as I have few raw data, I would like to increase the number of
points to smooth the line which correspond to the fit.

So my questions are:
- How can I use the group argument to make new predictions inside panel
argument ?
- How can I use this prediction inside the panel argument to draw the fit
per group?

Hereafter a minimal example:

#==
library(lattice)
set.seed(2)

# Dummy dataframe
foo <- data.frame(
  time = seq(0, 60, 5),
  char = sample(c("A", "B"), size = 13, replace = TRUE)
  );

# Simulated response vector according a Gompertz function + rnorn(0, 5)
foo$y <- SSgompertz(foo$time, Asym = 100, b2 = ifelse(foo$char == 'A', 6,
10),
  b3 = ifelse(foo$char == "A", .91, .8)) +
  rnorm(nrow(foo), mean=0, sd = 5);

# Non-linear fit on simulation data
res_nls <-  nls(
  y ~ SSgompertz(time, Asym = 100, b2[char], b3[char]), data = foo,
  start = list( b2 = c(7,7), b3 = c(0.9, 0.9)));

# My problem
xyplot(y ~ time, groups = char, data = foo,
  panel = function(x, y,

Re: [R] Using latticeExtra as.layer function with different number of plot panels

2015-07-30 Thread Duncan Mackay

David has replied

But I am wondering if the lattice function make.groups is what you  want.
As you seem to want extra panels.
For the 3 graphs I get the 4 same panels NC W NE S and coloured points are
added after foo but bar2 has more red points added
bar1 and bar2 have the same colour for pch

I'm not upto date with some of the latticeExtra functions so cannot really
comment otherwise.

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au
  
-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of sbihorel
Sent: Friday, 31 July 2015 01:38
To: r-help@r-project.org
Subject: [R] Using latticeExtra as.layer function with different number of
plot panels

Hi,

When the as.layer function is used to overaly 2 lattice plots, there 
seems to be an assumption that the data used in both plots will generate 
the same number of panels (and, I believe, in the same order). In case 
the data used in the plot within the as.layer call is incomplete , data 
may be plotted on the "wrong" panel, and data seem to get re-used on the 
last panel(s). See what happens in the example code below when the 
records with state.region=="South" are dropped...

Is there a trick to overlay panel based upon the conditioning variable 
value rather than the panel order?

require(lattice)
require(latticeExtra)
state2 <- state <- data.frame(state.x77,state.region)
state2$Income <- sample(state2$Income)
state3 <- state2[which(state2$state.region!="South"),]
foo <- xyplot(Income~Population|state.region,data=state,main='foo')
foo

bar <- update(foo,main='bar') + 
as.layer(xyplot(Income~Population|state.region,data=state2,col='red'))
bar

bar2 <- update(foo,main='bar2') + 
as.layer(xyplot(Income~Population|state.region,data=state3,col='red'))
bar2

Thank you

Sebastien

PS: I know that I could get what I want by setting the Income variable 
to NA for records with state.region=="South" instead of dropping them... 
but this is not the point of my example. I am just trying to illustrate 
what happens when as.layer is used for plotting data with inconsistent 
dimensions.

__
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-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] Mixed Date Formats

2015-07-29 Thread Duncan Mackay
Hi

I wonder if it is easier to convert the dates to character format and then 
reformat using gsub or the like

str(SampleData)
SampleData$date <- as.character(SampleData$date)
str(SampleData)

as.Date(
ifelse(nchar(SampleData[,"date"]) == 9, as.Date(SampleData[,"date"], format = 
"%d-%b-%y"),
   ifelse(nchar(SampleData[,"date"]) == 8, as.Date(SampleData[,"date"], 
format = "%d/%m/%y"),
  ifelse(as.numeric(substr(SampleData[,"date"],1,2)) > 12,
  as.Date(SampleData[,"date"], format =  "%d/%m/%Y"),
  as.Date(SampleData[,"date"], format =  "%m/%d/%Y")) )), 
origin = as.Date("1970-01-01"))

Beware of the American format in months jan feb mar oct nov -- will need more 
conditions to be imposed

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of farnoosh 
sheikhi via R-help
Sent: Thursday, 30 July 2015 07:16
To: Sarah Goslee
Cc: R. Help
Subject: Re: [R] Mixed Date Formats

Hi Sarah,
Thanks for getting back to me.Here is an example of my data:SampleData <- 
structure(list(id = 1:7, value = c(5813L, 8706L, 4049L, 5877L,  
1375L, 2223L, 3423L), date = structure(c(4L, 3L, 
2L, 1L, 7L, 
  6L, 5L), .Label = c("05/12/11", "06/05/11", "07-Dec-11",  

 "19-Dec-11", "01/22/2011", "10/19/2011", "31/12/2011"  

), class = "factor")), .Names = c("id", "value", "date"), row.names = c(NA, 

  -7L), 
class = "data.frame")SampleData
Thanks for your help:).
 
 


 On Wednesday, July 29, 2015 1:50 PM, Sarah Goslee  
wrote:
   

 On Wed, Jul 29, 2015 at 2:45 PM, farnoosh sheikhi via R-help
 wrote:
>  Hi Arun,
> Hope all is well with you. I have a data with a column for date.The date 
> format is mixed. There are date values with Month/Day/Year format and values 
> with Day/Month/Year format.I don't know how to unify it.I really appreciate 
> your help.Thanks.

You sent this to the R-help list, not just to Arun, so I'm assuming
this is an R question. The best way to get help is to provide a sample
of your data using dput() and to clearly specify what you would like
as the result - "unify" is a bit vague. paste(x, collapse="") could be
considered unification, after all.

Sarah

-- 
Sarah Goslee
http://www.functionaldiversity.org


  
[[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-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] Opposite color in R

2015-07-28 Thread Duncan Mackay
Hi

I plotted the 'spectrum' and it looked a little small - spectrum colours: red 
orange yellow green blue indigo violet.
I suppose you could go to infinite lengths to split it up but is this an 
improvement?

I have not gone into the "depths" of complimentary colours

library(colorspace)

ColorsRYB=rbind(colorRamp(c("purple","violet"))((0:4)/4)[1:4,],
colorRamp(c("violet","blue"))((0:4)/4)[1:4,],
colorRamp(c("blue","green"))((0:4)/4)[1:4,],
colorRamp(c("green","yellow"))((0:4)/4)[1:4,],
colorRamp(c("yellow","orange"))((0:4)/4)[1:4,],
colorRamp(c("orange","red"))((0:4)/4)[1:4,],
colorRamp(c("red","purple"))((0:4)/4)[1:4,])

LenCol=length(ColorsRYB[,1])

ColorsRYBhex=rep(0, LenCol)
for(i in 1: LenCol)
{
ColorsRYBhex[i]=rgb(ColorsRYB[i,1]/255,ColorsRYB[i,2]/255,ColorsRYB[i,3]/255)
}

pie(rep(1, LenCol), col = ColorsRYBhex)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au




-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Atte Tenkanen
Sent: Tuesday, 28 July 2015 18:22
To: r-help@r-project.org
Subject: [R] Opposite color in R

It seems that there is no implementation for the "traditional artist's 
color circle" in R. However I'm searching for such a wheel, because my 
program needs it.

As said, the description of complementary/opposite-function in package 
"colortools" is misleading since, for example

opposite("green") produces violet, not red, but the description of 
complementary-function says

"Complementary or opposite color scheme is formed by colors that are 
opposite each other on the color wheel (example: red and green)."

So, there must be just a lapse in the text.

I "constrained" such kind of a color wheel, which is enough near of what 
I need:

library(colorspace)

ColorsRYB=rbind(colorRamp(c("red", 
"violet"))((0:4)/4)[1:4,],colorRamp(c("violet", 
"blue"))((0:4)/4)[1:4,],colorRamp(c("blue", 
"green"))((0:4)/4)[1:4,],colorRamp(c("green", 
"yellow"))((0:4)/4)[1:4,],colorRamp(c("yellow", 
"orange"))((0:4)/4)[1:4,],colorRamp(c("orange", "red"))((0:4)/4)[1:4,])

LenCol=length(ColorsRYB[,1])

ColorsRYBhex=rep(0, LenCol)
for(i in 1: LenCol)
{
ColorsRYBhex[i]=rgb(ColorsRYB[i,1]/255,ColorsRYB[i,2]/255,ColorsRYB[i,3]/255)
}

pie(rep(1, 24), col = ColorsRYBhex)

Atte T.


28.7.2015, 2.23, Steve Taylor kirjoitti:
> I wonder if the hcl colour space is useful?  Varying hue while keeping chroma 
> and luminosity constant should give varying colours of perceptually the same 
> "colourness" and brightness.
>
> ?hcl
> pie(rep(1,12),col=hcl((1:12)*30,c=70),border=NA)
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Atte Tenkanen
> Sent: Sunday, 26 July 2015 7:50a
> To: r-help@r-project.org
> Subject: [R] Opposite color in R
>
> Hi,
>
> I have tried to find a way to find opposite or complementary colors in R.
>
> I would like to form a color circle with R like this one:
> http://nobetty.net/dandls/colorwheel/complementary_colors.jpg
>
> If you just make a basic color wheel in R, the colors do not form
> complementary color circle:
>
> palette(rainbow(24))
> Colors=palette()
> pie(rep(1, 24), col = Colors)
>
> There is a package ”colortools” where you can find function opposite(),
> but it doesn’t work as is said. I tried
>
> library(colortools)
> opposite("violet") and got green instead of yellow and
>
> opposite("blue") and got yellow instead of orange.
>
> Do you know any solutions?
>
> Atte Tenkanen
>
> __
> 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-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-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] plot auto key and text into panels using lattice

2015-07-21 Thread Duncan Mackay
, gp = gpar(cex = 0.3))
   }
)

panel.number() used on its own can play up sometimes
better to save the value and use it.

If you are having problems start from the beginning with a minimal script eg

xyplot(min.temp + max.temp ~ day, data = SeatacWeather,
as.table = T,
   layout = ...,
  groups = ...)

and build up from there. Its amazing what you find out.

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au





-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Tuesday, 21 July 2015 08:39
To: r-help
Subject: [R] plot auto key and text into panels using lattice

Dear all,
I am writing some text into several panels which I can do with this
script (in capital the variables):
xyplot(Y ~ X | Z,
   data = DATAFRAME,
   groups = Z,
   ylab= "Y",
   xlab="X",
   main="TITLE",
   scales = list(
   x = list(draw = FALSE),
   y = list(draw = FALSE),
   relation="same",
   alternating=TRUE),
   as.table = TRUE,
   layout = LAYOUT,
   par.settings = list(
   strip.background=list(col="white"),
   axis.text = list(cex = 0.6),
   par.xlab.text = list(cex = 0.75),
   par.ylab.text = list(cex = 0.75),
   par.main.text = list(cex = 0.8),
   superpose.symbol = list(pch = ".", cex = 1)
   ),
   strip= FALSE,
   type = "l",
   col = 3,
   panel = function(x, y,...) {
   panel.xyplot(x,y,...)
   panel.text(MIN.X+(0.1*MAX.X),
  MAX.Y-(0.1*MAX.Y),
  labels=LABELS[panel.number()],
  cex=0.3
  )
   }
)

A similar plot also add the autokey because it takes in account two
different Y values, but the plot is not drawn rather the function is
implemented but the plot remains empty:
xyplot(Y1+Y2 ~ X | Z,
   data = DATAFRAME,
   ylab= "Y",
   xlab="X",
   main="TITLE",
   scales = list(
   x = list(draw = FALSE),
   y = list(draw = FALSE),
   relation="same",
   alternating=TRUE),
   as.table = TRUE,
   layout = LAYOUT,
   auto.key= list(space = "centre"),
   par.settings = list(
   strip.background=list(col="white"),
   axis.text = list(cex = 0.6),
   par.xlab.text = list(cex = 0.75),
   par.ylab.text = list(cex = 0.75),
   par.main.text = list(cex = 0.8),
   superpose.symbol = list(pch = ".", cex = 1)
   ),
   strip= FALSE,
   type = "l",
   col =  c(4,2),
   key = list(
   space="top", columns=2,
   text=list(TEXT_FOR_AUTOKEY, col="black"),
   lines=list(col=c(4,2)),
   panel = panel.superpose
),
   panel = function(x, y,...)
   {
   panel.xyplot(x,y,...)
   panel.text(MIN.X+(0.1*MAX.X),
  MAX.Y-(0.1*MAX.Y),
  labels=LAB[panel.number()],
  cex=0.3,
  panel = panel.superpose
  )

   }
)


I am not attaching actual data because I believe the problem is in the
actual call, maybe I am using twice panel.superimpose, although
several combination I made (for instance moving the key argument into
the panel function) did not solve the problem.
Could you tell me where I am getting it wrong?
Thank you.
best regards
Luigi

__
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-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] (ordinal) logistic regression

2015-07-16 Thread Duncan Mackay
Hi 
your example is not reproducible. With ordinal regression the type of the y 
values is important
sometimes an ordered factor is required.

Ordinal regression depends on your hypothesis see Ananth and Kleinbaum 1997

functions/packages to look at apart from ordinal
VGAM
polr::MASS
bayespolr::arm
lrm::rms

if you want to do GEE that is another matter.

Regards

Duncan 

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au





-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Wolfgang 
Raffelsberger
Sent: Friday, 17 July 2015 03:41
To: r-help@r-project.org
Subject: [R] (ordinal) logistic regression

Dear list,
I've been looking at previous posts on the list, but I haven't found any
close enough to my question/problem.
My data can be seen as a matrix of mutiple individuals (columns) with
(rather independent) measures (lines). Now based on supplemental
information, the individuals are organized in (multiple) ordered classes.
Now I would like to test for which type of measure (ie which line form my
matrix of data) the groups are distinct (eg different by group-mean). In
other words, I would like to see in which line of my input matrix the
measures for the groups of individuals associate to distinct group-values.

So I tried glm (or glm2) on each line of the matrix, but in my toy-example
(shown below) I'm surprised to get warnings about not finding convergence
in the "nice" toy-cases (ie distinct groups as I am looking for),e even
with glm2 ! I see in such "nice" cases with glm() the "Pr(>|z|)" is close
to 1, which in first sight is OK (since: H0 : coefficient =0), but I
suppose the test is not really set up right this way.  When trying lrm (rms
package) I even get an error message (Unable to fit model using “lrm.fit”)
with the "nice" cases.
In my real data with >4000 lines of data (ie >4000 glm tests) multiple
testing correction would transform everything from 1-p to end up at p=1, so
that’s another problem with this approach.
I suppose somehow I should transform my data (I don't see where I would
change the H0 ?) to obtain low and NOT high p-values (example below) in the
case I'm looking for, ie when group-means are distinct.

Any suggestions ?

Thank’s in advance,
Wolfgang

Here my toy-example :
datB1 <- c(12,14:16,18:21,20:22,20,22:24,19.5)   # fit
partially/overlapping to 3grp model
datB2 <- c(11:15,21:25,31:36)# too beautiful to be real
...
datB3 <- c(15:12,11:15,12:14,15:12)  # no fit to 3grp model
datB4 <- c(11:15,15:11,21:26)# grpA == grpB but grpA !=
grpC

datB <- rbind(datB1,datB2,datB3,datB4)
set.seed(2015)
datB <- datB + round(runif(length(datB),-0.3,0.3),1)  # add some noise
datB <- datB - rowMeans(datB) # centering
## here the definition of the groups
grpB <- gl(3,6,labels=LETTERS[1:3])[c(-6,-7)]
   table(grpB)

## display
layout(1:4)
for(i in 1:4) plot(datB[i,],as.numeric(grpB))

## now the 'test'
glmLi <- function(dat,grp) {
  ## run glm : predict grp based on dat
  dat <- data.frame(dat=dat,grp=grp)
  glm(grp ~ dat, data=dat, family="binomial")}

logitB <- apply(datB,1,glmLi,grpB)
lapply(logitB,summary)
sapply(logitB,function(x) summary(x)$coefficients[,4])  # lines 1 & 2 are
designed to be 'positive' but give high p-values with convergence problem

## for completness
sessionInfo()
R version 3.2.0 (2015-04-16)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=French_France.1252  LC_CTYPE=French_France.1252
LC_MONETARY=French_France.1252
[4] LC_NUMERIC=C   LC_TIME=French_France.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base

other attached packages:
[1] glm2_1.1.2  MASS_7.3-40 TinnRcom_1.0.18 formatR_1.2
svSocket_0.9-57

loaded via a namespace (and not attached):
[1] tools_3.2.0   svMisc_0.9-70 tcltk_3.2.0

[[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-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] add outer strip for levels in lattice plot (useOuterStrips alternative for Lattice)

2015-07-08 Thread Duncan Mackay
Hi Luigi

str(my.data)
'data.frame':   540 obs. of  4 variables:
 $ Line  : chr  "1" "2" "3" "4" ...
 $ Well  : chr  "1" "1" "1" "1" ...
 $ Target: chr  "alpha" "alpha" "alpha" "alpha" ...
 $ Rn: chr  "0.728" "0.735" "0.749" "0.758" ...

You didnot create the data.frame properly

mydata <-
data.frame(Line=Line, Well=Well, Target=Target, Rn=Rn,Cycle= Cycle)
str(mydata)
'data.frame':   540 obs. of  4 variables:
 $ Line  : num  1 2 3 4 5 6 7 8 9 10 ...
 $ Well  : num  1 1 1 1 1 1 1 1 1 1 ...
 $ Target: chr  "alpha" "alpha" "alpha" "alpha" ...
 $ Rn: num  0.728 0.735 0.749 0.758 0.77 0.778 0.78 0.784 0.786 0.785 ...

I was having problems with your script so I started with the basics (before I 
found the problem with the df)

xyplot(Rn ~ Cycle | sprintf("%2d",Well), data = mydata,
   as.table = TRUE,
   layout = c(6,2),
   groups = Well)

You are not splitting up the data with groups being the same as the 
conditioning.
It can be necessary to use this setup in some cases but not this.

latticeExtra is on Cran so you can use install.packages("latticeExtra") or use 
the menu
I have never heard of lattice_Extra


mydata$rown <- ifelse(mydata$Well>6,2,1)
mydata$welln <- rep(1:6, 2)[sapply(mydata$Well, pmatch, 1:12)]


useOuterStrips(strip  = strip.custom(factor.levels = paste("column",1:6),
 par.strip.text = list(cex = 0.75)),
   strip.left = strip.custom(factor.levels = paste("row", 1:2),
 horizontal = FALSE,
 par.strip.text = list(cex = 0.75)),

xyplot(Rn ~ Cycle | welln*rown, data = mydata,
   as.table = TRUE,
   layout = c(6,2)
  )

) ## useOuterStrips

  ps.Colours <-
  c("#00","#FF","#00FF00","#FF","#FFA54F",
"#00","#FF00FF","#C0","#00B414","#FFD18F",
"#00B2EE","#ffe5cc","#6A5ACD","#C0C0C0","#CC",
"#6495ED","#FFFAFA")



useOuterStrips(strip  = strip.custom(factor.levels = paste("column",1:6),
 par.strip.text = list(cex = 0.75)),
   strip.left = strip.custom(factor.levels = paste("row", 1:2),
     horizontal = FALSE,
 par.strip.text = list(cex = 0.75)),

xyplot(Rn ~ Cycle | welln*rown, data = mydata,
   as.table = TRUE,
   groups = Well,
   col = ps.Colours,
   layout = c(6,2)
  )

) ## useOuterStrips

Duncan

-Original Message-
From: Luigi Marongiu [mailto:marongiu.lu...@gmail.com] 
Sent: Thursday, 9 July 2015 09:22
To: Duncan Mackay; Dennis Murphy; r-help
Subject: Re: [R] add outer strip for levels in lattice plot (useOuterStrips 
alternative for Lattice)

In relation to this question I have prepared a workable example. First
I prepare a dataframe with three variables (Cycle, Target, Rn), then I
plot the results with lattice's xyplot(). I won't use the scales but
only the labels and the panels are NOT indicated by the variable Well.
What I would need to use are instead the vectors row.name and col.name
that can identify each column and row of the plot.
Secondly I create replicates of the row.name and col.name in order to
fit the data and create a second dataframe, then I plot using lattice
extra's useOuterStrips().
However (a) I think the call is wrong anyway, (b) I obtain "Error:
length(dimx) == 2 is not TRUE" (c) I need a package on top of lattice
(d) I might introduce errors during the creation of the second
dataframe.
The requirements remains to create a strip on the top and left side of
the plot to allocate the elements of row.name and col.name possibly
using lattice only.
Thank you for your help.
Luigi

>>>
Line<-c(1,2,3,4,5,6,7,8,9,10,
  11,12,13,14,15,16,17,18,19,20,
 21,22,23,24,25,26,27,28,29,30,
31,32,33,34,35,36,37,38,39,40,
41,42,43,44,45,46,47,48,49,50,
51,52,53,54,55,56,57,58,59,60,
61,62,63,64,65,66,67,68,69,70,
71,72,73,74,75,76,77,78,79,80,
81,82,83,84,85,86,87,88,89,90,
91,92,93,94,95,96,97,98,99,100,
101,102,

Re: [R] add outer strip for levels in lattice plot (useOuterStrips alternative for Lattice)

2015-07-06 Thread Duncan Mackay
Hi Luigi

Not exactly sure what you want

Have a look at 
https://stat.ethz.ch/pipermail/r-help/2007-May/132785.html
and
https://stat.ethz.ch/pipermail/r-help/2007-July/135551.html

otherwise have a look at ?trellis.focus and
https://stat.ethz.ch/pipermail/r-help/2006-July/109585.html

failing that ?gridRect and ?gridText from library(grid)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Luigi
Marongiu
Sent: Monday, 6 July 2015 09:56
To: r-help
Subject: [R] add outer strip for levels in lattice plot (useOuterStrips
alternative for Lattice)

Dear all,
I would like to add an outer strip or something like that on a lattice
plot I am making. Such plot contains 384 cells and, since I am not
interested in the axis values, I set:
   scales = list(
   x = list(draw = FALSE),
   y = list(draw = FALSE),
   relation="same"
   ),
on a xyplot from the LATTICE package.
Nevertheless there are axis labels which run like:
   ylab= "Y axis",
   xlab= "X axis",
I would like to place some more information regarding the individual
cells thus I would like to draw a sort of extra axis labels that are
similar to the outer strip of the LATTICE_EXTRA package, that is
markers placed between the axis labels and the axis values and
centered for each cells, typically placed on the top and left sides of
the plot. This is performed by the useOuterStrips function but:
a) LatticeExtra is not in the CRAN repository thus I have to install
it through a more laborious approach which makes LatticeExtra less
direct than Lattice
b)  useOuterStrips uses information directly from the data whereas I
will have to provide the extra information from ad hoc vectors not
present in the data set.

The question therefore is: is there a way to write text from a vector
in the top and left corners of a lattice xyplot and place the
individual elements at the centre of the rows and columns that compose
the graph?

Many thanks,
Luigi

__
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-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] Lattice: set col = "black" for box.rectangle and box.umbrella

2015-07-03 Thread Duncan Mackay
Rich

Just a thought
Have you set pch colour values somewhere else?
see also https://stat.ethz.ch/pipermail/r-help/2010-March/230329.html

Duncan

-Original Message-
From: rshep...@localhost.appl-ecosys.com
[mailto:rshep...@localhost.appl-ecosys.com] On Behalf Of Rich Shepard
Sent: Saturday, 4 July 2015 01:58
To: Duncan Mackay
Subject: Re: [R] Lattice: set col = "black" for box.rectangle and
box.umbrella

On Fri, 3 Jul 2015, Duncan Mackay wrote:

> My settings are
>
>   par.settings = list(fontsize = list(text = 10.5,
>   points = 8),
>   strip.background = list(col = "transparent"),
>   box.dot = list(col = "#FF", # red

Duncan,

   This is interesting: the color of the horizontal line remains black,
rather than displaying in red whether I use the numeric code or the word. I
need to explore why.

Thanks again,

Rich

-- 
Richard B. Shepard, Ph.D.
Applied Ecosystem Services, Inc.   Troutdale, OR 97060 USA
www[dot]appl-ecosys[dot]com   Voice: 503-667-4517Fax: 503-667-8863

__
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] Lattice: set col = "black" for box.rectangle and box.umbrella

2015-07-02 Thread Duncan Mackay
Hi

I usually avoid global settings as they may change between graphs therefore
I use the par.settings in each plot

My settings are

   par.settings = list(fontsize = list(text = 10.5,
   points = 8),
   strip.background = list(col = "transparent"),
   box.dot = list(col = "#FF", # red
  pch = "|"),
   box.rectangle = list(col = "#00",
lty = 1),
   box.umbrella = list(col = "#00",
   lty = 1),
   plot.symbol = list(alpha = 1,
  col = "#00",
  cex = 0.7,
  pch = 20)
  ),

This gives a red line instead of the large dot: it avoids "bulls-eyes"
across the panel when there are a lot of factors

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rich Shepard
Sent: Friday, 3 July 2015 04:52
To: r-help@r-project.org
Subject: Re: [R] Lattice: set col = "black" for box.rectangle and
box.umbrella

On Thu, 2 Jul 2015, Bert Gunter wrote:

> 1. box.rectangle, etc. are not functions;  they are (lists of)
> parameters that are sublists of the par.settings list.

Bert,

   Thought so ...

> 2. Read the Help for simpleTheme() -- it has a specific list of
> parameters which is nothing like what you show.

   found the simpleTheme example on a web forum thread. Mea culpa! Will read
the help page. Still desire to have the changes set in .Rprofile rather than
for each plot.

Thanks,

Rich

__
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-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] R lattice : labeling of matrix groups of different size with strips

2015-06-25 Thread Duncan Mackay
I am not sure that changing the aspect ratio by using 
levelplot(plotMatrix[,,2],
 aspect = 1/0.6,
 ...)

will do the job as I seem to remember doing something like that when first 
looking at your problem. There were unwanted side effects

using grid.arrange is the quick way to fill the plot area, I rarely use it

You may be better off by using print - I have not got your original data so I 
can only guess
eg

print(plot2, position = c(0.2,0,0.8,0.5), more = TRUE)
print(plot1 position = c(0,0.5,1.1), more = FALSE)

You may have to fiddle with the position values for plot2 to get it right.

If the text of plot2 is too small then you could put a line in to get plot2
par.settings = list(fontsize = list(text = 12.5, points = 8)),  
this is device dependent and you may need to change it

 Regards

Duncan


-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of R codeplayer
Sent: Thursday, 25 June 2015 21:01
To: r-help@r-project.org
Subject: Re: [R] R lattice : labeling of matrix groups of different size with 
strips

Hi Duncan,


thank you very much for your help.


Originally, I thought that it is possible to use a different data
representation and then to automatically create the plots and strips
in lattice.

Based on your suggestion, I could write the code for an annotated
levelplot of the two groups (code is shown below).

An open question is how to display the two groups with the same aspect
ratio for the rows.


> plotMatrix
> , , group1
>
>   a b c d
> 1 1 0 0 0
> 2 1 0 0 0
> 3 1 1 0 0
> 4 0 1 0 0
> 5 0 1 1 0
>
> , , group2
>
>a  b  c  d
> 1  0  0  1  0
> 2  0  0  1  1
> 3  0  0  0  1
> 4 NA NA NA NA
> 5 NA NA NA NA

library(gridExtra)

trellis.device(device = "pdf",file
="lattice_annotated_groups.pdf",width=8,height=5)

#The aspect="fill" option was added to coerce the same height of the 2 plots
#panel.text was used instead of grid.text to avoid using the
latticeExtra package

plot1 <- levelplot(plotMatrix[,,1],
 page = function(n)
 panel.text("group 1",
 x = 0.5,
 y = 0.96),
 colorkey = F,
 xlab = "",
 ylab="",
 aspect="fill")

pm <- plotMatrix[1:3,,2]
colnames(pm) <- rep("",ncol(pm))

plot2 <-levelplot(pm,
page = function(n)
panel.text(
"group 2",
 x = 0.5,
 y = 0.96),
colorkey = F,
xlab = "",
ylab="",
aspect="fill")


grid.arrange(plot1,plot2,ncol=2)
dev.off()

__
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] R lattice : labeling of matrix groups of different size with strips

2015-06-24 Thread Duncan Mackay
Hi

I am not sure what you want

plotMatrix
, , group1

  a b c d
1 1 0 0 0
2 1 0 0 0
3 1 1 0 0
4 0 1 0 0
5 0 1 1 0

, , group2

   a  b  c  d
1  0  0  1  0
2  0  0  1  1
3  0  0  0  1
4 NA NA NA NA
5 NA NA NA NA

If you do not want to show the NA's without giving them a different colour then 
here is a cludgy way of doing things

print(
levelplot(plotMatrix[1:3,,2],
  page = function(n){
   grid.text(paste("group2"),
 x = 0.5,
 y = 0.96,
 default.units = "npc",
 just = c("left", "bottom"),
 gp = gpar(fontsize = 12) )
  },
  colorkey = F,
  xlab = "",
  ylab=""),
position = c(0.2,0,0.8,0.5), more = TRUE)
print(
levelplot(plotMatrix[,,1],
  page = function(n){
   grid.text(paste("group1"),
 x = 0.5,
 y = 0.96,
 default.units = "npc",
 just = c("left", "bottom"),
 gp = gpar(fontsize = 12) )
  },
  colorkey = F,
  xlab = "",
 ylab=""),
position = c(0,0.5,1,1), more = FALSE)

It will depend on your device so you will have to amend the position settings 
of group n and size of plots.

using the page argument saves having to do a panel function 

If you wanted to have the strip that is a different matter

Regards

Duncan

PS Does this suit?

library(latticeExtra)
c(levelplot(plotMatrix[,,1],colorkey=F,xlab="",ylab=""),levelplot(plotMatrix[1:3,,2],colorkey=F,xlab="",ylab=""))

just using the defaults. have not got time to explore further
you may have to annotate groups by grid.text  with or without trellis.focus

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au 
 



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of R codeplayer
Sent: Wednesday, 24 June 2015 23:10
To: r-help@r-project.org
Subject: [R] R lattice : labeling of matrix groups of different size with strips

In R lattice, I am trying to label predefined groups of rows in a
matrix of data with strips. Currently, the length of the strips fail
to match the different sizes of the groups as the data representation
only allows groups with the same size.

One possibility to solve this might be to suppress the display of
NAs, but I did not find any configuration to realize
this in Lattice.

The example code below shows a matrix (m) with 8 rows and 4 columns.
Group 1 contains row 1-5 and group 2 contains row 6-8. The lattice
output is attached below the code.

Thank you for your time



library(lattice)

m <- matrix(c(1,1,1,0,0,0,0,0,
0,0,1,1,1,0,0,0,
0,0,0,0,1,1,1,0,
0,0,0,0,0,0,1,1),nrow=8,ncol=4)

group1 <- m[1:5,]
group2 <- m[6:nrow(m),]

plotMatrix <- array(dim=c(5,4,2))
dimnames(plotMatrix) <- list(rep("",5), c("a","b","c","d"),c("group1","group2"))
plotMatrix[,,1]<- group1
plotMatrix[1:3,,2] <- group2

trellis.device(device = "pdf",file ="lattice_strips.pdf",width=14,height=10)
print(levelplot(plotMatrix,colorkey=F,xlab="",ylab=""))
dev.off()

__
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] How to add legend to a dotplot

2015-06-03 Thread Duncan Mackay
Hi 
If you use the lattice package and not resort to other packages read the ?
xyplot carefully
There are several ways to put a key in the graph including auto.key if you
want something simple ie default
The examples at the bottom give some ideas

If you want something special you can use key = list(...) eg

   key  = list(text = list(labels = LETTERS[1:3],   cex  =
c(1,1,1) ),
   title = "Farm", cex.title = 1,
   points = list(pch = c(20,20,3),
 col = c("black","grey","grey")),
   lines = list(lwd = c(2,1,2),
lty = c(1,1,1),
col = c("black","black","grey80")),
space = "bottom"),
which gives 3 columns: text points and lines.

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au




-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of li li
Sent: Wednesday, 3 June 2015 13:07
To: r-help
Subject: [R] How to add legend to a dotplot

Hi all,
  I wanted to add the legend to a dotplot using legend funciton. If
does not seem to be working? Anyone have any suggestions?
  Thanks!
  Hanna

__
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-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] combine trellis lattice contour plot with simple plot() points() and text() commands?

2015-06-01 Thread Duncan Mackay
Hi Ivo

If you want to add lines, text etc you can do that by a  lattice panel
function included in it would be panel.contour

something like (untested)

contourplot(...
   panel = function(x,y, etc,...){

panel.countorplot(x,y, etc)
 
   panel.lines(x,y,...)
   panel.text()
  }
)

and see also
library(lattice)
names(trellis.par.get())
and delve into the names that come up that are applicable

See the help page

? panel.lines which should cover most of what you need.
Remember that you may have to look at 
? grid::gpar for fine tuning of the arguments

Just finished a plot with panel.segments

panel.segments(xlocs - medsbar.len, meds,
   xlocs + medsbar.len, meds,
   lineend = 1, # grid gpar call for line ending
   lwd = 5,
   col = 2)

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of ivo welch
Sent: Tuesday, 2 June 2015 07:03
To: r-help
Subject: [R] combine trellis lattice contour plot with simple plot()
points() and text() commands?

can I add ordinary graphics commands to a contourplot?  my naive
attempts are telling me that plot.new() has not yet been called when I
try to add text(1,1,"hi") or points( c(0,1), c(1,0) )?

[or do I need to rewrite another contourplot with the old graphics
system.  the basics are probably looking at adjacent points,
pretending that they are linear, and mark where a line between them
intercepts the level, and then hope that some sanity prevents me from
connecting disconnected levels.  not my plan...]


Ivo Welch (ivo.we...@gmail.com)
http://www.ivo-welch.info/

__
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-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] dotplot

2015-05-16 Thread Duncan Mackay
if this is using lattice panel.dotplot gives the clues
The vertical lines are inserted by panel abline.

You can make your own panel.dotplot function by removing panel.abline which
uses col.line for the vertical line colour
 
A quick fix is by making col.line = "transparent". If you want to add lines
this may cause trouble for you

dotplot(val ~ lot, tmp,
col.line = "transparent",
ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
pch=tmp$sybm, col=tmp$color)

Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Daniel
Nordlund
Sent: Sunday, 17 May 2015 06:45
To: r-help@r-project.org
Cc: sa...@listserv.uga.edu
Subject: Re: [R] dotplot

On 5/16/2015 1:19 PM, Daniel Nordlund wrote:
> On 5/16/2015 12:32 PM, li li wrote:
>> Hi all,
>>I wrote the following code and have two questions:
>>(1) As you can see, I would like different colors for different
>> types. It does not come out that way in the graph from this code.
>> Anyone know how to fix this?
>> (2) How do I made the lots number on x axis eligible to read?
>> (3) How do I remove the verticle line in the graph.
>>  Thanks for your help.
>>Hanna
>>
>>
>> lot <- as.character(c("D130" ,"D135" ,"D1300010", "D1300015",
>> "D1300020",
>>   "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045",
>>   "D130" ,"D135" ,"D1300010", "D1300015",  "D1300020",
>>   "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045",
>>   "D130" ,"D135" ,"D1300010", "D1300015",  "D1300020",
>>   "D1300025" ,"D1300030" ,"D1300035", "D1300040",  "D1300045"))
>>
>> val <- rnorm(30)
>> type <- rep(1:3,each=10)
>> tmp <- as.data.frame(cbind(val, type, lot))
>> tmp$sybm <- rep(c(1, 12, 16), each=10)
>> tmp$color <- rep(c("blue", "red", "green"), each=10)
>> tmp$val <- as.numeric(tmp$val)
>> dotplot(val ~ lot, tmp,
>>  ylab = "values", xlab="lot", aspect=1,
>>  pch=tmp$sybm, color=tmp$color)
>>
>
> Li Li,
>
> 1. if the dotplot function you are referring to is from the lattice
> package, then the correct name for the "color" parameter is col.  You
> could just use col=type to get different colors but you won't have
> control over the colors chosen.  I created a vector, color, specifying
> the colors and the order they will be applied.
>
> 2.  the scales parameter is what you are looking for.  The parameter is
> looking for a list which consists of name=value pairs. You can rotate
> the labels by a specified number of degrees.  In my example, I chose 30
> degrees, rot=30.
>
> 3. I don't know how to eliminate the vertical lines, but if you read the
> lattice documentation, you will find it (if it is possible).
>
> color=c("blue", "red", "green")
> dotplot(val ~ lot, tmp,
>  ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
>  pch=tmp$sybm, col=color)
>
>
> Hope this is helpful,
>
> Dan
>

I apologize; my use of the color vector was incorrect.  You could just 
use the tmp$color values with the correct color parameter name.  Like

dotplot(val ~ lot, tmp,
 ylab = "values", xlab="lot", scales=list(rot=30), aspect=1,
 pch=tmp$sybm, col=tmp$color)


Dan



-- 
Daniel Nordlund
Bothell, WA USA

__
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-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] lm model exported from R to excel

2015-05-06 Thread Duncan Mackay
At the expense of extra bandwidth. I also like latex + booktabs; hate word

I format the table header and footer in latex with extra vertical space
between lines and type; output looks more like latex than being cramped from
xtable. 
Thanks anyway to xtable creators -- would be lost without it

Duncan

-Original Message-
From: John Kane [mailto:jrkrid...@inbox.com] 
Sent: Thursday, 7 May 2015 01:34
To: Duncan Mackay; R
Subject: Re: [R] lm model exported from R to excel

And for those of us who know close to nothing about HTML I found just now
that under a basic print.xtable commmand we get those horrible HMTL borders
that in Apache OpenOffice seemed impossible to remove safely.  No idea about
Word--I have not used it in years.

I did find that adding  html.table.attributes = "border = 0" gets rid of the
borders.  So 
So something like 

print.xtable(modtable, type = "html", html.table.attributes = "border = 0",
file = "modtable .html") 
seems to give a reasonable  result in AOO.  At least I managed to do some
half-decent formatting with it.

Meanwhile, back to LaTeX where the output looks beautiful. I like booktabs
:)

John Kane
Kingston ON Canada


> -Original Message-
> From: dulca...@bigpond.com
> Sent: Thu, 7 May 2015 00:32:48 +1000
> To: r-help@r-project.org
> Subject: Re: [R] lm model exported from R to excel
> 
> If you know some basic html language you can jazz up the table headings
> to
> your liking by writing that before the xtable statement.
> It save having to muck around in Microsoft to fix it.
> If you are going to do a lot of it - a little study of html basics can go
> far.
> 
> I was changing the headings to what I wanted using html (although not all
> the tables were lm summaries) before the major upgrade a year or so ago
> Now things are better.
> 
> Even a title and comments in html for yourself if not available in xtable
> are helpful. I have not used xtable and html since the upgrade as I use
> latex
> 
> Duncan
> 
> -Original Message-
> From: Livia Maria Vestergaard [mailto:lves...@student.sdu.dk]
> Sent: Wednesday, 6 May 2015 22:37
> To: Duncan Mackay; R
> Subject: SV: [R] lm model exported from R to excel
> 
> Hi Duncan
> Thank you so much - it worked :)
> 
> Best
> 
> Livia
> 
> Fra: Duncan Mackay [dulca...@bigpond.com]
> Sendt: 6. maj 2015 14:26
> Til: R; Livia Maria Vestergaard
> Emne: RE: [R]  lm model exported from R to excel
> 
> Hi Livia
> 
> There are several html packages that ?could also do it
> 
> Heres a way with xtable
> 
> library(xtable)
> y = rnorm(100)
> x= rnorm(100)+rnorm(100)
> mod <- lm(y ~x)
> 
> # latex example easy view
> xtable(mod)
> 
> # html
> file.create("lm.htm")
> ff <- file("lm.htm", "a+")
> fchars <-  print(xtable(mod),type = "html")
> writeLines(paste(fchars, sep = ""), ff)
> close(ff)
> 
> You can then bring this into Microsoft as an html file
> 
> You may need to fill in some of the arguments in xtable to get the right
> border format etc
> 
> If you are doing many you can make a function to do things
> 
> Duncan
> 
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
> 
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Livia
> Maria
> Vestergaard
> Sent: Wednesday, 6 May 2015 19:37
> To: r-help
> Subject: [R] lm model exported from R to excel
> 
> Hi all
> I all. I am wondering whether anybody know how to export an output of an
> lm
> model from R to excel in order to have excel recognize the table that
> comes
> and divide the numbers in the table into columns and rows?
> I really hope it is possible? :)
> 
> Best Livia
> __
> 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-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.


Can't remember your password? Do you need a strong and secure password?
Use Password manager! It stores your passwords & protects your account.

__
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] lm model exported from R to excel

2015-05-06 Thread Duncan Mackay
If you know some basic html language you can jazz up the table headings to
your liking by writing that before the xtable statement.
It save having to muck around in Microsoft to fix it.
If you are going to do a lot of it - a little study of html basics can go
far.

I was changing the headings to what I wanted using html (although not all
the tables were lm summaries) before the major upgrade a year or so ago
Now things are better.

Even a title and comments in html for yourself if not available in xtable
are helpful. I have not used xtable and html since the upgrade as I use
latex

Duncan

-Original Message-
From: Livia Maria Vestergaard [mailto:lves...@student.sdu.dk] 
Sent: Wednesday, 6 May 2015 22:37
To: Duncan Mackay; R
Subject: SV: [R] lm model exported from R to excel

Hi Duncan
Thank you so much - it worked :)

Best 

Livia

Fra: Duncan Mackay [dulca...@bigpond.com]
Sendt: 6. maj 2015 14:26
Til: R; Livia Maria Vestergaard
Emne: RE: [R]  lm model exported from R to excel

Hi Livia

There are several html packages that ?could also do it

Heres a way with xtable

library(xtable)
y = rnorm(100)
x= rnorm(100)+rnorm(100)
mod <- lm(y ~x)

# latex example easy view
xtable(mod)

# html
file.create("lm.htm")
ff <- file("lm.htm", "a+")
fchars <-  print(xtable(mod),type = "html")
writeLines(paste(fchars, sep = ""), ff)
close(ff)

You can then bring this into Microsoft as an html file

You may need to fill in some of the arguments in xtable to get the right
border format etc

If you are doing many you can make a function to do things

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au

-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Livia Maria
Vestergaard
Sent: Wednesday, 6 May 2015 19:37
To: r-help
Subject: [R] lm model exported from R to excel

Hi all
I all. I am wondering whether anybody know how to export an output of an lm
model from R to excel in order to have excel recognize the table that comes
and divide the numbers in the table into columns and rows?
I really hope it is possible? :)

Best Livia
__
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-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.


  1   2   3   4   >