how to draw paired mosaic plot?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

how to draw paired mosaic plot?

laomeng_3
Hi all:
If there are two numeric variable:x,y, and I can get paired scatter plot by function "pairs".But if x and y are character, and I want to get paired mosaic plot,which function should be used then?


Many thanks!
My best.






--
QQ: 1733768559


        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to draw paired mosaic plot?

Duncan Murdoch-2
On 06/02/2015 6:46 AM, meng wrote:
> Hi all:
> If there are two numeric variable:x,y, and I can get paired scatter plot by function "pairs".But if x and y are character, and I want to get paired mosaic plot,which function should be used then?

Why not pairs, with a custom panel function?  There are examples on the
help page, though I don't think a mosaic plot is there.

Duncan Murdoch

>
>
> Many thanks!
> My best.
>
>
>
>
>
>
> --
> QQ: 1733768559
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to draw paired mosaic plot?

Hasan Diwan-2
In reply to this post by laomeng_3
The stats package has a mosaicplot function. Perhaps that would help? -- H

On 6 February 2015 at 03:46, meng <[hidden email]> wrote:

> Hi all:
> If there are two numeric variable:x,y, and I can get paired scatter plot
> by function "pairs".But if x and y are character, and I want to get paired
> mosaic plot,which function should be used then?
>
>
> Many thanks!
> My best.
>
>
>
>
>
>
> --
> QQ: 1733768559
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.
>



--
OpenPGP: https://hasan.d8u.us/gpg.key
Sent from my mobile device
Envoyé de mon portable

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to draw paired mosaic plot?

laomeng_3
In reply to this post by Duncan Murdoch-2
If both x and y are all character, paired scatter plot is a little bit strange I think.






--
QQ: 1733768559





At 2015-02-06 23:52:34,"Duncan Murdoch" <[hidden email]> wrote:

>On 06/02/2015 6:46 AM, meng wrote:
>> Hi all:
>> If there are two numeric variable:x,y, and I can get paired scatter plot by function "pairs".But if x and y are character, and I want to get paired mosaic plot,which function should be used then?
>
>Why not pairs, with a custom panel function?  There are examples on the
>help page, though I don't think a mosaic plot is there.
>
>Duncan Murdoch
>>
>>
>> Many thanks!
>> My best.
>>
>>
>>
>>
>>
>>
>> --
>> QQ: 1733768559
>>
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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.
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to draw paired mosaic plot?

Jim Lemon-4
Hi meng,
It's not too hard to get a mosaic plot of two character variables:

x<-sample(LETTERS[1:3],20,TRUE)
y<-sample(LETTERS[24:26],20,TRUE)
mosaicplot(table(x,y))

If you could tell us how the above is not what you want, perhaps a
better suggestion will appear.

Jim


On Sat, Feb 7, 2015 at 6:29 PM, meng <[hidden email]> wrote:

