[R] Wireframe plot inside a function
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Fri Apr 21 23:58:46 CEST 2017
No... it is
print(plot(cop1, main = "cop1 function"))
--
Sent from my phone. Please excuse my brevity.
On April 21, 2017 1:56:00 PM PDT, George Trojan - NOAA Federal <george.trojan at noaa.gov> wrote:
>I see. So, if I don't care about the plot object itself, the proper
>incantation is
>
>plot(plot(cop1, main = "cop1 function"))
>
>Thanks again.
>
>On 21 April 2017 at 20:32, Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
>wrote:
>> Your original function created the cop1 plot object but did nothing
>with it. It then created the cop2 plot and returned it from the
>function. Since you had invoked the cplot function from the interactive
>console, R printed that returned object automatically, which displayed
>the plot.
>>
>> FYI: when you want to start presenting multiple plots and/or tables
>together you will find that something like knitr and RMarkdown are very
>helpful.
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On April 21, 2017 11:59:28 AM PDT, George Trojan - NOAA Federal
><george.trojan at noaa.gov> wrote:
>>>Thanks. After changing the function to
>>>
>>>cplot <- function(cop1, cop2) {
>>> x11()
>>> o <- plot(cop1, main = "cop1 function")
>>> print(o)
>>> x11()
>>> o <- plot(cop2, main = "cop2 function")
>>> print(o)
>>>}
>>>
>>>I see both plots. But, since "cop2 function" was plotted before, does
>>>it mean it is plotted twice now? Looks as a strange design.
>>>
>>>I did check the "Plain text mode" in Chrome, you should see only the
>>>text part.
>>>
>>>George
>>>
>>>On 21 April 2017 at 16:27, Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
>>>wrote:
>>>> FAQ 7.22
>>>> And don't send HTML email... you are the one making it difficult
>for
>>>us to read your question.
>>>>
>>>> --
>>>> Sent from my phone. Please excuse my brevity.
>>>>
>>>> On April 21, 2017 8:27:20 AM PDT, George Trojan - NOAA Federal
>>><george.trojan at noaa.gov> wrote:
>>>>>Consider the following example:
>>>>>
>>>>>library("kdecopula")
>>>>>library("mvtnorm")
>>>>>
>>>>>pobs <- function(x) rank(x) / (length(x) + 1)
>>>>>
>>>>>n <- 1000
>>>>>
>>>>>sigma1 <- diag(x = 1, 2, 2)
>>>>>x1 <- rmvnorm(n, sigma = sigma1)
>>>>>xx1 <- apply(x1, 2, pobs)
>>>>>cop1 <- kdecop(xx1)
>>>>>
>>>>>eps <- 0.8
>>>>>sigma2 <- matrix(c(1, eps, eps, 1), ncol = 2)
>>>>>x2 <- rmvnorm(n, sigma = sigma2)
>>>>>xx2 <- apply(x2, 2, pobs)
>>>>>cop2 <- kdecop(xx2)
>>>>>
>>>>>x11()
>>>>>plot(cop1, main = "cop1 main")
>>>>>x11()
>>>>>plot(cop2, main = "cop2 main")
>>>>>
>>>>>cplot <- function(cop1, cop2) {
>>>>> x11()
>>>>> plot(cop1, main = "cop1 function")
>>>>> x11()
>>>>> plot(cop2, main = "cop2 function")
>>>>>}
>>>>>
>>>>>cplot(cop1, cop2)
>>>>>
>>>>>cat("Press <Enter> to quit")
>>>>>readLines(file("stdin"), n
>>>>>
>>>>>=
>>>>>
>>>>>1)
>>>>>quit()
>>>>>
>>>>>When I run it with Rscript all four x11 windows pop up, however the
>>>one
>>>>>that should display "cop1 function" is blank, the wireframe is not
>>>>>plotted.
>>>>>This is R 3.3.1, on Fedora 20.
>>>>>I see similar behaviour on Fedora 24, R 3.3.3 when I run the code
>>>from
>>>>>RStudio (the most recent one).
>>>>>
>>>>>George
>>>>>
>>>>> [[alternative HTML version deleted]]
>>>>>
>>>>>______________________________________________
>>>>>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>>>>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