[R] dotplot with library lattice

Richard M. Heiberger rmh at temple.edu
Sat Oct 25 06:06:55 CEST 2014


## My interpretation is that KOST is a categorical budget code id, and
## not an amount of currency.  This is based on both you and Jim using
## even spacing for the rows of the dotplot.  Your first line of the
## email said barplot, so my example uses likert in the HH package
## which is built on barchart in the lattice package.

## Your example shows negative IST, IST larger than budget, and
## negative budgets.  My solution handles the first two cases.
## It forces the percents for the negative budget to zero.

## install.packages("HH")  ## if necessary

mwdat <- read.table(text=
"KOST                  Budget        IST
1060                 -2.18          0
1080                  91037.71   91647.15
1100                  955573.87  907938.98
1120                  23326.8          0
1150                 2521.57          0
1180                 51302.03   48760.45
1200                  2027.04    -1667.5
1210                 2385.03    2386.06
1220                       0          0
1250                  528.87          0
1255                 766.54          0
1260                 12154.97    4861.41",
 header=TRUE)

mwdat3 <- with(mwdat,
               data.frame(KOST=KOST,
                          ISTneg=pmax(0, -IST),
                          IST=pmax(IST, 0),
                          BudgetNotAttained=pmax(0, Budget-IST),
                          OverBudget=pmax(0, IST-Budget),
                          Budget=Budget))
mwdat3percent <- mwdat3
BudgetNonzero <- mwdat3$Budget != 0
mwdat3percent[BudgetNonzero, 2:5] <- 100 * (mwdat3percent[BudgetNonzero, 2:5] /
                                              mwdat3percent[BudgetNonzero, 6])
BudgetNegative <- mwdat3$Budget < 0
mwdat3percent[BudgetNegative, 2:5] <- 0
ISTneg <- mwdat3percent$ISTneg > 0
mwdat3percent$BudgetNotAttained[ISTneg] <- 100

ISTcolors <- likertColor(nc=6, ReferenceZero=1.5)[c(1,3,2,6)]

likert(KOST ~ ISTneg + IST + BudgetNotAttained + OverBudget,
       data=mwdat3percent, ReferenceZero=1.5,
       col=ISTcolors,
       xlab="Percent of Budget", xlimEqualLeftRight=TRUE,
       rightAxisLabels=mwdat3$Budget, ylab.right="Budget",
       par.settings=list(layout.widths=list(axis.right=1.5))) +
         layer(panel.abline(v=100, col="gray65"), under=TRUE)

On Fri, Oct 24, 2014 at 9:27 PM, Jim Lemon <jim at bitwrit.com.au> wrote:
> On Fri, 24 Oct 2014 12:49:39 PM Matthias Weber wrote:
>>
>> I want always to see the "Process" of the green button in
> dependence
>> of the blue button at 100%.
>
> Okay.
>
> mwdat<-read.table(text=
> "KOST                  Budget        IST
> 1060                 -2.18          0
> 1080                  91037.71   91647.15
> 1100                  955573.87  907938.98
> 1120                  23326.8          0
> 1150                 2521.57          0
> 1180                 51302.03   48760.45
> 1200                  2027.04    -1667.5
> 1210                 2385.03    2386.06
> 1220                       0          0
> 1250                  528.87          0
> 1255                 766.54          0
> 1260                 12154.97    4861.41
> Gesamtbudget 1141622.25 1054236.55",
>  header=TRUE)
> par(las=1,mar=c(5,7,4,6))
> plot(rep(100,13),1:13,main="IST against Budget",
>  xlab="IST/Budget (prozent)",ylab="KOST",
>  xlim=c(0,100),type="n",yaxt="n")
> abline(h=1:13,lty=2,col="lightgray")
> points(rep(100,13),1:13,pch=19,col="blue",cex=3)
> mwdat$ISTpct<-100*mwdat$IST/mwdat$Budget
> # fix divide by zero
> mwdat$ISTpct[9]<-0
> points(mwdat$ISTpct,1:13,pch=19,col="green",cex=3)
> legend(105,10,c("Budget","IST"),pch=19,
>  col=c("blue","green"),bty="n",xpd=TRUE)
> axis(2,at=1:13,labels=mwdat$KOST)
> par(las=0,mar=c(5,4,4,2))
>
> Jim
>
> ______________________________________________
> 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