[R] Creating a Clustered-Stacked Column Chart

Peter Ehlers ehlers at ucalgary.ca
Sun Oct 11 14:14:07 CEST 2009



zhijie zhang wrote:
>   Thanks for your ideas and suggestions. I need to point out that most of us
> will create the Clustered-Stacked Column Chart in the matrix layout as David
> gave above, but here i hope to display the graph side by side as the example
> in the link http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html,
> which may be not a good method to display the information.
>    Actually, i browsed the lattice package and re-run the examples in its
> help before posting this question. As John said above, "I don't think I've
> seen an R version, probably because the technique is not very good for
> displaying data.".
>   Following Peter's suggestion, i browsed the layout= argument in the link
> http://www.stat.ucl.ac.be/ISdidactique/Rhelp/library/lattice/html/xyplot.html
> and
> tried it, but cannot successfully get the correct graph.
> 
> library(lattice)
> barchart(Titanic, scales = list(x = "free"),auto.key = list(title =
> "Survived"))
> barchart(Titanic, scales = list(x = "free"),auto.key = list(title =
> "Survived"),layout=c(2,1))  #missed the children's graph
> barchart(Titanic, scales = list(x = "free"),auto.key = list(title =
> "Survived"),layout=c(1,2))  #missed the children's graph
>   Thanks a lot.

Didn't miss anything. It just produced two pages. Try it with plot
recording turned on.

This should be close to what you want:

   barchart(Titanic, scales = list(x = "free"),
     layout = c(4,1),
     horizontal = FALSE,
     auto.key = list(title = "Survived"))

  -Peter Ehlers

> 
> 2009/10/10 Peter Ehlers <ehlers at ucalgary.ca>
> 
>> I think you're missing the point. David _did_ show you how
>> to create a graph showing 4 clusters of stacked barcharts.
>> If you want them side-by-side instead of in the matrix
>> layout David gave, use the layout= argument.
>>
>>  -Peter Ehlers
>>
>> zhijie zhang wrote:
>>
>>>  Hi David,
>>>  Your codes are for stacked chart. Actually, i hope to Create a
>>> Clustered-Stacked Column Chart, which means that a chart will combine the
>>> traits of stacked chart and clustered chart, see the example in the page
>>> http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html.
>>>  Thanks.
>>> 2009/10/10 David Winsemius <dwinsemius at comcast.net>
>>>
>>>   library(lattice)
>>>> barchart(Titanic, scales = list(x = "free"),
>>>>         auto.key = list(title = "Survived"))
>>>>
>>>> Or if you prefer vertical:
>>>>
>>>> barchart(Titanic, scales = list(x = "free"),
>>>>        auto.key = list(title = "Survived"), horizontal=FALSE)
>>>>
>>>> There are adjustments available to the space between bars.
>>>>
>>>> barchart(Titanic, scales = list(x = "free"),
>>>>        auto.key = list(title = "Survived"), horizontal=FALSE,
>>>> box.ratio=100)
>>>>
>>>>
>>>>
>>>> On Oct 9, 2009, at 9:57 PM, zhijie zhang wrote:
>>>>
>>>>  Thanks a lot. Maybe someone else has the method to solve that.
>>>>
>>>>> 2009/10/9 John Kane <jrkrideau at yahoo.ca>
>>>>>
>>>>>  I don't think I've seen an R version, probably because the technique is
>>>>>
>>>>>> not
>>>>>> very good for displaying data.
>>>>>>
>>>>>> Have a look at http://chartsgraphs.wordpress.com/tag/r-and-excel/ for
>>>>>> an
>>>>>> alternative method of displaying the data using lattice.
>>>>>>
>>>>>> --- On Fri, 10/9/09, zhijie zhang <rusers.sh at gmail.com> wrote:
>>>>>>
>>>>>> From: zhijie zhang <rusers.sh at gmail.com>
>>>>>>
>>>>>>> Subject: [R] Creating a Clustered-Stacked Column Chart
>>>>>>> To: r-help at stat.math.ethz.ch
>>>>>>> Received: Friday, October 9, 2009, 5:31 AM
>>>>>>> Hi all,
>>>>>>>  In R, is there some functions or ways to
>>>>>>> create a Clustered-Stacked
>>>>>>> Column Chart as the example in the following page
>>>>>>> http://peltiertech.com/Excel/ChartsHowTo/ClusterStack.html?
>>>>>>>  I have browsed the R Graph Gallery (
>>>>>>>
>>>>>>> http://addictedtor.free.fr/graphiques/)
>>>>>> and searched the R site, and didnot find an appropriate
>>>>>>> method to do it.
>>>>>>>  Anybody has met this problem before?
>>>>>>>  Thanks a lot.
>>>>>>>
>>>>>>>  [[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<http://www.r-project.org/posting-guide.html>
>>>>>> <http://www.r-project.org/posting-guide.html>
>>>>>> <http://www.r-project.org/posting-guide.html>
>>>>>>
>>>>>> and provide commented, minimal, self-contained,
>>>>>>> reproducible code.
>>>>>>>
>>>>>>>
>>>>>>>   __________________________________________________________________
>>>>>> Get the name you've always wanted @ymail.com or @rocketmail.com! Go to
>>>>>> http://ca.promos.yahoo.com/jacko/
>>>>>>
>>>>>>
>>>>>>       [[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<http://www.r-project.org/posting-guide.html>
>>>>> <http://www.r-project.org/posting-guide.html>
>>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>>
>>>>> David Winsemius, MD
>>>> Heritage Laboratories
>>>> West Hartford, CT
>>>>
>>>>
>>>>
>>>        [[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<http://www.r-project.org/posting-guide.html>
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>>
>




More information about the R-help mailing list