Learn R Programming

itsadug (version 2.0)

fadeRug: Fade out the areas in a surface without data.

Description

Add a transparency Rug to a contour plot or image.

Usage

fadeRug(x, y, n.grid = 30, gradual = FALSE, max.alpha = 0.75,
  col = "white")

Arguments

x
Observations on x-axis.
y
Observations on y-axis.
n.grid
Resolution of Rug. Defaults to 30, which means that the x- and y-axis are divided in 30 bins.
gradual
Logical: whether or not to use the number of observations in an area, i.e., more transparent equals more observations. Default is FALSE, which means that the function only distinguishes between observations in a certain region or not, regardless how m
max.alpha
Maximum of transparency, number between 0 (completely transparent) and 1 (non-transparent). Defaults to .75.
col
Color value. Defaults to "white".

Value

  • Plots a shaded image over the contour plot or image.

Warning

On Linux x11 devices may not support transparency. In that case, a solution might be to write the plots immediately to a file using functions such as pdf, or png.

See Also

rug, contour, image

Other Functions for plotting: addInterval, add_bars, alphaPalette, alpha, check_normaldist, color_contour, dotplot_error, drawArrows, emptyPlot, errorBars, fill_area, getCoords, getFigCoords, getProps, gradientLegend, marginDensityPlot, plot_error, plot_image, plotsurface, rug_model

Examples

Run this code
data(simdat)

# Introduce extreme values:
set.seed(123)
newdat <- simdat[sample(which(simdat$Time < 1500),
    size=round(.5*length(which(simdat$Time < 1500)))),]
newdat <- rbind(newdat, 
    simdat[sample(which(simdat$Time > 1500),
    size=5),])
# Some simple GAM with tensor:
m1 <- bam(Y ~ te(Time, Trial), data=newdat)
# plot summed effects:
fvisgam(m1, view=c("Time", "Trial"), zlim=c(-15,15),
    add.color.legend=FALSE)
# add rug:
fadeRug(newdat$Time, newdat$Trial)
# compare with default rug:
rug(newdat$Time)
rug(newdat$Trial, side=2)
# add color legend:
gradientLegend(c(-15,15), pos=.875)
# add data points (for checking the grid):
points(newdat$Time, newdat$Trial)

# change x- and y-grid:
fvisgam(m1, view=c("Time", "Trial"), zlim=c(-15,15))
points(newdat$Time, newdat$Trial)
fadeRug(newdat$Time, newdat$Trial, n.grid=c(100,10), col='gray')

Run the code above in your browser using DataLab