Skip to content

Commit a879293

Browse files
Merge pull request #16 from inSileco/ganttchart
Ganttchart
2 parents 8fd599e + e7c16a4 commit a879293

453 files changed

Lines changed: 1549 additions & 579 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

DESCRIPTION

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ Package: graphicsutils
22
Type: Package
33
Title: Collection of graphics utilities
44
Version: 1.3.0-9000
5-
Date: 2019-08-07
6-
Authors@R: c(person("Kevin", "Cazelles", role = c("aut", "cre"), email = "kcazelle@uoguelph.ca", comment = c(ORCID = "0000-0001-6619-9874")),
7-
person("Nicolas", "Casajus", role = c("aut"), comment = c(ORCID = "0000-0002-5537-5294")),
8-
person("David", "Beauchesne", role = c("aut")))
5+
Date: 2019-08-16
6+
Authors@R: c(
7+
person("Kevin", "Cazelles", role = c("aut", "cre"), email = "kcazelle@uoguelph.ca", comment = c(ORCID = "0000-0001-6619-9874")),
8+
person("Nicolas", "Casajus", role = "aut", comment = c(ORCID = "0000-0002-5537-5294")),
9+
person("David", "Beauchesne", role = "aut", comment = c(ORCID = "0000-0002-3590-8161")),
10+
person(given = "Steve", family = "Vissault", comment = c(ORCID = "0000-0002-0866-4376"), role = "aut")
11+
)
912
Description: A collection of functions to make the customizing graphics-based plots easier.
1013
Depends:
1114
R (>= 3.0.0)

NAMESPACE

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
export(arrows2)
44
export(biBoxplot)
5+
export(blendColors)
56
export(box2)
67
export(boxplot2)
78
export(circles)
@@ -15,6 +16,7 @@ export(ellipse)
1516
export(encircle)
1617
export(envelop)
1718
export(frameIt)
19+
export(ganttChart)
1820
export(getAngle2d)
1921
export(gpuPalette)
2022
export(gpuPalettes)
@@ -46,21 +48,37 @@ export(translation)
4648
export(vecfield2d)
4749
import(Rcpp)
4850
importFrom(Rcpp,evalCpp)
51+
importFrom(grDevices,as.graphicsAnnot)
4952
importFrom(grDevices,as.raster)
5053
importFrom(grDevices,col2rgb)
5154
importFrom(grDevices,colorRampPalette)
55+
importFrom(grDevices,dev.off)
56+
importFrom(grDevices,palette)
57+
importFrom(grDevices,rgb)
58+
importFrom(grDevices,xy.coords)
5259
importFrom(graphics,abline)
60+
importFrom(graphics,axis)
5361
importFrom(graphics,box)
5462
importFrom(graphics,image)
5563
importFrom(graphics,layout)
64+
importFrom(graphics,layout.show)
5665
importFrom(graphics,lines)
5766
importFrom(graphics,lines.default)
5867
importFrom(graphics,locator)
5968
importFrom(graphics,par)
69+
importFrom(graphics,plot)
70+
importFrom(graphics,plot.default)
71+
importFrom(graphics,plot.new)
72+
importFrom(graphics,plot.window)
6073
importFrom(graphics,points)
74+
importFrom(graphics,polygon)
75+
importFrom(graphics,rasterImage)
6176
importFrom(graphics,rect)
77+
importFrom(graphics,strheight)
78+
importFrom(graphics,strwidth)
6279
importFrom(graphics,text)
6380
importFrom(stats,aggregate)
81+
importFrom(stats,as.formula)
6482
importFrom(stats,quantile)
6583
importFrom(stats,rnorm)
6684
importFrom(stats,runif)

R/arrows2.R

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#'
2121
#' @keywords arrows
2222
#'
23-
#' @seealso \code{[graphics::arrows()]}, \code{[shape::Arrows()]}
23+
#' @seealso `[graphics::arrows()]`, `[shape::Arrows()]`
2424
#'
2525
#' @examples
2626
#' # Example 1:
@@ -35,24 +35,25 @@
3535
#' arrows2(runif(2), runif(2), x1=runif(2), y1=runif(2), prophead=FALSE, lty=3)
3636

3737

