Dear all, I use the barchart-function (lattice) for plotting stacked barcharts. The data is a summary table (data frame) of likert-scale-evaluations (strongly agree, agree...strongly disagree) to different issues constructed as follows (L1=precentage of "strongly agree" evaluations, L4=precentage of "strongly disagree" evaluations): --- ID L1 L2 L3 L4 DN Issue1 25 40 35 0 0 Issue2 15 30 22 28 5 . . . --- What I have so far not achieved is adding data labels to each "sub-bar" of a 100%-bar. What I would like to have is something like this: Issue1: |###25%###OOOOOO40%OOOOOOXXX35%XXX Issue2: | (similar) ... What should I do in oder to display data labels? Thanks in advance, Kimmo
On 4/21/08, K. Elo <maillists at nic.fi> wrote:> Dear all, > > I use the barchart-function (lattice) for plotting stacked barcharts. > The data is a summary table (data frame) of likert-scale-evaluations > (strongly agree, agree...strongly disagree) to different issues > constructed as follows (L1=precentage of "strongly agree" evaluations, > L4=precentage of "strongly disagree" evaluations): > --- > ID L1 L2 L3 L4 DN > Issue1 25 40 35 0 0 > Issue2 15 30 22 28 5 > . > . > . > --- > What I have so far not achieved is adding data labels to each "sub-bar" > of a 100%-bar. What I would like to have is something like this: > > Issue1: |###25%###OOOOOO40%OOOOOOXXX35%XXX > Issue2: | (similar) > ... > > What should I do in oder to display data labels?Write your own panel function (which may or may not be a simple exercise depending on your level of expertise in R). You could use panel.barchart as a starting point. Basically, you need to insert some calls to panel.text() (or something equivalent) after calls to panel.rect() that draw the bars. -Deepayan
Hi again, Deepayan Sarkar wrote (21.4.2008):> Write your own panel function (which may or may not be a simple > exercise depending on your level of expertise in R). You could use > panel.barchart as a starting point. Basically, you need to insert > some calls to panel.text() (or something equivalent) after calls to > panel.rect() that draw the bars.Thanks to Deepayan for his quick answer. Well, I am quite familiar with R programming, so programming would not be the issue. What is an issue is that I do not (yet) fully understand how the panel-function interacts with the calling barchart-function (or vice versa). My stacked bar is build of five variables [barchart(ID ~ L1+L2+L3+L4+DN ...) ] so the problem is that the data label to be displayed is either L1,2,3,4 or DN (for ID, see my first posting). So the question is: How could I use the current data value used for drawing the "sub-bar" as an argument/variable for/in the panel-function? Many thanks again & greetings, Kimmo