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? Regards, mlsc [[alternative HTML version deleted]]
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
I do not see the restricted range that you report. There is probably some masking as David pointed out. Try again in a fresh R session with --vanilla. You probably want three additional arguments. update(.Last.value, xlim=c(0, 100), between=list(x=1, y=1), origin = 0) to the barchart function call. The origin=0 makes the bars start at 0, not at the left margin of the panel. The between visually separates the panels. If you want the values 0 and 100 to appear on the x-axis, then you will need to use xlim=x(-5, 105) On Mon, Feb 20, 2012 at 5:34 AM, MLSC <mlscmahe@gmail.com> 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? > > Regards, > mlsc > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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<http://www.r-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]