[R] Draw a circle on a filled.contour() plot

Renaud Lancelot renaud.lancelot at gmail.com
Sun Dec 17 16:40:28 CET 2006


Try levelplot in package lattice instead of filled.contour: you will
be able to annotate the plot using the grid package. Moreover, you can
remove the key using the colorkey argument.

library(lattice)
library(grid)
z <- as.matrix(read.table("hist_2d"))
dimnames(z) <- NULL
Data <- expand.grid(x = seq(-4.45, 4.45, len = 90),
                    y = seq(-4.45, 4.45, len = 90))
Data$z <- c(z)
rm(z)
Cols <- colorRampPalette(c("white", "blue","yellow","red"))
levelplot(z ~ x * y, data = Data,
  aspect = 1, colorkey = FALSE, col.regions = Cols(6),
    panel = function(...){
      panel.levelplot(...)
      grid.circle(x = 0.62, y = 0, r = 2.5, default.units = "native")
      })

Best,

Renaud

2006/12/17, Webmaster <webmaster at citedesjeunes.com>:
> > The output produced by 'filled.contour' is actually a combination
> >      of two plots; one is the filled contour and one is the legend.
> >      Two separate coordinate systems are set up for these two plots,
> >      but they are only used internally - once the function has
> > returned
> >      these coordinate systems are lost.  If you want to annotate the
> >      main contour plot, for example to add points, you can specify
> >      graphics commands in the 'plot.axes' argument.  An example is
> >      given below.
>
> Thanks!
>
> I now have another question (hopefully the last) for which I couldn't
> find an answer in the mailing-list archives: how can I get rid of the
> color key on the contour.filled() plot? I that question, unanswered,
> in a post one year ago on this same list, so I hope it's by any mean
> possible... (I think it's possible to change the code completely and
> use image(), but it's much less pretty).
>
> FX
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Renaud LANCELOT
Département Elevage et Médecine Vétérinaire (EMVT) du CIRAD
Directeur adjoint chargé des affaires scientifiques

CIRAD, Animal Production and Veterinary Medicine Department
Deputy director for scientific affairs

Campus international de Baillarguet
TA 30 / B (Bât. B, Bur. 214)
34398 Montpellier Cedex 5 - France
Tél   +33 (0)4 67 59 37 17
Secr. +33 (0)4 67 59 39 04
Fax   +33 (0)4 67 59 37 95



More information about the R-help mailing list