[R] barplot help needed

Antje niederlein-rstat at yahoo.de
Fri Nov 24 16:16:49 CET 2006


Still, there is one problem. The SD-Values don't fit to the bar they 
belong to. I made the following experiment:

 > data1 <- c(2,4,6,2,5)
 > data2 <- data1
 > sd1 <- c(0.5,1,1.5,1,2)
 > sd2 <- sd1
 > tab <- do.call(rbind, list(data1, data2))
 > etype <- c(sd1,sd2)
 > b <- barplot(tab, beside=T)
 > arrows(unlist(b), unlist(tab) - etype, unlist(b),  unlist(tab) + 
etype, code=3)

I expect the bars with the same height and the same stddev. The height 
is okay, but the stddev is messed up...

if I do it like this:

etype <- matrix(c(sd1,sd2), nrow=2, byrow=TRUE)

it works (but maybe there is an easier way...)

Antje




Jacques VESLOT schrieb:
> thought sd1, sd2... were scalars but if not just do:
> etype <- c(sd1, sd2, sd3, sd4)
> -------------------------------------------------------------------
> Jacques VESLOT
> 
> CNRS UMR 8090
> I.B.L (2ème étage)
> 1 rue du Professeur Calmette
> B.P. 245
> 59019 Lille Cedex
> 
> Tel : 33 (0)3.20.87.10.44
> Fax : 33 (0)3.20.87.10.31
> 
> http://www-good.ibl.fr
> -------------------------------------------------------------------
> 
> 
> Antje a écrit :
>> Thank you very much for your help.
>> I just don't understand the following line (which also gives me a 
>> dimension error later in the arrows command)
>>
>> etype <- rep(c(sd1, sd2, sd3, sd4), length(data1))
>>
>> Antje
>>
>> (I don't see my emails to the mailinglist anymore... just the answers 
>> from other people... I don't understand???)
>>
>>
>> Jacques VESLOT schrieb:
>>
>>> tab <- do.call(rbind, list(data1, data2, data3, data4))
>>> etype <- rep(c(sd1, sd2, sd3, sd4), length(data1))
>>> b <- barplot(tab, beside=T)
>>> arrows(unlist(b), unlist(tab) - etype, unlist(b),  unlist(tab) + 
>>> etype, code=3)
>>> -------------------------------------------------------------------
>>> Jacques VESLOT
>>>
>>> CNRS UMR 8090
>>> I.B.L (2ème étage)
>>> 1 rue du Professeur Calmette
>>> B.P. 245
>>> 59019 Lille Cedex
>>>
>>> Tel : 33 (0)3.20.87.10.44
>>> Fax : 33 (0)3.20.87.10.31
>>>
>>> http://www-good.ibl.fr
>>> -------------------------------------------------------------------
>>>
>>> Antje a écrit :
>>>
>>>> hello,
>>>>
>>>> I would like to create the following barplot:
>>>>
>>>> I have 4 different data sets (same length + stddev for each data point)
>>>>
>>>> data1
>>>> sd1
>>>> data2
>>>> sd2
>>>> data3
>>>> sd3
>>>> data4
>>>> sd4
>>>>
>>>> now, I'd like to plot in the following way:
>>>>
>>>> data1[1],data2[1],data3[1],data4[1] with it's sd-values side-by-side 
>>>> at one x-axis label (named "position 1") and each bar in different 
>>>> colors.
>>>>
>>>> data1[2],data2[2],data3[2],data4[2] at the next x-axis label (named 
>>>> "position 2") with the same color scheme
>>>>
>>>> and so on over the whole length.
>>>>
>>>> I managed to plot one set in the following way:
>>>>
>>>> par(mai=c(1.5,1,1,0.6))
>>>> plotInfo <- barplot(data1, las=2, ylim = c(0,plotMax+1), ylab = 
>>>> "Percentage")
>>>> arrows(plotInfo,data1,plotInfo,  data1 + sd1, length=0.1, angle=90)
>>>> arrows(plotInfo,data1,plotInfo,  data1 - sd1, length=0.1, angle=90)
>>>>
>>>> could anybody give me a help on this?
>>>>
>>>> Antje
>>>>
>>>> ______________________________________________
>>>> R-help at stat.math.ethz.ch 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.
>>>>
>>>
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch 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