> If both x and y are all character, paired scatter plot is a little bit strange I think.
>
>
>
>
>
>
> --
> QQ: 1733768559
>
>
>
>
>
> At 2015-02-06 23:52:34,"Duncan Murdoch" <[hidden email]> wrote:
>>On 06/02/2015 6:46 AM, meng wrote:
>>> Hi all:
>>> If there are two numeric variable:x,y, and I can get paired scatter plot by function "pairs".But if x and y are character, and I want to get paired mosaic plot,which function should be used then?
>>
>>Why not pairs, with a custom panel function?  There are examples on the
>>help page, though I don't think a mosaic plot is there.
>>
>>Duncan Murdoch
>>>
>>>
>>> Many thanks!
>>> My best.
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> QQ: 1733768559
>>>
>>>
>>>      [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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.

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to draw paired mosaic plot?

laomeng_3
If there are many character variables,and I want to get the mosaic plot of every pair of each variable,how to do then?


If the variables are numeric, I can use pairs to get paired scatter plot.
But as to the character variables, how to get the "paired mosaic plot"?


Many thanks.





--
QQ: 1733768559





At 2015-02-07 17:04:26,"Jim Lemon" <[hidden email]> wrote:

>Hi meng,
>It's not too hard to get a mosaic plot of two character variables:
>
>x<-sample(LETTERS[1:3],20,TRUE)
>y<-sample(LETTERS[24:26],20,TRUE)
>mosaicplot(table(x,y))
>
>If you could tell us how the above is not what you want, perhaps a
>better suggestion will appear.
>
>Jim
>
>
>On Sat, Feb 7, 2015 at 6:29 PM, meng <[hidden email]> wrote:
>> If both x and y are all character, paired scatter plot is a little bit strange I think.
>>
>>
>>
>>
>>
>>
>> --
>> QQ: 1733768559
>>
>>
>>
>>
>>
>> At 2015-02-06 23:52:34,"Duncan Murdoch" <[hidden email]> wrote:
>>>On 06/02/2015 6:46 AM, meng wrote:
>>>> Hi all:
>>>> If there are two numeric variable:x,y, and I can get paired scatter plot by function "pairs".But if x and y are character, and I want to get paired mosaic plot,which function should be used then?
>>>
>>>Why not pairs, with a custom panel function?  There are examples on the
>>>help page, though I don't think a mosaic plot is there.
>>>
>>>Duncan Murdoch
>>>>
>>>>
>>>> Many thanks!
>>>> My best.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> QQ: 1733768559
>>>>
>>>>
>>>>      [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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.
>>>
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to draw paired mosaic plot?

Jim Lemon-4
Hi meng,
A basic display of mosaic plots for all pairs of variables isn't too
difficult, but you will probably want to make this a bit fancier. It
only displays the unique plots, unlike the "pairs" plot. Keep in mind
that "many" variables will mean many plots.

chardf<-data.frame(v1=sample(LETTERS[1:3],20,TRUE),
 v2=sample(LETTERS[4:6],20,TRUE),
 v3=sample(LETTERS[7:9],20,TRUE),
 v4=sample(LETTERS[10:12],20,TRUE))

mosaic_pairs<-function(x,...) {
 if(!is.data.frame(x) && !is.matrix(x))
  stop("x must be a 2D matrix or data frame")
 nvar<-dim(x)[2]
 paircomb<-combn(nvar,2)
 nplots<-dim(paircomb)[2]
 split.screen(figs=c(nvar-1,nvar-1))
 for(i in 1:nplots) {
  screen((paircomb[2,i]-1)+(paircomb[1,i]-1)*(nvar-1))
  maintitle<-
   paste(names(x)[paircomb[1,i]],"by",names(x)[paircomb[2,i]])
  par(mar=c(1,1,3,1))
  mosaicplot(table(x[[paircomb[2,i]]],x[[paircomb[1,i]]]),
   main=maintitle,...)
 }
}

mosaic_pairs(chardf)

Jim


On Sun, Feb 8, 2015 at 1:50 AM, meng <[hidden email]> wrote:

> If there are many character variables,and I want to get the mosaic plot of
> every pair of each variable,how to do then?
>
> If the variables are numeric, I can use pairs to get paired scatter plot.
> But as to the character variables, how to get the "paired mosaic plot"?
>
> Many thanks.
>
>
>
>
> --
> QQ: 1733768559
>
>
>
> At 2015-02-07 17:04:26,"Jim Lemon" <[hidden email]> wrote:
>>Hi meng,
>>It's not too hard to get a mosaic plot of two character variables:
>>
>>x<-sample(LETTERS[1:3],20,TRUE)
>>y<-sample(LETTERS[24:26],20,TRUE)
>>mosaicplot(table(x,y))
>>
>>If you could tell us how the above is not what you want, perhaps a
>>better suggestion will appear.
>>
>>Jim
>>
>>
>>On Sat, Feb 7, 2015 at 6:29 PM, meng <[hidden email]> wrote:
>>> If both x and y are all character, paired scatter plot is a little bit
>>> strange I think.
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> QQ: 1733768559
>>>
>>>
>>>
>>>
>>>
>>> At 2015-02-06 23:52:34,"Duncan Murdoch" <[hidden email]> wrote:
>>>>On 06/02/2015 6:46 AM, meng wrote:
>>>>> Hi all:
>>>>> If there are two numeric variable:x,y, and I can get paired scatter
>>>>> plot by function "pairs".But if x and y are character, and I want to get
>>>>> paired mosaic plot,which function should be used then?
>>>>
>>>>Why not pairs, with a custom panel function?  There are examples on the
>>>>help page, though I don't think a mosaic plot is there.
>>>>
>>>>Duncan Murdoch
>>>>>
>>>>>
>>>>> Many thanks!
>>>>> My best.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> QQ: 1733768559
>>>>>
>>>>>
>>>>>      [[alternative HTML version deleted]]
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] 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.
>>>>
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>
>
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to draw paired mosaic plot?

Michael Friendly
In reply to this post by laomeng_3
You are looking for the pairs plot for table and other objects in the
vcd package:

  ?vcd::pairs.table

It allows you to use various panel functions for the diagonal and
off-diagonal plots

On 2/7/2015 9:50 AM, meng wrote:

> If there are many character variables,and I want to get the mosaic plot of every pair of each variable,how to do then?
>
>
> If the variables are numeric, I can use pairs to get paired scatter plot.
> But as to the character variables, how to get the "paired mosaic plot"?
>
>
> Many thanks.
>
>
>
>
>
> --
> QQ: 1733768559
>
>
>
>
>
> At 2015-02-07 17:04:26,"Jim Lemon" <[hidden email]> wrote:
>> Hi meng,
>> It's not too hard to get a mosaic plot of two character variables:
>>
>> x<-sample(LETTERS[1:3],20,TRUE)
>> y<-sample(LETTERS[24:26],20,TRUE)
>> mosaicplot(table(x,y))
>>
>> If you could tell us how the above is not what you want, perhaps a
>> better suggestion will appear.
>>
>> Jim
>>
>>
>> On Sat, Feb 7, 2015 at 6:29 PM, meng <[hidden email]> wrote:
>>> If both x and y are all character, paired scatter plot is a little bit strange I think.
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>> QQ: 1733768559
>>>
>>>
>>>
>>>
>>>
>>> At 2015-02-06 23:52:34,"Duncan Murdoch" <[hidden email]> wrote:
>>>> On 06/02/2015 6:46 AM, meng wrote:
>>>>> Hi all:
>>>>> If there are two numeric variable:x,y, and I can get paired scatter plot by function "pairs".But if x and y are character, and I want to get paired mosaic plot,which function should be used then?
>>>>
>>>> Why not pairs, with a custom panel function?  There are examples on the
>>>> help page, though I don't think a mosaic plot is there.
>>>>
>>>> Duncan Murdoch
>>>>>
>>>>>
>>>>> Many thanks!
>>>>> My best.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> QQ: 1733768559
>>>>>
>>>>>
>>>>>       [[alternative HTML version deleted]]
>>>>>
>>>>> ______________________________________________
>>>>> [hidden email] 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.
>>>>
>>>
>>>          [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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.
>
> [[alternative HTML version deleted]]
>


--
Michael Friendly     Email: friendly AT yorku DOT ca
Professor, Psychology Dept. & Chair, Quantitative Methods
York University      Voice: 416 736-2100 x66249 Fax: 416 736-5814
4700 Keele Street    Web:   http://www.datavis.ca
Toronto, ONT  M3J 1P3 CANADA

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: how to draw paired mosaic plot?

laomeng_3
Many thanks.





--
QQ: 1733768559





At 2015-02-08 23:01:09,"Michael Friendly" <[hidden email]> wrote:

>You are looking for the pairs plot for table and other objects in the
>vcd package:
>
>  ?vcd::pairs.table
>
>It allows you to use various panel functions for the diagonal and
>off-diagonal plots
>
>On 2/7/2015 9:50 AM, meng wrote:
>> If there are many character variables,and I want to get the mosaic plot of every pair of each variable,how to do then?
>>
>>
>> If the variables are numeric, I can use pairs to get paired scatter plot.
>> But as to the character variables, how to get the "paired mosaic plot"?
>>
>>
>> Many thanks.
>>
>>
>>
>>
>>
>> --
>> QQ: 1733768559
>>
>>
>>
>>
>>
>> At 2015-02-07 17:04:26,"Jim Lemon" <[hidden email]> wrote:
>>> Hi meng,
>>> It's not too hard to get a mosaic plot of two character variables:
>>>
>>> x<-sample(LETTERS[1:3],20,TRUE)
>>> y<-sample(LETTERS[24:26],20,TRUE)
>>> mosaicplot(table(x,y))
>>>
>>> If you could tell us how the above is not what you want, perhaps a
>>> better suggestion will appear.
>>>
>>> Jim
>>>
>>>
>>> On Sat, Feb 7, 2015 at 6:29 PM, meng <[hidden email]> wrote:
>>>> If both x and y are all character, paired scatter plot is a little bit strange I think.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> QQ: 1733768559
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> At 2015-02-06 23:52:34,"Duncan Murdoch" <[hidden email]> wrote:
>>>>> On 06/02/2015 6:46 AM, meng wrote:
>>>>>> Hi all:
>>>>>> If there are two numeric variable:x,y, and I can get paired scatter plot by function "pairs".But if x and y are character, and I want to get paired mosaic plot,which function should be used then?
>>>>>
>>>>> Why not pairs, with a custom panel function?  There are examples on the
>>>>> help page, though I don't think a mosaic plot is there.
>>>>>
>>>>> Duncan Murdoch
>>>>>>
>>>>>>
>>>>>> Many thanks!
>>>>>> My best.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> QQ: 1733768559
>>>>>>
>>>>>>
>>>>>>       [[alternative HTML version deleted]]
>>>>>>
>>>>>> ______________________________________________
>>>>>> [hidden email] 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.
>>>>>
>>>>
>>>>          [[alternative HTML version deleted]]
>>>>
>>>> ______________________________________________
>>>> [hidden email] 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.
>>
>> [[alternative HTML version deleted]]
>>
>
>
>--
>Michael Friendly     Email: friendly AT yorku DOT ca
>Professor, Psychology Dept. & Chair, Quantitative Methods
>York University      Voice: 416 736-2100 x66249 Fax: 416 736-5814
>4700 Keele Street    Web:   http://www.datavis.ca
>Toronto, ONT  M3J 1P3 CANADA

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.