George Chen
2010-Aug-08 19:49 UTC
[R] Does anybody know how to control the appearance of the end of the line in lattice?
Hi All, I am plotting vertical lines using xyplot in lattice and type="h". It works well, but the problem is that the tops of the lines are convex and the bottoms are concave. Is there a way to flatten the tops and bottoms? Here's my code: Source<-matrix(1:30,10,3) colnames(Source)<-c("x","y1","y2") Source<-data.frame(Source) xyplot(y2+y1~x, data=Source, distribute.type=TRUE, type=c("h","h"), col=c("black","white"), lwd=20) graphics.off() Thanks. George Chen
Paul Murrell
2010-Aug-08 20:23 UTC
[R] Does anybody know how to control the appearance of the end of the line in lattice?
Hi On 9/08/2010 7:49 a.m., George Chen wrote:> Hi All, > > I am plotting vertical lines using xyplot in lattice and type="h". > It works well, but the problem is that the tops of the lines are convex and the bottoms are concave. > Is there a way to flatten the tops and bottoms?You want to control the graphical parameter called "lineend", but I don't think this is generally made available via trellis.par.set(). Also, trying to set a default value via the 'grid.pars' argument, or via a viewport with the 'draw.in' argument doesn't appear to work in this case (the lineend may be hard coded in the internal code somewhere). The following code (to be run AFTER your code) does the trick for your example ... library(grid) grid.gedit("segments", gp=gpar(lineend="butt"), grep=TRUE) ... though I believe this will also make the ends of the tick marks on the axes square (not obvious to the naked eye at the default size). Paul> Here's my code: > > Source<-matrix(1:30,10,3) > colnames(Source)<-c("x","y1","y2") > Source<-data.frame(Source) > > xyplot(y2+y1~x, > data=Source, > distribute.type=TRUE, > type=c("h","h"), > col=c("black","white"), > lwd=20) > graphics.off() > > Thanks. > > George Chen > > ______________________________________________ > R-help at r-project.org mailing list > 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.-- Dr Paul Murrell Department of Statistics The University of Auckland Private Bag 92019 Auckland New Zealand 64 9 3737599 x85392 paul at stat.auckland.ac.nz http://www.stat.auckland.ac.nz/~paul/
p_connolly at slingshot.co.nz
2010-Aug-08 23:11 UTC
[R] Does anybody know how to control the appearance of the end of the line in lattice?
On Sun, 08-Aug-2010 at 12:49PM -0700, George Chen wrote: |> Hi All, |> |> I am plotting vertical lines using xyplot in lattice and type="h". |> It works well, but the problem is that the tops of the lines are |> convex and the bottoms are concave. Is there a way to flatten the |> tops and bottoms? The bottom isn't concave. You've drawn a white line which has semi-circular ends (as is the default) over the black one. I'm having difficulty imagining what your real objective is, but if you want to change the way the end of lines are drawn, it's simple in base graphics using the 'lend' parameter (but it doesn't work with all devices according to the help file for par). If you are using xyplot because you want to use the neat things you can do with lattice, I think you'll have to go about it a slightly more complicated way. Use lpolygon in a panel function to draw polygons and fill them. HTH |> |> Here's my code: |> |> Source<-matrix(1:30,10,3) |> colnames(Source)<-c("x","y1","y2") |> Source<-data.frame(Source) |> |> xyplot(y2+y1~x, |> data=Source, |> distribute.type=TRUE, |> type=c("h","h"), |> col=c("black","white"), |> lwd=20) |> graphics.off() |> |> Thanks. |> |> George Chen |> |> ______________________________________________ |> R-help at r-project.org mailing list |> 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. -- Patrick Connolly Plant & Food Research Mt Albert Auckland New Zealand Ph: +64-9 925 7079 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ I have the world`s largest collection of seashells. I keep it on all the beaches of the world ... Perhaps you`ve seen it. ---Steven Wright ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~
Deepayan Sarkar
2010-Aug-17 09:26 UTC
[R] Does anybody know how to control the appearance of the end of the line in lattice?
On Mon, Aug 9, 2010 at 1:19 AM, George Chen <glchen at stanford.edu> wrote:> Hi All, > > I am plotting vertical lines using xyplot in lattice and type="h". > It works well, but the problem is that the tops of the lines are convex and the bottoms are concave. > Is there a way to flatten the tops and bottoms? > > Here's my code: > > Source<-matrix(1:30,10,3) > colnames(Source)<-c("x","y1","y2") > Source<-data.frame(Source) > > xyplot(y2+y1~x, > ? ? ? ?data=Source, > ? ? ? ?distribute.type=TRUE, > ? ? ? ?type=c("h","h"), > ? ? ? ?col=c("black","white"), > ? ? ? ?lwd=20) > graphics.off()An additional note: If you actually want segments, then it would be more natural to use library(latticeExtra) segplot(x ~ y2 + y1, data = Source, horizontal = FALSE, col=c("black"), lwd=20) To get flattened corners, you could use segplot(x ~ y2 + y1, data = Source, horizontal = FALSE, col=c("black"), lwd=20, lineend = "butt") -Deepayan