Skip to content

Commit

Permalink
Merge pull request #30 from courtiol/misc_generics
Browse files Browse the repository at this point in the history
Add generics for larrows, lpolygon, lrect and lsegments (fixes #29)
  • Loading branch information
deepayan committed Oct 2, 2023
2 parents 148fb35 + 33c34f3 commit 2cb437d
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 47 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Expand Up @@ -13,7 +13,8 @@ Authors@R: c(person("Deepayan", "Sarkar", role = c("aut", "cre"),
person("Zhijian (Jason)", "Wen", role = "cph", comment = "filled contour code"),
person("Paul", "Murrell", role = "ctb", email = "paul@stat.auckland.ac.nz"),
person("Stefan", "Eng", role = "ctb", comment = "violin plot improvements"),
person("Achim", "Zeileis", role = "ctb", comment = "modern colors")
person("Achim", "Zeileis", role = "ctb", comment = "modern colors"),
person("Alexandre", "Courtiol", role = "ctb", comment = "generics for larrows, lpolygon, lrect and lsegments")
)
Description: A powerful and elegant high-level data visualization
system inspired by Trellis graphics, with an emphasis on
Expand Down
6 changes: 5 additions & 1 deletion NAMESPACE
Expand Up @@ -299,9 +299,13 @@ S3method(tmd, formula)
S3method(tmd, trellis)


S3method(larrows, default)
S3method(llines, default)
S3method(ltext, default)
S3method(lpoints, default)
S3method(lpolygon, default)
S3method(lrect, default)
S3method(lsegments, default)
S3method(ltext, default)


### Local variables:
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Expand Up @@ -4,6 +4,8 @@

* TODO: data.frame methods

* `larrows()`, `lpolygon()`, `lrect()` and `lsegments()` are now generic functions.


# Changes in lattice 0.21

Expand Down
22 changes: 14 additions & 8 deletions R/miscellaneous.R
Expand Up @@ -203,13 +203,13 @@ Rows <- function(x, which)

## panel functions corresponding to standard base functions

panel.points <- function(...) lpoints(...)
panel.arrows <- function(...) larrows(...)
panel.lines <- function(...) llines(...)
panel.points <- function(...) lpoints(...)
panel.polygon <- function(...) lpolygon(...)
panel.rect <- function(...) lrect(...)
panel.segments <- function(...) lsegments(...)
panel.text <- function(...) ltext(...)
panel.arrows <- function(...) larrows(...)
panel.rect <- function(...) lrect(...)
panel.polygon <- function(...) lpolygon(...)



Expand All @@ -228,8 +228,9 @@ primName <- function(name, identifier = NULL, name.type = "panel", group = 0) {
## panel.points, panel.lines, etc.


lpolygon <- function(x, ...) UseMethod("lpolygon")

lpolygon <-
lpolygon.default <-
function(x, y = NULL,
## density = NULL,
## angle = 45,
Expand Down Expand Up @@ -281,8 +282,9 @@ lpolygon <-



lsegments <- function(...) UseMethod("lsegments")

lsegments <-
lsegments.default <-
function(x0 = NULL, y0 = NULL, x1, y1,
x2 = NULL, y2 = NULL,
col = add.line$col,
Expand Down Expand Up @@ -318,7 +320,10 @@ lsegments <-
}


lrect <-

lrect <- function(...) UseMethod("lrect")

lrect.default <-
function(xleft, ybottom, xright, ytop,
x = (xleft + xright) / 2,
y = (ybottom + ytop) / 2,
Expand Down Expand Up @@ -362,8 +367,9 @@ lrect <-



larrows <- function(...) UseMethod("larrows")

larrows <-
larrows.default <-
function(x0 = NULL, y0 = NULL, x1, y1, x2 = NULL, y2 = NULL,
angle = 30, code = 2, length = 0.25, unit = "inches",
ends = switch(code, "first", "last", "both"),
Expand Down
82 changes: 45 additions & 37 deletions man/llines.Rd
@@ -1,22 +1,27 @@
\name{F_2_llines}
\alias{larrows}
\alias{llines}
\alias{lpoints}
\alias{lpolygon}
\alias{lrect}
\alias{lsegments}
\alias{ltext}
\alias{larrows.default}
\alias{llines.default}
\alias{lpoints.default}
\alias{lpolygon.default}
\alias{lrect.default}
\alias{lsegments.default}
\alias{ltext.default}
\alias{lplot.xy}
\alias{larrows}
\alias{lsegments}
\alias{lrect}
\alias{lpolygon}
\alias{panel.arrows}
\alias{panel.lines}
\alias{panel.points}
\alias{panel.polygon}
\alias{panel.rect}
\alias{panel.segments}
\alias{panel.text}
\alias{panel.rect}
\alias{panel.polygon}

\title{Replacements of traditional graphics functions}

\description{
Expand All @@ -36,35 +41,15 @@ lplot.xy(xy, type, pch, lty, col, cex, lwd,
col.line, col.symbol, alpha, fill,
origin = 0, \dots, identifier, name.type)

larrows(...)
llines(x, ...)
lpoints(x, ...)
lpolygon(x, ...)
lrect(...)
lsegments(...)
ltext(x, ...)

\method{llines}{default}(x, y = NULL, type = "l",
col, alpha, lty, lwd, \dots, identifier, name.type)
\method{lpoints}{default}(x, y = NULL, type = "p", col, pch, alpha, fill,
font, fontfamily, fontface, cex, \dots, identifier, name.type)
\method{ltext}{default}(x, y = NULL, labels = seq_along(x),
col, alpha, cex, srt = 0,
lineheight, font, fontfamily, fontface,
adj = c(0.5, 0.5), pos = NULL, offset = 0.5, \dots, identifier, name.type)

lsegments(x0, y0, x1, y1, x2, y2,
col, alpha, lty, lwd,
font, fontface, \dots, identifier, name.type)
lrect(xleft, ybottom, xright, ytop,
x = (xleft + xright) / 2,
y = (ybottom + ytop) / 2,
width = xright - xleft,
height = ytop - ybottom,
col = "transparent",
border = "black",
lty = 1, lwd = 1, alpha = 1,
just = "center",
hjust = NULL, vjust = NULL,
font, fontface,
\dots, identifier, name.type)
larrows(x0 = NULL, y0 = NULL, x1, y1, x2 = NULL, y2 = NULL,
\method{larrows}{default}(x0 = NULL, y0 = NULL, x1, y1, x2 = NULL, y2 = NULL,
angle = 30, code = 2, length = 0.25, unit = "inches",
ends = switch(code, "first", "last", "both"),
type = "open",
Expand All @@ -75,17 +60,40 @@ larrows(x0 = NULL, y0 = NULL, x1, y1, x2 = NULL, y2 = NULL,
fill = NULL,
font, fontface,
\dots, identifier, name.type)
lpolygon(x, y = NULL,
border = "black", col = "transparent", fill = NULL,
font, fontface, \dots, identifier, name.type)
\method{llines}{default}(x, y = NULL, type = "l",
col, alpha, lty, lwd, \dots, identifier, name.type)
\method{lpoints}{default}(x, y = NULL, type = "p", col, pch, alpha, fill,
font, fontfamily, fontface, cex, \dots, identifier, name.type)
\method{lpolygon}{default}(x, y = NULL,
border = "black", col = "transparent", fill = NULL,
font, fontface, \dots, identifier, name.type)
\method{ltext}{default}(x, y = NULL, labels = seq_along(x),
col, alpha, cex, srt = 0,
lineheight, font, fontfamily, fontface,
adj = c(0.5, 0.5), pos = NULL, offset = 0.5, \dots, identifier, name.type)
\method{lrect}{default}(xleft, ybottom, xright, ytop,
x = (xleft + xright) / 2,
y = (ybottom + ytop) / 2,
width = xright - xleft,
height = ytop - ybottom,
col = "transparent",
border = "black",
lty = 1, lwd = 1, alpha = 1,
just = "center",
hjust = NULL, vjust = NULL,
font, fontface,
\dots, identifier, name.type)
\method{lsegments}{default}(x0, y0, x1, y1, x2, y2,
col, alpha, lty, lwd,
font, fontface, \dots, identifier, name.type)

panel.arrows(\dots)
panel.lines(\dots)
panel.points(\dots)
panel.polygon(\dots)
panel.rect(\dots)
panel.segments(\dots)
panel.text(\dots)
panel.rect(\dots)
panel.arrows(\dots)
panel.polygon(\dots)
}
\arguments{

Expand Down

0 comments on commit 2cb437d

Please sign in to comment.