[R] Error when using plot in diag.panel argument of pairs

Uwe Ligges ligges at statistik.tu-dortmund.de
Sat Jul 2 17:42:09 CEST 2011


OK, so let me make it reproducible and start with

myTable <- iris
require("MASS")


On 02.07.2011 17:09, "Patrick Großmann" wrote:
> Dear Mr. Ligges,
>
>   my apologies! As I can see in your E-Mail the quote of mine is really  just unreadable! Anyhow, this was not produced by me writing messy  messages, this is due to the Java application behind the client not  being able to cope with external tab-characters on my browser when  parsing the message while sending(I tipped the message on an external  editor because of the code lines and copy pasted it). Of course I also  never would add any html files!
>
>   Anyhow, I send you my original message again (new = True did not help  me. Assuming I used it the way you suggested it produced the same  error). I send it to myself first, so I am sure, this mess won't happen  again!
>
>   My previous Message:
>
>   #########
>   Dear Madame or Sir,
>
>   I am having a problem in combining density-smoothed scatterplot matrices  with a plot of kernel destiny estimations of each dimension plotted on  the respective diagonals.
>
>   I have tried following approach using the package "sm" for the kernel density estimation, as well as "MASS" respectively:
>
>   pairs
>   (myTable[, 1:4],
>       panel=function(x,y, ...)
>       {
>           xy=kde2d(x,y)
>           image(xy, add=TRUE)
>       }
>       ,diag.panel = function(x,...)
>       {
>           plot(density(x,...), add = TRUE)
>           #boxplot(x, add = TRUE)
>       }
>   )


Now we could go with:

pairs(myTable[, 1:4],
     panel=function(x,y, ...)
     {
         xy <- kde2d(x,y)
         image(xy, add=TRUE)
     },
     diag.panel = function(x,...)
     {
         pu <- par("usr")
         d <- density(x,...)
         par("usr" = c(pu[1:2], 0, max(d$y)*1.5))
         lines(d)
         par("usr" = c(pu[1:2], 0, 1))
         boxplot(x, at=0.5, boxwex=0.3, horizontal=TRUE, add=TRUE)
      }
)


Uwe Ligges



>   where myTable is an ordinary table I am using the first four columns of.  Unfortunately this produces an error stating that plot has created a  new plot. I suppose this is the same situation when forgetting "add  =  TRUE" with plotting functions such as boxplot (as in my code used with  "boxplot(x, add = TRUE)" ) or any other (e.g. smoothScatter). Analyzing  the partial plot,  which can be seen before R rejects my code, I come to  the conclusion that add might not be a valid argument for "plot".
>    My questions therefore is, whether there is an option to plot the  result of the 1d kernel density estimation to the diagonal of the  scatterplot produced by pairs or which plot function is valid in this  case. So basically I would like to generate the same output I am able to  produce with boxplots on the diagonal with a density estimation.
>
>   Additional question: I bet there is an opportunity to include both the  boxplot and the kernel density estimation on each field of the diagonal  (as I saw before in a published paper), but I just could not figure out  how to "overdraw". Maybe you could give me a slight idea (reference  would be fine, too) on how to achieve this. I would be highly thankful!
>
>
>   Kind regards and many thanks in advance,
>   -Patrick Grossman
>
>   ##############
>
>   Please excuse the inconvenience and note my thanks.
>
>   Warmest regards,
>   -Patrick Grossman
>
> ----- Ursprüngliche Nachricht -----
> Von: Uwe Ligges<ligges at statistik.tu-dortmund.de>
> Datum: Samstag, 2. Juli 2011, 16:36
> Betreff: Re: [R] Error when using plot in diag.panel argument of pairs
> An: Patrick Großmann<patrick.grossmann at uni-bielefeld.de>
> Cc: r-help at r-project.org
>
>> If you send a better readable message with really reproducible
>> code, we
>> may provide a solution, this way it is really hard to read your
>> code.
>> And yes, please do not send html mail. My guess is that
>> par(new=TRUE)
>> will help, but I do not want to construct the examples at first.
>>
>>
>>
>>
>> On 02.07.2011 14:37, "Patrick Großmann" wrote:
>>>    Dear Madame or Sir,I am having a problem in
>> combining density-smoothed scatterplot matrices with a plot of
>> kernel destiny estimations of each dimension plotted on the
>> respective field of the diagonal.I have tried following approach
>> using the package "sm" for the kernel density estimation, as
>> well as "MASS" respectively:pairs(myTable[,
>> 1:4],panel=function(x,y, ...){
>> xy=kde2d(x,y)     image(xy,
>> add=TRUE)},diag.panel = function(x,...){plot(density(x), add =
>> TRUE)#boxplot(x, add = TRUE)})where myTable is an ordinary table
>> I am using the first four columns of. Unfortunately this
>> produces an error stating that plot has created a new plot. I
>> suppose this is the same situation when forgetting "add  =
>> TRUE" with plotting functions such as boxplot (as in my code
>> used with "boxplot(x, add = TRUE)" ) or any other (e.g.
>> smoothScatter). Analyzing the partial plot,  which can be
>> seen before R rejects my code, I come to the conclusion that add
>> might not be a valid argument for "plot
>> ". My questions therefore is, whether there is an option to plot
>> the result of the 1d kernel density estimation to the diagonal
>> of the scatterplot produced by pairs or which plot function is
>> valid in this case. So basically I would like to generate the
>> same output I am able to produce with boxplots on the diagonal
>> with a density estimation.Additional question: I bet there is an
>> opportunity to include both the boxplot and the kernel density
>> estimation on each field of the diagonal (as I saw before in a
>> published paper), but I just could not figure out how to
>> "overdraw". Maybe you could give me a slight idea (reference
>> would be fine, too) on how to achieve this. I would be highly
>> thankful!Kind regards and many thanks in advance,-Patrick
>> Grossman --
>>> Patrick Großmann - HiWi zur Netzwerkdokumentation
>>> Network Operation Center    NOC
>>> Hochschulrechenzentrum    HRZ
>> Universität Bielefeld
>>>
>>> Büro:
>>> UHG V0-251
>>> Telefon:
>>> +49 521 106-12618
>>> Fax:
>>> +49 521 106-2969
>>> Telefon Sekretariat:
>>> +49 521 106-4951
>>>
>>> http://www.uni-bielefeld.de/hrz/
>>>
>>>
>>>
>>> 	[[alternative HTML version deleted]]
>>>
>>>
>>>
>>>
>>> ______________________________________________
>>> 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.
>
> --
> Patrick Großmann - HiWi zur Netzwerkdokumentation
> Network Operation Center    NOC
> Hochschulrechenzentrum    HRZ    Universität Bielefeld
>
> Büro:
> UHG V0-251
> Telefon:
> +49 521 106-12618
> Fax:
> +49 521 106-2969
> Telefon Sekretariat:
> +49 521 106-4951
>
> http://www.uni-bielefeld.de/hrz/
>
>
>



More information about the R-help mailing list