[R] Creating smooth color regions with panel.contourplot()

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Sep 18 22:43:44 CEST 2008


On Thu, Sep 18, 2008 at 1:36 PM, Waichler, Scott R
<Scott.Waichler at pnl.gov> wrote:
>> > Thank you very much, Deepayan.  There is just one more feature I'd
>> > like to get, the ability to add the contour lines.  My revision to
>> > your code below prints too many lines.  What needs to be changed?
>
>> You need to name arguments here. as.double(at) is being
>> matched to 'nlevels', but you want 'levels'.
>>
>> Another option is to use panel.levelplot() for the contours.
>> E.g., (also with more accurate 'x' and 'y'):
>>
>> panel.filledcontour <-
>>    function(x, y, z, subscripts,
>>             at,
>>             col.regions = cm.colors,
>>             col = col.regions(length(at) - 1),
>>             ...)
>> {
>>    stopifnot(require("gridBase"))
>>    z <- matrix(z[subscripts],
>>                nrow = length(unique(x[subscripts])),
>>                ncol = length(unique(y[subscripts])))
>>    if (!is.double(z)) storage.mode(z) <- "double"
>>    opar <- par(no.readonly = TRUE)
>>    on.exit(par(opar))
>>    if (panel.number() > 1)
>>        par(new = TRUE)
>>    par(fig = gridFIG(), omi = c(0, 0, 0, 0), mai = c(0, 0, 0, 0))
>>    cpl <- current.panel.limits()
>>    plot.window(xlim = cpl$xlim, ylim = cpl$ylim,
>>                log = "", xaxs = "i", yaxs = "i")
>>    .Internal(filledcontour(as.double(sort(unique(x[subscripts]))),
>>                            as.double(sort(unique(y[subscripts]))),
>>                            z, as.double(at), col = col))
>>    panel.contourplot(x, y, z, subscripts = subscripts, at = at,
>>                    region = FALSE, contour = TRUE, labels = FALSE) }
>
> The contour lines do not exactly line up with some of the color breaks.
> I see this in the volcano example as well as the figure I'm trying to
> make.

Does the contour() solution work? If not, there's not really much that
can be done.

-Deepayan



More information about the R-help mailing list