Simon Kiss
2010-Jul-19 13:36 UTC
[R] Grouping and stacking bar plot for categorical variables
Hi all, I have a series of cateogiral variables that look just like this: welfare=sample(c("less", "same", "more"), 1000, replace=TRUE) education=sample(c("less", "same", "more"), 1000, replace=TRUE) defence=sample(c("less", "same", "more"), 1000, replace=TRUE) egp=sample(c("salariat", "routine non-manual", "self-employed, farmers", "skilled labour, foremen", "unskilled labour", "social and cultural specialists"), 1000, replace=TRUE) welfare, education and defence are responses to a series of questions about whether or not the respondent supports, less, the same or more spending on an issue. egp is a class category. What I would like is a barplot that is both stacked and grouped. The x-axis categories should be the egp class category. Within each class category I would like a cluster of stacked bars that show the distribution of spending support for each issue. Can anyone suggest something? Yours, Simon Kiss ********************************* Simon J. Kiss, PhD SSHRC and DAAD Post-Doctoral Fellow John F. Kennedy Institute of North America Studies Free University of Berlin Lansstra?e 7-9 14195 Berlin, Germany Cell: +49 (0)1525-300-2812, Web: http://www.jfki.fu-berlin.de/index.html
David Winsemius
2010-Jul-19 13:44 UTC
[R] Grouping and stacking bar plot for categorical variables
On Jul 19, 2010, at 9:36 AM, Simon Kiss wrote:> Hi all, > I have a series of cateogiral variables that look just like this: > > welfare=sample(c("less", "same", "more"), 1000, replace=TRUE) > education=sample(c("less", "same", "more"), 1000, replace=TRUE) > defence=sample(c("less", "same", "more"), 1000, replace=TRUE) > egp=sample(c("salariat", "routine non-manual", "self-employed, > farmers", "skilled labour, foremen", "unskilled labour", "social and > cultural specialists"), 1000, replace=TRUE) > > welfare, education and defence are responses to a series of > questions about whether or not the respondent supports, less, the > same or more spending on an issue. > > egp is a class category. > > What I would like is a barplot that is both stacked and grouped. > The x-axis categories should be the egp class category. Within each > class category I would like a cluster of stacked bars that show the > distribution of spending support for each issue. > > Can anyone suggest something?Learn to search: RSiteSearch("stacked barchart") Once you are there you can also ask for prior years' r-help searching which will provide a large number of worked examples since this has been a frequently asked (and answered) question. -- David.> Yours, Simon Kiss > > ********************************* > Simon J. Kiss, PhD > SSHRC and DAAD Post-Doctoral Fellow > John F. Kennedy Institute of North America Studies > Free University of Berlin > Lansstra?e 7-9 > 14195 Berlin, Germany > Cell: +49 (0)1525-300-2812, > Web: http://www.jfki.fu-berlin.de/index.html > > ______________________________________________ > 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.David Winsemius, MD West Hartford, CT
Jim Lemon
2010-Jul-20 08:55 UTC
[R] Grouping and stacking bar plot for categorical variables
On 07/19/2010 11:36 PM, Simon Kiss wrote:> Hi all, > I have a series of cateogiral variables that look just like this: > > welfare=sample(c("less", "same", "more"), 1000, replace=TRUE) > education=sample(c("less", "same", "more"), 1000, replace=TRUE) > defence=sample(c("less", "same", "more"), 1000, replace=TRUE) > egp=sample(c("salariat", "routine non-manual", "self-employed, farmers", > "skilled labour, foremen", "unskilled labour", "social and cultural > specialists"), 1000, replace=TRUE) > > welfare, education and defence are responses to a series of questions > about whether or not the respondent supports, less, the same or more > spending on an issue. > > egp is a class category. > > What I would like is a barplot that is both stacked and grouped. The > x-axis categories should be the egp class category. Within each class > category I would like a cluster of stacked bars that show the > distribution of spending support for each issue. > > Can anyone suggest something?Hi Simon, You might also like to look at the barNest function in the plotrix package, not stacked, but nested. Jim
Possibly Parallel Threads
- help calculating variable based on factor level of another
- Problem with recode -Error in parse(text = range[[1]][1]) : unexpected end of input in " c(0"
- generate irregular series of dates
- Finding different hues for a mosaic plot compatible with grayscale printing
- Comparing a 4-point and 5-point Likert scale