[R] how to add points/lines to a surface plot
Uwe Ligges
ligges at statistik.tu-dortmund.de
Tue Feb 10 17:50:41 CET 2009
See ?persp, particularly the example that starts with
# (2) Add to existing persp plot - using trans3d() :
Uwe Ligges
Domenico Vistocco wrote:
> Dear All,
> is there a way to superimpose points and/or lines on a surface plot?
>
> Below I try to explain my problem.
> Suppose I have the following surface plot (likelikood for the normal
> variable when both parameters are unknown):
>
> -------------------------------------------------------------------------------------------------------------------------------------------
>
> normalLike <- function(mu, sigma, sample){
> (sigma ^ - length(sample)) * exp(-0.5 * (sigma ^ -2) * sum((sample -
> mu)^2))
> }
> normalLikeVec <- Vectorize(normalLike, vectorize.args = c("mu","sigma"))
>
> teta1 <- seq(0, 6, by=0.1)
> teta2 <- seq(0.1, 8, by=0.1)
> matrixMuSigma <- outer(teta1, teta2, normalLikeVec, sample=c(0.88, 1.07,
> 1.27,1.54, 1.91, 2.27, 3.84, 4.50, 4.64, 9.41))
> matrixMuSigma <- matrixMuSigma / max(matrixMuSigma)
>
> persp(teta1, teta2, matrixMuSigma)
> -------------------------------------------------------------------------------------------------------------------------------------------
>
>
> Then I would like to superimpose on the same plot points (or a line)
> corresponding to the following data:
> -------------------------------------------------------------------------------------------------------------------------------------------
>
> #x coordinates
> teta1
> #y coordinates
> sigmaMax <- teta2[apply(matrixMuSigma, 1, which.max)]
> #z coordinates
> apply(matrixMuSigma, 1, max)
> -------------------------------------------------------------------------------------------------------------------------------------------
>
>
> Thanks in advance,
> domenico
>
> PS:
> I am trying to explain the geometrical interpretation of profile
> likelihood. Any better idea?
>
> ______________________________________________
> R-help at r-project.org 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