[R] Presentation of data in Graphical format

Petr PIKAL petr.pikal at precheza.cz
Thu Nov 19 07:59:35 CET 2009


Well, from what you say it seems to me that you could also use Pareto 
charts together with some aggregation of data. But it depends on what you 
want to show to your audience. Below is some code which I slightly adapted 
form original author.

Regards
Petr

#----------------------------------------------------------------------------------------------------------------------
# pareto. Produces a Pareto plot of effects. 
# 
# Parameters: 
# effects - vector or matrix of effects to plot. 
# names - vector of names to label the effects. 
# xlab - String to display as the x axis label. 
# ylab - String to display as the y axis label. 
# perlab - Label for the cumulative percentage label. 
# heading - Vector of names for plot heading. 
# 
pareto <- function(effects, names=NULL, xlab=NULL, ylab="Magnitude of 
Effect", indicate.percent=TRUE, perlab="Cumulative Percentage", 
heading=NULL, trunc.perc=.95, long.names=FALSE,...) 
{ 
        # set up graphics parameters, note: set las=2 for perpendicular 
axis. 
        oldpar <- par( mar=c(6, 4, 2, 4) + 0.1 , las=3) 
        on.exit(par(oldpar)) 
 
        if( ! is.matrix(effects)) effects<-as.matrix( effects ) 
 
        for( i in 1:ncol(effects) ) 
        { 
 
                if( i==2 ) oldpar$ask<-par(ask=TRUE)$ask 
                # draw bar plot 
                eff.ord <- rev(order(abs(effects[,i]))) 
                ef <- abs(effects[eff.ord,i]) 
                names<-as.character(names)[eff.ord]
                # plot barplot 

                        # get cumulative sum of effects 
                        sumeff <- cumsum(ef) 
                        m<-max(ef) 
                        sm<-sum(ef) 
                        sumeff <- sumeff/sm

                vyber<-sumeff>trunc.perc
                suma.ef<-sum(ef[vyber])
                sumeff<-c(sumeff[!vyber],1)*m
                ef<-c(ef[!vyber],suma.ef)
                names<-c(as.character(names[!vyber]),"Dalsi")
                ylimit<-max(ef) + max(ef)*0.19 
                ylimit<-c(0,ylimit) 
                par( mar=c(6, 4, 2, 4) + 0.1 , las=3) 
 
        if (long.names) {
        x<- barplot(ef, names.arg=names, ylim=ylimit, xlab=xlab, 
ylab=ylab, main=heading[i], plot=F, ...)
        x<- barplot(ef, ylim=ylimit, xlab=xlab, ylab=ylab, 
main=heading[i], ...)
        text(x,ylimit[2]/10, names, srt=90, adj=0, cex=.7)} else {

                x<-barplot(ef, names.arg=names, ylim=ylimit, xlab=xlab, 
ylab=ylab, main=heading[i], ...) 
                }


                if( indicate.percent == TRUE ){ 



                        # draws curve. 
                        lines(x, sumeff, lty="solid", lwd=2, col="purple") 

                        # draw 80% line 
                        lines( c(0,max(x)), rep(0.8*m,2) ) 
                        # draw axis labling percentage. 
                        at <- c(0:5)* m/5 
                        axis(4, at=at, 
labels=c("0","20","40","60","80","100"), pos=max(x)+.6) 
                        # add axis lables 
                        par(las=0) 
                        mtext(perlab, 4, line=2) 
                } 
 
        } # end for each col 
} 


#Don Wingate 


r-help-bounces at r-project.org napsal dne 18.11.2009 16:17:32:

