[R] Add group name in barchart

Silong Liao silong.liao at hotmail.com
Wed Dec 3 00:27:18 CET 2014


Dear ALL,
 
I have a dataset contains 2 variables: mate (mating groups) and ratio (ratio of number of mothers and fathers). And mate is an identifer which consists three components: year, flock (flk), and tag.
 
I am using command "barchart" under package "lattice" to generate plots of ratio against mate divided by each flock (See attachment). I want to put flock names onto the corresponding plots, but don't know how.
 
Cheers, Sid
 
load("ratiodata.Rdata")
attach(ratiodata)
head(ratiodata)
 
        mate    ratio1 2007.102.A 21.285712 2007.102.B 68.200003 2007.102.C 59.500004 2007.102.D 19.333335 2007.102.E 72.333336 2007.102.F 35.50000 
str(ratiodata$mate) #factor
str(ratiodata$ratio) #num
unique(ratiodata$flk)
 
[1]  102    2 2744 2747 2749  391 4357 4880 3001 3003 3004 3855 3658 4588 4591 4631 
library("lattice")
ratiodata$flk=read.table(text=as.character(ratiodata$mate),sep=".")[,2]
barchart(ratiodata$ratio~ratiodata$mate|ratiodata$flk)
 
 
 		 	   		  


More information about the R-help mailing list