38-
arrows2 <- function(x0, y0, x1 = x0, y1 = y0, off0 = 0, off1 = off0, cex.arr = 1,
39-
cex.shr = 1, cex.hh = 1, cex.hl = 1, prophead = TRUE, twoheaded = FALSE, ...) {
38+
arrows2 <- function(x0, y0, x1 = x0, y1 = y0, off0 = 0, off1 = off0,
39+
cex.arr = 1, cex.shr = 1, cex.hh = 1, cex.hl = 1, prophead = TRUE,
40+
twoheaded = FALSE, ...) {
4041
stopifnot(all(c(off0, off1)^2 < 1))
4142
## ---- Format checking / adjusting vectors sizes
4243
argn <- c("x0", "y0", "x1", "y1")
4344
argo <- list(x0, y0, x1, y1)
44-
sz <- max(sapply(list(x0, y0, x1, y1), length))
45-
for (i in 1L:length(argn)) assign(argn[i], rep_len(argo[[i]], sz))
45+
sz <- max(lengths(list(x0, y0, x1, y1)))
46+
for (i in seq_along(argn)) assign(argn[i], rep_len(argo[[i]], sz))
4647
argo <- list(x0, y0, x1, y1)
4748
## ----
4849
rx <- (x1 - x0)
4950
ry <- (y1 - y0)
5051
distpt <- sqrt(rx * rx + ry * ry)
5152
# ----- Checking
5253
pb <- which(distpt == 0)
53-
if (length(pb) > 0) {
54+
if (length(pb)) {
5455
warning("Zero-length arrows are skipped.")
55-
for (i in 1L:length(argn)) assign(argn[i], argo[[i]][-pb])
56+
for (i in seq_along(argn)) assign(argn[i], argo[[i]][-pb])
5657
}
5758
## ----
5859
anglept <- 0.5 * pi
@@ -70,7 +71,7 @@ arrows2 <- function(x0, y0, x1 = x0, y1 = y0, off0 = 0, off1 = off0, cex.arr = 1
7071
hg2 <- hg1 * cex.shr
7172
hg3 <- hg2 + cex.hh * hg1
7273
## ----
73-
for (i in 1L:sz) {
74+
for (i in seq_len(sz)) {
7475
lg1 <- distpt[i]
7576
if (!prophead) {
7677
lg3 <- cex.hl * 0.06 * (myusr[2L] - myusr[1L])
@@ -90,9 +91,9 @@ arrows2 <- function(x0, y0, x1 = x0, y1 = y0, off0 = 0, off1 = off0, cex.arr = 1
9091
-hg1, -hg2, -hg3)
9192
}
9293
## ----
93-
ptcoord <- rotation(sqptx, sqpty, rot = anglept[i], xrot = x0[i], yrot = y0[i],
94-
rad = TRUE)
95-
graphics::polygon(ptcoord$x, ptcoord$y, ...)
94+
ptcoord <- rotation(sqptx, sqpty, rot = anglept[i], xrot = x0[i],
95+
yrot = y0[i], rad = TRUE)
96+
polygon(ptcoord$x, ptcoord$y, ...)
9697
}
9798
## ----
9899
invisible(NULL)

R/biBoxplot.R

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#'
55
#' @param df1 first set of boxplots.
66
#' @param df2 first set of boxplots.
7-
#' @param probs numeric vector of five probabilities (see \code{[stats::quantile()]}).
7+
#' @param probs numeric vector of five probabilities (see `[stats::quantile()]`).
88
#' @param width a vector giving the relative widths of the boxes making up the plot.
99
#' @param sta_wd staple width.
1010
#' @param median a list of arguments passed to [graphics::lines()] to custom the median line.
@@ -16,13 +16,11 @@
1616
#' @param at numeric vector giving the locations where the boxplots should be drawn. Same default behavior as in [graphics::boxplot()].
1717
#' @keywords boxplots
1818
#'
19-
#' @importFrom graphics lines.default rect
20-
#' @importFrom stats quantile rnorm
2119
#' @export
2220
#'
2321
#' @details Do not attempt to assess the distributions. Based on quantiles only.
2422
#'
25-
#' @seealso \code{[graphics::box()]}
23+
#' @seealso `[graphics::box()]`
2624
#'
2725
#' @examples
2826
#' # Example 1:
@@ -52,7 +50,7 @@ biBoxplot <- function(df1, df2 = df1, probs = c(0.01, 0.25, 0.5, 0.75, 0.99), wi
5250
if (!isTRUE(add))
5351
plot0(c(0.5, sz + 0.5), range(unlist(c(seqy1, seqy2))))
5452

55-
for (i in 1:sz) {
53+
for (i in seq_len(sz)) {
5654
makeUnit(at[i], seqy1[[i]], seqy2[[i]], width, sta_wd, col_left, col_right,
5755
dft_med, dft_sta, dft_whi)
5856
}

R/box2.R

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
#' @param side a numerical or character vector or a character string specifying which side(s) of the plot the box is to be drawn (see details).
66
#' @param which a character, one of `plot`, `figure`, `inner` and `outer`.
77
#' @param fill the color to be used to fill the box.
8-
#' @param ... further graphical parameters (see \code{[graphics::par()]}) may also be supplied as arguments, particularly, line type, `lty`, line width, `lwd`, color, `col` and for \code{type = 'b'}, `pch`. Also the line characteristics `lend`, `ljoin` and `lmitre`.
8+
#' @param ... further graphical parameters (see `[graphics::par()]`) may also be supplied as arguments, particularly, line type, `lty`, line width, `lwd`, color, `col` and for \code{type = 'b'}, `pch`. Also the line characteristics `lend`, `ljoin` and `lmitre`.
99
#'
1010
#' @keywords box
1111
#'
1212
#' @export
1313
#'
14-
#' @details This function intends to give more flexibility to the \code{[graphics::box()]} function.
15-
#' As `which` parameter, the user provides an object first coerced by \code{as.character} to a character string that is secondly split into single characters. For all of these characters, matches are sought with all elements of \code{1, 2, 3, 4, b, l, t, r} where \code{1=below, 2=left, 3=above, 4=right, b=below, l=left, t=above and r=right}.
14+
#' @details This function intends to give more flexibility to the `[graphics::box()]` function.
15+
#' As `which` parameter, the user provides an object first coerced by `as.character` to a character string that is secondly split into single characters. For all of these characters, matches are sought with all elements of `1, 2, 3, 4, b, l, t, r` where `1=below, 2=left, 3=above, 4=right, b=below, l=left, t=above and r=right`.
1616
#'
1717
#'
18-
#' @seealso \code{[graphics::box()]}
18+
#' @seealso `[graphics::box()]`
1919
#'
2020
#' @examples
2121
#' # Example 1:
@@ -31,66 +31,68 @@
3131
#' box2(c(1,4), fill='grey80', lwd=2)
3232
#'
3333
#' # Example 3:
34-
#' graphics::par(mfrow=c(2,2),oma=c(2,2,2,2))
34+
#' par(mfrow=c(2,2),oma=c(2,2,2,2))
3535
#' plot0(0,0)
36-
#' graphics::box('outer',lwd=2)
37-
#' graphics::box('inner',lwd=2)
38-
#' graphics::plot.default(0,0)
39-
#' graphics::plot.default(0,0)
36+
#' box('outer',lwd=2)
37+
#' box('inner',lwd=2)
38+
#' plot.default(0,0)
39+
#' plot.default(0,0)
4040
#' plot0()
4141
#' box2(which='figure',lwd=2, fill=2)
4242
#' box2(side=12, lwd=2, fill=8)
4343

4444

45-
box2 <- function(side = 1:4, which = "plot", fill = NULL, ...) {
46-
##
47-
stopifnot(which %in% c("plot", "figure", "outer", "inner"))
48-
##
45+
box2 <- function(side, which = c("plot", "figure", "outer", "inner"),
46+
fill = NULL, ...) {
47+
##
48+
which <- match.arg(which)
49+
if (missing(side)) side <- 1:4
50+
## get the sides desired
4951
vec <- unlist(strsplit(tolower(as.character(side)), ""))
50-
ax1 <- match(vec, c("1", "2", "3", "4"))%%5
51-
ax2 <- match(vec, c("b", "l", "t", "r"))%%5
52+
ax1 <- match(vec, as.character(1:4)) %% 5
53+
ax2 <- match(vec, c("b", "l", "t", "r")) %% 5
5254
ax <- unique(c(ax1, ax2), na.rm = TRUE)
5355
ax <- ax[!is.na(ax)]
54-
##
56+
##
5557
if (length(ax)) {
56-
coord <- graphics::par()$usr
58+
opar <- par(no.readonly = TRUE)
59+
on.exit(par(opar))
60+
coord <- opar$usr
5761
if (which != "plot") {
5862
## figure margins in user units
59-
cvx <- (graphics::par()$usr[2L] - graphics::par()$usr[1L])/graphics::par()$pin[1L]
60-
cvy <- (graphics::par()$usr[4L] - graphics::par()$usr[3L])/graphics::par()$pin[2L]
61-
mau <- graphics::par()$mai * rep(c(cvy, cvx), 2)
63+
cvx <- (opar$usr[2L] - opar$usr[1L])/opar$pin[1L]
64+
cvy <- (opar$usr[4L] - opar$usr[3L])/opar$pin[2L]
65+
mau <- opar$mai * rep(c(cvy, cvx), 2)
6266
coord <- coord + c(-mau[2L], mau[4L], -mau[1L], mau[3L])
6367
## inner margins in user units (get the lenght and adjust!)
6468
if (which != "figure") {
6569
diffx <- coord[2L] - coord[1L]
6670
diffy <- coord[4L] - coord[3L]
67-
lenx <- diffx * 1/(diff(graphics::par()$fig[1L:2L]))
68-
leny <- diffy * 1/(diff(graphics::par()$fig[1L:2L]))
69-
coord[1L] <- coord[1L] - graphics::par()$fig[1L] * lenx
71+
lenx <- diffx * 1/(diff(opar$fig[1L:2L]))
72+
leny <- diffy * 1/(diff(opar$fig[1L:2L]))
73+
coord[1L] <- coord[1L] - opar$fig[1L] * lenx
7074
coord[2L] <- coord[1L] + lenx
71-
coord[3L] <- coord[3L] - graphics::par()$fig[3L] * leny
75+
coord[3L] <- coord[3L] - opar$fig[3L] * leny
7276
coord[4L] <- coord[3L] + leny
7377
## outer margins in user units
7478
if (which != "inner") {
75-
omu <- graphics::par()$omi * rep(c(cvy, cvx), 2)
79+
omu <- opar$omi * rep(c(cvy, cvx), 2)
7680
coord <- coord + c(-omu[2L], omu[4L], -omu[1L], omu[3L])
7781
}
7882
}
7983
}
80-
op <- graphics::par("xpd")
81-
graphics::par(xpd = NA)
84+
op <- par("xpd")
85+
par(xpd = NA)
8286
mat <- matrix(c(4, 2, 3, 1, 3, 1, 4, 2), ncol = 2)
83-
if (!is.null(fill))
84-
graphics::rect(coord[1L], coord[3L], coord[2L], coord[4L], col = fill,
85-
border = NA)
87+
if (!is.null(fill))
88+
rect(coord[1L], coord[3L], coord[2L], coord[4L],
89+
col = fill, border = NA)
8690
for (i in ax) {
8791
coordb <- coord
8892
coordb[mat[i, 1L]] <- coordb[mat[i, 2L]]
89-
graphics::lines(c(coordb[1L], coordb[2L]), c(coordb[3L], coordb[4L]),
90-
...)
93+
lines(c(coordb[1L], coordb[2L]), c(coordb[3L], coordb[4L]), ...)
9194
}
92-
graphics::par(xpd = op)
93-
} else warning("'bty' does not match any of '1', '2', '3', '4', 'b', 'l', 't', 'r'")
94-
95-
invisible(NULL)
95+
} else warning("'side' does not match ant of the available values.")
96+
97+
invisible(ax)
9698
}

R/boxplot2.R

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
#' @return
2424
#' Draw a boxplot and returns the coordinates as an invisible output.
2525
#'
26-
#' @importFrom graphics lines points
27-
#' @importFrom stats aggregate quantile runif
2826
#' @export
2927
#'
3028
#' @examples
@@ -50,7 +48,7 @@ boxplot2 <- function(x, ..., probs = c(.05, 0.25, .5, .75, .95),
5048
val <- apply(as.data.frame(x), 2, quantile, probs = probs)
5149
}
5250
##
53-
if (is.null(at)) xco <- 1:ncol(val) else xco <- rep_len(at, ncol(val))
51+
if (is.null(at)) xco <- seq_len(ncol(val)) else xco <- rep_len(at, ncol(val))
5452
##
5553
if (!add)
5654
plot0(c(.5, ncol(val) + .5), range(val))

R/circles.R

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#' @param pie a logical. If `TRUE`, end points are linked with the center of the circle (default is set to `FALSE`).
1212
#' @param clockwise a logical. Shall circles and arcs be drawn clockwise? Defaut is `FALSE`.
1313
#' @param add a logical. Should the circles be added on the current plot?
14-
#' @param ... additional arguments to be passed to \code{[graphics::polygon()]} function.
14+
#' @param ... additional arguments to be passed to `[graphics::polygon()]` function.
1515
#'
1616
#' @keywords circle geometries
1717
#'
@@ -23,10 +23,10 @@
2323
#' Sizes are adjusted (i.e. repeated over) with \code{\link{rep_len}} function.
2424
#'
2525
#' @return
26-
#' An invisible list of \code{data.frame} of two columns including the
26+
#' An invisible list of `data.frame` of two columns including the
2727
#' coordinates of all circles.
2828
#'
29-
#' @seealso \code{[graphics::symbols()]}, \code{\link[plotrix]{draw.circle}}, \code{\link[plotrix]{draw.arc}}.
29+
#' @seealso `[graphics::symbols()]`, \code{\link[plotrix]{draw.circle}}, \code{\link[plotrix]{draw.arc}}.
3030
#'
3131
#' @examples
3232
#' # Example 1:
@@ -47,26 +47,26 @@
4747
#' plot0(x=c(-2,2),y=c(-2,2), asp=1)
4848
#' circles(x=c(-1,1),c(1,1,-1,-1),from=pi*seq(0.25,1,by=0.25),to=1.25*pi, col=2, border=4, lwd=3)
4949

50-
circles <- function(x, y = x, radi = 1, from = 0, to = 2 * pi, incr = 0.01, pie = FALSE,
50+
circles <- function(x, y = x, radi = 1, from = 0, to = 2 * pi, incr = 0.01, pie = FALSE,
5151
clockwise = FALSE, add = TRUE, ...) {
52-
#
52+
#
5353
pipi <- 2 * pi
54-
#
55-
if (!isTRUE(add))
54+
#
55+
if (!isTRUE(add))
5656
plot0()
5757
# format checking / adjusting vectors sizes
5858
matx <- as.matrix(x)
5959
argn <- c("x", "y", "radi", "from", "to")
6060
nbarg <- length(argn)
6161
nbcol <- min(nbarg, ncol(matx))
62-
for (i in 1L:nbcol) assign(argn[i], matx[, i])
62+
for (i in seq_len(nbcol)) assign(argn[i], matx[, i])
6363
argo <- list(x, y, radi, from, to)
64-
##
65-
sz <- max(sapply(argo, length))
66-
for (i in 1L:nbarg) assign(argn[i], rep_len(argo[[i]], sz))
64+
##
65+
sz <- max(lengths(argo))
66+
for (i in seq_len(nbarg)) assign(argn[i], rep_len(argo[[i]], sz))
6767
# drawing circles
6868
out <- list()
69-
for (i in 1L:sz) {
69+
for (i in seq_len(sz)) {
7070
## distance (in rardian)
7171
dagl <- abs(to[i] - from[i])
7272
## --- angles sequence
@@ -75,24 +75,24 @@ circles <- function(x, y = x, radi = 1, from = 0, to = 2 * pi, incr = 0.01, pie
7575
to[i] <- pipi + 0.5 * pi
7676
from[i] <- 0.5 * pi
7777
}
78-
##
78+
##
7979
if (!clockwise) {
8080
sqc <- seq(from[i], from[i] + dagl, by = incr)
8181
} else {
8282
sqc <- seq(from[i], from[i] - dagl, by = -incr)
8383
}
84-
##
84+
##
8585
if (!pie) {
8686
xout <- x[i] + radi[i] * cos(sqc)
8787
yout <- y[i] + radi[i] * sin(sqc)
8888
} else {
8989
xout <- x[i] + c(0, radi[i] * cos(sqc), 0)
9090
yout <- y[i] + c(0, radi[i] * sin(sqc), 0)
9191
}
92-
93-
graphics::polygon(xout, yout, ...)
92+
93+
polygon(xout, yout, ...)
9494
out[[i]] <- data.frame(x = xout, y = yout)
9595
}
96-
96+
9797
invisible(out)
9898
}

0 commit comments

Comments
 (0)