Skip to content

how to add points/lines to a surface plot

3 messages · Domenico Vistocco, Uwe Ligges, David Winsemius

#
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?
#
See ?persp, particularly the example that starts with
  # (2) Add to existing persp plot - using trans3d() :

Uwe Ligges
Domenico Vistocco wrote:
#
In this case, following your instructions and a bit of noodling with  
the example "solves" the problem with:

persp(teta1, teta2, matrixMuSigma) -> res
points(trans3d( teta1, sigmaMax, apply(matrixMuSigma, 1, max),  
pmat=res), col="red")