[R] mosaic plot with two factors and one continous variable
Achim.Zeileis at wu-wien.ac.at
Mon May 4 18:37:51 CEST 2009
On Mon, 4 May 2009, Karsten Weinert wrote:
> my dataset is already aggregated: I have two categorical variables, say
> "continent" and "country" and one non-negative metric variable "population".
> Now I would like to produce a mosaic plot which uses "population" to
> determine how large each area of the plot is.
> In other words, I fail to find out
> - how to use the mosaic function of the vcd package without using table,
> - or I do not know how to convert my dataset into a table (as.table fails)
> As an example, here a simple dataset:
> Continent; Country; Population
> Europe; France; 65
> Europe; Germany; 80
> Africa; Algeria; 32
> Can you help me to get started?
You can create the tables by
xtabs(Population ~ Continent, data = mydata)
etc. which can then be visualized using mosaic() in the usual way.
> Kind regards,
> [[alternative HTML version deleted]]
> R-help at r-project.org mailing list
> 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