[R] Help on lattice barchart ploting

David Winsemius dwinsemius at comcast.net
Mon Feb 20 15:04:47 CET 2012


On Feb 20, 2012, at 5:34 AM, MLSC wrote:

> Hi friends,
>
> I have following data and would like to plot this with barchart()  
> availble
> with lattice package.
>
>       RsID  Freqs Genotype
> AAA 63.636      1/1
> AAA 32.727      1/2
> AAA  3.636      2/2
> BBB 85.965      2/2
> BBB 14.035      2/1
> CCC 63.158      1/1
> CCC 21.053      1/2
> CCC 15.789      2/2
> DDD 26.786      2/2
> DDD 46.429      2/1
> DDD 26.786      1/1
> EEE 32.759      2/2
> EEE 43.103      2/1
> EEE 24.138      1/1
> EEE 37.931      1/1
> EEE 51.724      1/2
> EEE 10.345      2/2
> FFF 23.214      2/2
> FFF 53.571      2/1
> FFF 23.214      1/1
> GGG 46.552      1/1
> GGG 44.828      1/2
> GGG  8.621      2/2
> HHH 65.517      2/2
> HHH 32.759      2/1
> HHH  1.724      1/1
>
> Following is the code which I have written to get the plot.
>
> barchart(Genotype~Freqs | RsID, data=gDataFr,layout=c(4,6),
>                main="Genotype Frequency",
>                ylab="Genotype", xlab="Frequency",
>                scales=list(x=list(alternating=c(1, 1, 1))),
>                panel=function(x,y,...){
>                panel.fill(col="white")
>                panel.grid(-1,0,lty=3,col="black")
>                panel.barchart(x,y,col=c("blue","green","red"),...)
>                }
> )
>
> but in plot, x-axis scale ranges from 0 to 30 though I have "Freq"  
> column
> values in range of 0 to 100. I have tried many ways to get x-axis  
> scale to
> 0 to 100, including xlim=c(1:100), but still bars in plot are not
> propotional to the range 0 to 100. hence can somebody let me know  
> how get
> bars in the plot propotional to x-axis range 0 to 100?
>

Check the class of Genotype. I do not see what you are describing when  
I create a dataset from your example. I suspect you had implicit  
coercion of your Genotype column to factor class. Or that you  
recognized that and forgot to tell us that you made the newbie error  
of using as.numeric() without first converting using as.character()  
from factor.


-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list