Thursday 15 August 2013

r - add different text to panels in barchart -



r - add different text to panels in barchart -

hi add together different text 2 panels in barchart. 2 text values indicate percentage of 0 values in barchart. have been searching though different help sites, have yet find answer. here attempt:

data

dput(ztable) structure(list(group.1 = structure(c(1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l, 9l, 11l, 12l, 14l, 17l, 19l, 29l, 115l, 1l, 2l, 3l, 4l, 5l, 6l, 7l, 8l, 9l, 11l, 12l, 14l, 17l, 19l, 29l, 115l), .label = c("0", "10", "20", "30", "40", "50", "60", "70", "80", "90", "100", "110", "120", "130", "140", "150", "160", "170", "180", "190", "200", "210", "220", "230", "240", "250", "260", "270", "280", "290", "300", "310", "320", "330", "340", "350", "360", "370", "380", "390", "400", "410", "420", "430", "440", "450", "460", "470", "480", "490", "500", "510", "520", "530", "540", "550", "560", "570", "580", "590", "600", "610", "620", "630", "640", "650", "660", "670", "680", "690", "700", "710", "720", "730", "740", "750", "760", "770", "780", "790", "800", "810", "820", "830", "840", "850", "860", "870", "880", "890", "900", "910", "920", "930", "940", "950", "960", "970", "980", "990", "1000", "1010", "1020", "1030", "1040", "1050", "1060", "1070", "1080", "1090", "1100", "1110", "1120", "1130", "1140"), class = "factor"), group.2 = structure(c(1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 1l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l, 2l), .label = c("fall", "spring" ), class = "factor"), x = c(677l, 344l, 18l, 6l, 5l, 4l, 0l, 2l, 0l, 1l, 0l, 0l, 1l, 1l, 0l, 1l, 82l, 186l, 15l, 6l, 8l, 1l, 3l, 0l, 1l, 1l, 1l, 1l, 0l, 0l, 1l, 0l)), .names = c("group.1", "group.2", "x"), row.names = c(na, -32l), class = "data.frame")

barchart code

mytext<-c("63.9","7.7") barchart(ztable[,3]~ztable[,1]|ztable[,2],col="light grey", scales=list(y=list(cex=.8),x=list(cex=.8,rot=90)),ylim=c(0,800), xlab="number of black sea bass",ylab="number of stations", panel=function(x,y,...){ panel.barchart(x,y,...) panel.text(1,0,labels=mytext[panel.number()]) } )

you have minor error in panel.text() function. x , y coordinates create cannot read text. x-coordinate in barchart (which first number in panel.text function) refers bar number. have 1, create 8 set in middle. y coordiante refers value on y-axis. sec number in panel.text' function. 0, 400 works better. replace yourpanel.text` line this:

panel.text(8,400,labels=mytext[panel.number()]) }

and get:

r text bar-chart lattice

No comments:

Post a Comment