Skip to content

Commit

Permalink
Merge pull request #19 from daffp/master
Browse files Browse the repository at this point in the history
Additional graphical parameters for loess lines
  • Loading branch information
edzer authored Jan 7, 2021
2 parents 8098c76 + e7fd6d5 commit 367ab7b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: hexbin
Version: 1.28.1
Version: 1.28.2
Title: Hexagonal Binning Routines
Author: Dan Carr <dcarr@voxel.galaxy.gmu.edu>, ported by Nicholas
Lewin-Koh and Martin Maechler <maechler@stat.math.ethz.ch>,
Expand Down
4 changes: 2 additions & 2 deletions R/hexPlotMA.R
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ plotMAhex <- function (MA, array = 1, xlab = "A", ylab = "M",
invisible(list(hbin = hbin, plot.vp = hp$plot.vp, legend.vp = hp$legend.vp))
}

hexMA.loess <- function(pMA, span = .4, col = 'red', n = 200)
hexMA.loess <- function(pMA, span = .4, col = 'red', n = 200, ...)
{
fit <- hexVP.loess(pMA$hbin, pMA$plot.vp, span = span, col = col, n = n)
fit <- hexVP.loess(pMA$hbin, pMA$plot.vp, span = span, col = col, n = n, ...)
invisible(fit)
}
4 changes: 2 additions & 2 deletions R/hexViewport.R
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ hexVP.abline <- function(hvp, a = NULL, b = NULL, h = numeric(0),
popViewport()
}

hexVP.loess <- function(hbin, hvp = NULL, span = 0.4, col = 'red', n = 200)
hexVP.loess <- function(hbin, hvp = NULL, span = 0.4, col = 'red', n = 200, ...)
{
fit <- loess(hbin@ycm ~ hbin@xcm, weights = hbin@count, span = span)
if(!is.null(hvp)) {
Expand All @@ -251,7 +251,7 @@ hexVP.loess <- function(hbin, hvp = NULL, span = 0.4, col = 'red', n = 200)
# gp = gpar(col = col), default.units = 'native')
grid.lines(seq(hbin@xbnds[1], hbin@xbnds[2], length = n),
predict(fit,seq(hbin@xbnds[1], hbin@xbnds[2], length = n)),
gp = gpar(col = col), default.units = 'native')
gp = gpar(col = col, ...), default.units = 'native')
popViewport()
}
invisible(fit)
Expand Down
13 changes: 9 additions & 4 deletions man/hexMA.loess.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
coordinates and the cell counts as weights.
}
\usage{
hexMA.loess(pMA, span = 0.4, col = "red", n = 200)
hexVP.loess(hbin, hvp = NULL, span = 0.4, col = "red", n = 200)
hexMA.loess(pMA, span = 0.4, col = "red", n = 200, ...)
hexVP.loess(hbin, hvp = NULL, span = 0.4, col = "red", n = 200, ...)
}

\arguments{
Expand All @@ -18,7 +18,7 @@ hexVP.loess(hbin, hvp = NULL, span = 0.4, col = "red", n = 200)
\item{span}{the parameter alpha which controls the degree of smoothing.}
\item{col}{line color for the loess fit.}
\item{n}{number of points at which the fit should be evaluated.}
}
\item{...}{Additional graphical parameter settings for the \code{loess} line fit; see \code{\link[grid]{gpar}}.}}
\value{
Returns invisibly the object associated with the loess fit.
}
Expand All @@ -36,7 +36,12 @@ hexVP.loess(hbin, hvp = NULL, span = 0.4, col = "red", n = 200)
hb <- plotMAhex(swirl[,1], main = "M vs A plot with hexagons", legend=0)
hexVP.abline(hb$plot, h=0, col= gray(.6))
hexMA.loess(hb)
}
}

dat <- data.frame(x=rnorm(1000), y=rnorm(1000))
bin <- hexbin(dat$x, dat$y)
hb <- plot(bin)
hexVP.loess(bin, hvp = hb$plot.vp, span = 0.4, n = 200, col = "blue", lwd = 3, lty = "dashed")
}
\keyword{aplot}

0 comments on commit 367ab7b

Please sign in to comment.