Skip to content

Commit

Permalink
fixes #28, making lty an argument for slopegraph
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtPoon committed Oct 21, 2022
1 parent 5c851c9 commit bfa8b43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
13 changes: 10 additions & 3 deletions R/ridgeplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#' @param fill: character vector of R colours for filling densities. Will recycle
#' colours if there are fewer than the number of groups in 'x'.
#' @param lwd: line width for drawing density curves and line segments.
#' @param lty: line style for drawing density curves
#' @param density.args: list of optional arguments for density().
#' @param add.grid: if TRUE, call add.grid() before drawing densities
#' @param grid.args: list of optional arguments for add.grid()
Expand All @@ -47,7 +48,7 @@
#'
#' @export
ridgeplot <- function(x, xlim=NA, labels=NA, yaxt='s', xlab=NA, ylab=NA, step=0.2,
col=NA, fill=NA, lwd=1, density.args=list(),
col=NA, fill=NA, lwd=1, lty=1, density.args=list(),
add.grid=F, grid.args=list(), extend.lines=T, add=F,
freq=F, prev=NA, ...)
{
Expand Down Expand Up @@ -127,7 +128,13 @@ ridgeplot <- function(x, xlim=NA, labels=NA, yaxt='s', xlab=NA, ylab=NA, step=0.
plot(NA, xlim=xlim, ylim=c(step, max(all.y, na.rm=T)), xlab=xlab, ylab=ylab, yaxt='n', ...)

# override y-axis labels
if (yaxt != 'n') axis(side=2, at=seq(step, n*step, step), labels=labels, las=2)
if (yaxt != 'n') {
if (step==0) {
axis(side=2, at=pretty(seq(0, max(all.y, na.rm=T), length.out=10)), ...)
} else {
axis(side=2, at=seq(step, n*step, step), labels=labels, las=2)
}
}

# optional grid
if (add.grid) {
Expand Down Expand Up @@ -156,7 +163,7 @@ ridgeplot <- function(x, xlim=NA, labels=NA, yaxt='s', xlab=NA, ylab=NA, step=0.
ymin <- c(ymin, min(y))

polygon(kd$x, y, col=bg[i], border=NA)
lines(kd$x, y, col=pal[i], lwd=lwd)
lines(kd$x, y, col=pal[i], lwd=lwd, lty=ifelse(length(lty)==1, lty, lty[i]))

# extend density curve to full horizontal range
if (extend.lines) {
Expand Down
2 changes: 1 addition & 1 deletion R/slopegraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ slopegraph <- function(x, y=NA, type='b', names.arg=NA, xlab=NA, ylab=NA,
}

# prepare plot region
par(mar=c(5,5,2,5))
#par(mar=c(5,5,2,5))
plot(NA, xlim=c(ifelse(type=='t', 1-shim, 0.9), 2+shim),
ylim=range(c(x, y)),
xaxt='n', yaxt=ifelse(type=='t', 'n', 's'), bty='n',
Expand Down

0 comments on commit bfa8b43

Please sign in to comment.