[R] Fwd: barchar and box on the same figure! is it possible

Jim Lemon jim at bitwrit.com.au
Fri Jan 10 12:16:29 CET 2014


On 01/10/2014 09:46 PM, Adel ESSAFI wrote:
> Hello list
>
> I have this data frame which represent values grouped by algorithm.
> remark that for each algorithm, we have the same value in V3 but differnt
> values in V4.
> I want to make a plot with algorithms in axes, and for each algorithm I
> draw a bar (for V3) and a bwplot for V4.
> is thart possible.
> Thanks for any entry.
>
>
>
>> t[t[,2]<3,]
>            V1 V2       V3       V4
> 1    HEFT-AC  1 402499.9 460543.4
> 2    HEFT-AC  2 402499.9 470316.8
> 31  HEFT-ACU  1 420814.2 433203.7
> 32  HEFT-ACU  2 420814.2 453475.8
> 60       LPT  1 402499.9 460543.4
> 61       LPT  2 402499.9 470316.8
> 90       SPT  1 453262.3 459070.3
> 91       SPT  2 453262.3 483893.6
> 119  MIN-MIN  1 447286.4 477632.5
> 120  MIN-MIN  2 447286.4 488146.3
> 149  MAX-MIN  1 457122.6 498265.2
> 150  MAX-MIN  2 457122.6 491143.3
>
Hi Adel,
Try this. I have used barp in plotrix as your algorithm labels need 
staggering.

aedf<-read.table(text="V1 V2       V3       V4
  HEFT-AC  1 402499.9 460543.4
  HEFT-AC  2 402499.9 470316.8
  HEFT-ACU  1 420814.2 433203.7
  HEFT-ACU  2 420814.2 453475.8
  LPT  1 402499.9 460543.4
  LPT  2 402499.9 470316.8
  SPT  1 453262.3 459070.3
  SPT  2 453262.3 483893.6
  MIN-MIN  1 447286.4 477632.5
  MIN-MIN  2 447286.4 488146.3
  MAX-MIN  1 457122.6 498265.2
  MAX-MIN  2 457122.6 491143.3",
  header=TRUE)
library(plotrix)
barp(aedf$V3[!duplicated(aedf$V1)],ylim=c(0,600000),
  names.arg=unique(aedf$V1),staxx=TRUE)
boxat<-1
for(alg in unique(aedf$V1)) {
  boxplot(aedf$V4[aedf$V1==alg],range=0,at=boxat,add=TRUE)
  boxat<-boxat+1
}

Jim




More information about the R-help mailing list