[R] dotplot with library lattice

Matthias Weber Matthias.Weber at fntsoftware.com
Fri Oct 24 12:49:39 CEST 2014


Hi Jim,

thanks for your reply.

Doesn't look very bad, but what I mean with "Budget 100", is the percentage of the process on the x-axis. As a example, the Budget for ""1120" is 23326.8. At the moment we have "0" as value for IST. In this case, the blue button should be stand at 100% (x-axis = process in %) on the right side and the green button is on the x-axis at 0 (left side), because the value is 0. If the value for "1120" rises up to 11663, the blue button is still at 100% on the right side (the blue button is in all cases on the right side) and the green button is right in the middle, because the Budget is 50% full.

I want always to see the "Process" of the green button in dependence of the blue button at 100%.

Maybe you can help me.

Thank you.

Best regards.

Mat

-----Ursprüngliche Nachricht-----
Von: Jim Lemon [mailto:jim at bitwrit.com.au]
Gesendet: Freitag, 24. Oktober 2014 11:29
An: r-help at r-project.org
Cc: Matthias Weber
Betreff: Re: [R] dotplot with library lattice

On Thu, 23 Oct 2014 05:57:27 PM Matthias Weber wrote:
> Hello together,
>
> i have a short question. Maybe anyone can help me to create a
barplot in R
> with the package lattice.
>
> I have the following data as ouput values and the following code:
>
> Data (d):
>
> 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
>
> Code:
>
> ### read the data
>
> d$KOST <- ordered( d$KOST, levels = d$KOST)
>
> ### load lattice and grid
> require( lattice )
>
>  ### setup the key
> k <- simpleKey( c( "Budget",  "IST" ) ) k$points$fill <- c("blue",
> "darkgreen") k$points$pch <- 21 k$points$col <- "black"
> k$points$cex <- 1
>
>  ### create the plot
> dotplot( KOST ~ Budget + IST , data = d, horiz = TRUE,
>      par.settings = list(
>          superpose.symbol = list(
>              pch = 21,
>              fill = c( "blue", "darkgreen"),
>              cex = 3,
>              col = "black"
>          )
>       ) , xlab = "Kostenstellenübersicht", key = k,
>       panel = function(x, y,  ...){
>         panel.dotplot( x, y, ... )
> #       grid.text(
>   #           unit( x, "native") , unit( y, "native") ,
>    #          label = x, gp = gpar( cex = .7 ) )
>       } )
>
> The result look like the attached graph. But this is not exactly what
> I want. I want the "Budget" on the right side (100), and the
> "IST"-Value
in
> dependence of the "Budget" between 0 and 100. As a example. If
there is a
> budget over 100.000 and the "IST"-Value ist around 50.000, the blue
button
> should be on the right side and the green button right in the middle.
>
> Maybe anyone can help me.
>
> Thank you.
>
> Best regards.
>
> Mat
>
>
Hi Mat,
I must admit that I have probably misunderstood your request. I have assumed that you want the Budget as the x axis and the KOST as the y axis. You seemed to be asking for Budget to be always 100 and that didn't make sense. For some reason the "scipen" option stopped working for me after the first plot and so I couldn't get rid of the scientific notation on the x axis. Also this was done in base graphics rather than lattice. I also left the "Gesamtbudget" (Total budget) out as it would have squeezed most of the dots even farther to the left.
However, it might help.

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)
options(scipen=4)
par(las=1)
plot(mwdat$Budget,mwdat$KOST,main="IST against Budget",  xlab="Budget",ylab="KOST",  xlim=range(mwdat$Budget),ylim=range(mwdat$KOST),
 type="n",yaxt="n")
abline(h=mwdat$KOST,lty=2,col="lightgray")
points(mwdat$Budget,mwdat$KOST,pch=19,col="blue",cex=3)
points(mwdat$IST,mwdat$KOST,pch=19,col="green",cex=3)
legend(400000,1250,c("Budget","IST"),pch=19,
 col=c("blue","green"),bty="n")
options(scipen=0)
axis(2,at=mwdat$KOST)
par(las=0)

Jim


This e-mail may contain trade secrets, privileged, undisclosed or otherwise confidential information. If you have received this e-mail in error, you are hereby notified that any review, copying or distribution of it is strictly prohibited. Please inform us immediately and destroy the original transmittal. Thank you for your cooperation.

Diese E-Mail kann Betriebs- oder Geschaeftsgeheimnisse oder sonstige vertrauliche Informationen enthalten. Sollten Sie diese E-Mail irrtuemlich erhalten haben, ist Ihnen eine Kenntnisnahme des Inhalts, eine Vervielfaeltigung oder Weitergabe der E-Mail ausdruecklich untersagt. Bitte benachrichtigen Sie uns und vernichten Sie die empfangene E-Mail. Vielen Dank.



More information about the R-help mailing list