[R] Equivalent of box() in grid graphics

Patrick Connolly p_connolly at slingshot.co.nz
Tue Jan 29 10:42:12 CET 2013


On Mon, 28-Jan-2013 at 12:21PM +1300, Paul Murrell wrote:

|> Hi
|> 
|> On 17/01/13 13:19, p_connolly at slingshot.co.nz wrote:
|> >Paul Murell's article "What's in a Name" in The R Journal Vol 4/2
|> >gives an interesting example of editing a stacked barplot of the barley
|> >data.  Using the method described in that article, it's easy to do
|> >something along the lines of
|> >
|> >grid.edit("plot_01.border.strip.1",
|> >           grep=TRUE, global=TRUE,
|> >           gp=gpar(col = "red"))
|> >
|> >That changes more than I'd like to change. I'd like to change only the
|> >bottom line of the rectangle.  How would I overwrite the unwanted red
|> >lines along the lines of what box() would do with base graphics?
|> 
|> You cannot modify just part of a basic shape (e.g., just the bottom
|> line of a rectangle).  One way to do what I think you want is to
|> specify a custom strip function that draws an extra line over the
|> top of the existing rectangle, like this ...
|> 
|> library(lattice)
|> library(grid)
|> barchart(yield ~ variety | site, data = barley,
|>          groups = year, layout = c(1,6),
|>          stack = TRUE,
|>          ylab = "Barley Yield (bushels/acre)",
|>          scales = list(x = list(rot = 45)),
|>          strip = function(...) {
|>              strip.default(...)
|>              grid.segments(0, 0, 1, 0, gp=gpar(lwd=1.5, col="red"))
|>          })
|> 
|> Is that the sort of effect you want?

I didn't really want thick red lines, but now that I know how to use
grid.segments, I can do what I need.

Thanks


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



More information about the R-help mailing list