[R] Draw a circle on a filled.contour() plot
Jean.Coursol at math.u-psud.fr
Jean.Coursol at math.u-psud.fr
Sun Dec 17 23:04:34 CET 2006
Use my function filled.next:
filled.next <- function(fun) {
mar.orig <- mar <- par("mar")
w <- (3 + mar[2]) * par("csi") * 2.54
layout(matrix(c(2, 1), nc = 2), widths = c(1, lcm(w)))
mar[4] <- 1
par(mar = mar)
par(mfg=c(1,2))
par(new=TRUE)
fun
par(mar = mar.orig)
}
# then
filled.contour(y,x,z,levels=seq(0.02,1.0,len=50),
color.palette=colorRampPalette(c("blue","yellow","red")),
title=title(main="",xlab="",ylab=""))
filled.next(symbols(0.62,0.0,circles=c(2.5),add=TRUE,inches=FALSE))
With plot function in filled.next, don't forget to add xaxs='i', yaxs='i'...
Jean Coursol
----------------------------------------------
Quoting Renaud Lancelot <renaud.lancelot at gmail.com>:
> 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
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list