> yes in my data the 1st column is the main category say suppose 
"Secretary"
> the second column is the sub category "HR Dept" the 3rd column is the 
list
> of duties performed by the Secretary from HR dept and 4th column is time
> required to perform the duty
> 
> so there are many such posts and dept with varied duties and times resp.
> 
> Regards
> 
> Our Thoughts have the Power to Change our Destiny.
> Sunita
> 
> 
> On Wed, Nov 18, 2009 at 8:42 PM, Petr PIKAL <petr.pikal at precheza.cz> 
wrote:
> 
> > Hi
> >
> > r-help-bounces at r-project.org napsal dne 18.11.2009 16:01:27:
> >
> > > Yes I tried all the basic ones like box plot, pie chart, etc but the
> > data
> > > representation isnt that clear.
> > >
> >
> > I agree with Tal. But it partly depends on your data. If you have many
> > levels and only few time values in each boxplot would not look well. 
Maybe
> > you could check also ?xtabs or ?table and/or R graph gallery
> > http://addictedtor.free.fr/graphiques/ if you find suitable graph.
> >
> > Regards
> > Petr
> >
> >
> >
> > >
> > > Regards
> > >
> > > Our Thoughts have the Power to Change our Destiny.
> > > Sunita
> > >
> > >
> > > On Wed, Nov 18, 2009 at 7:20 PM, Tal Galili <tal.galili at gmail.com>
> > wrote:
> > >
> > > > I would start with
> > > > ?boxplot
> > > >
> > > >
> > > > ----------------------------------------------
> > > >
> > > >
> > > > My contact information:
> > > > Tal Galili
> > > > E-mail: Tal.Galili at gmail.com
> > > > Phone number: 972-52-7275845
> > > > FaceBook: Tal Galili
> > > > My Blogs:
> > > > http://www.talgalili.com (Web and general, Hebrew)
> > > > http://www.biostatistics.co.il (Statistics, Hebrew)
> > > > http://www.r-statistics.com/ (Statistics,R, English)
> > > >
> > > >
> > > >
> > > >
> > > > On Wed, Nov 18, 2009 at 2:47 PM, Sunita Patil 
<sunitap22 at gmail.com>
> > wrote:
> > > >
> > > >> Thanx
> > > >>
> > > >> but I am not able to find a graph that wud suit my data
> > > >>
> > > >> Regards
> > > >>
> > > >> Our Thoughts have the Power to Change our Destiny.
> > > >> Sunita
> > > >>
> > > >>
> > > >> On Sun, Nov 15, 2009 at 8:54 PM, milton ruser 
<milton.ruser at gmail.com
> > > >> >wrote:
> > > >>
> > > >> > Google "R graph grallery"
> > > >> > Google "R ggplot2"
> > > >> > Google "R lattice"
> > > >> >
> > > >> > and good luck
> > > >> >
> > > >> > milton
> > > >> > On Sun, Nov 15, 2009 at 7:48 AM, Sunita22 <sunitap22 at gmail.com>
> > wrote:
> > > >> >
> > > >> >>
> > > >> >> Hello
> > > >> >>
> > > >> >> My data contains following columns:
> > > >> >>
> > > >> >> 1st column: Posts (GM, Secretary, AM, Office Boy)
> > > >> >> 2nd Column: Dept (Finance, HR, ...)
> > > >> >> 3rd column: Tasks (Open the door, Fix an appointment, Fill the
> > > >> register,
> > > >> >> etc.....) depending on the post
> > > >> >> 4th column: Average Time required to do the task
> > > >> >>
> > > >> >> So the sample data would look like
> > > >> >> Posts            Dept        Task Average
> > time
> > > >> >> Office Boy      HR           Open the door          00:00:09
> > > >> >> Secretary       Finance    Fix an appointment    00.00.30
> > > >> >> ....                .....          ..... .....
> > > >> >>
> > > >> >> I am trying to represent this data in Graphical format, I 
tried
> > graphs
> > > >> >> like
> > > >> >> Mosaic plot, etc. But it does not represent the data 
correctly. My
> > aim
> > > >> is
> > > >> >> to
> > > >> >> check the "amount of time and its variability for groups of 
tasks"
> > > >> >>
> > > >> >> Thank you in advance
> > > >> >> Regards
> > > >> >> Sunita
> > > >> >>
> > > >> >> --
> > > >> >> View this message in context:
> > > >> >>
> > > >> http://old.nabble.com/Presentation-of-data-in-Graphical-format-
> > > tp26358857p26358857.html
> > > >> >> Sent from the R help mailing list archive at Nabble.com.
> > > >> >>
> > > >> >> ______________________________________________
> > > >> >> 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.
> > > >> >>
> > > >> >
> > > >> >
> > > >>
> > > >>        [[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
> > > >> and provide commented, minimal, self-contained, reproducible 
code.
> > > >>
> > > >
> > > >
> > >
> > >    [[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
> > > and provide commented, minimal, self-contained, reproducible code.
> >
> >
> 
>    [[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
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list