[R] Can 'mosaic' be used with a continuous variable?
friendly at yorku.ca
Thu Sep 15 15:04:42 CEST 2011
On 9/14/2011 2:10 PM, Mauricio Cornejo wrote:
> Thanks Z.
> Let me clarify my problem a bit further ... as I don't think I could use cut() or spine() to solve it.
> I have a data frame with three columns (A, B, Value). 'A' and 'B' are categorical and 'Value' is continuous and non-negative. I'm looking to make a mosaic plot with A on one axis and B on the other. The size (i.e. area) of the tiles would correspond to the proportion of the total Value represented by the given combinations of the levels of A and B.
> Thanks again,
I think what you are looking for is called a TreeMap -- a plot of a
single continuous variable broken down by two or more categorical
variables (which need not be crossed, as in a contingency table).
Typically, the Value is shown as the size (area) of the tile for each
leaf of the tree.
for some simple examples in R
> From: Achim Zeileis<Achim.Zeileis at uibk.ac.at>
> Cc: "r-help at r-project.org"<r-help at r-project.org>
> Sent: Wednesday, September 14, 2011 1:45 PM
> Subject: Re: [R] Can 'mosaic' be used with a continuous variable?
> On Wed, 14 Sep 2011, Mauricio Cornejo wrote:
>> I'm wondering if the 'mosaic' plot of the vcd package (or any other function for that matter) can be used with a continuous variable that should be represented via various categorical variables.? All the documentation I've read lead me to believe that it only works with counts of categories.
>> Alternatively, I've thought of first creating a contingency table where the frequencies would really be the values of my continuous variable as opposed to counts ... but I don't know how to do that.
> Well, you can always use cut() to create a categorical variable from a continuous variable. But you have to do that in advance before calling mosaic().
> For a bivariate display with a continuous x and a categorical y, you can use spine() which does the categorization for you.
>> Any insight would be appreciated.
>> [[alternative HTML version deleted]]
> [[alternative HTML version deleted]]
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street Web: http://www.datavis.ca
Toronto, ONT M3J 1P3 CANADA
More information about the R-help