Skip to content

Does anybody know how to control the appearance of the end of the line in lattice?

4 messages · George Chen, Paul Murrell, Duncan Mackay +1 more

#
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
#
Hi
On 9/08/2010 7:49 a.m., George Chen wrote:
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

  
    
#
Hi

see
http://finzi.psych.upenn.edu/Rhelp10/2010-April/234441.html

The following I think works - its a bit rough - needs improving but saves 
closing the device.
xyplot(y2+y1~x,
        data=Source,
        par.settings = list(grid.pars = list(lineend = "butt")),
        #distribute.type=TRUE,
        y1 = Source$y1,
        y2=Source$y2,

         panel = function(x,y1,y2,...){

           panel.segments(x,y1, x,y2, gp = gpar(lineend="butt"), 
col=c("black"), lwd =20)

         }
)


Regards

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
ARMIDALE NSW 2351
Email home: mackay at northnet.com.au
At 06:23 9/08/2010, you wrote:
7 days later
#
On Mon, Aug 9, 2010 at 1:19 AM, George Chen <glchen at stanford.edu> wrote:
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