Dear R-users I hope someone could help me on this problem. I want to create a multiple kiteChart showing the real values with a scalebar on each indicating the scale . Here are some sample data to show what I want to achieve. Y <- read.table(textConnection("Sample1 Sample2 60 20 150 50 300 100"),header=TRUE) X <- read.table(textConnection("Sample1 Sample2 6 2 15 5 30 10"),header=TRUE) par(las=1,mfrow=c(2,1)) kiteChart(t(Y),xlim=c(-400,400),timelabels=c("2-3cm","1-2cm","0-1cm"), normalize=FALSE,shownorm=FALSE,timex=FALSE) kiteChart(t(X),xlim=c(-400,400),timelabels=c("2-3cm","1-2cm","0-1cm"), normalize=FALSE,shownorm=FALSE,timex=FALSE) My first problem with the above approach is that the kites in both graphs are overlapping. If I take out the xlim switch then the kites are too large and you can't see anything. If I use the xlim switch then they are not plotted next to each other as they should. Please note that I could use normalize=TRUE and then they are plotted ok but I don't want to normalize them. My second problem is that I have data which are way too smaller that the values shown in data.frame X. So, if the first graph has large values and the second very small values then on the second graph you see only a thin line. Therefore I want to multiply the small values of data.frame X by a factor to make the kites visible but then I need to place a scalebar on each graph showing e.g. that for the 0-1cm the top graph is 0-300 and the lower graph is 0-30. Hope that my post is not very confusing. Thanks in advance. -- View this message in context: http://r.789695.n4.nabble.com/kiteChart-to-show-real-values-with-scalebar-tp4593386p4593386.html Sent from the R help mailing list archive at Nabble.com.
On 04/28/2012 04:12 AM, bodiless wrote:> Dear R-users > > I hope someone could help me on this problem. > > I want to create a multiple kiteChart showing the real values with a > scalebar on each indicating the scale . > Here are some sample data to show what I want to achieve. > > Y<- read.table(textConnection("Sample1 Sample2 > 60 20 > 150 50 > 300 100"),header=TRUE) > X<- read.table(textConnection("Sample1 Sample2 > 6 2 > 15 5 > 30 10"),header=TRUE) > par(las=1,mfrow=c(2,1)) > kiteChart(t(Y),xlim=c(-400,400),timelabels=c("2-3cm","1-2cm","0-1cm"), > normalize=FALSE,shownorm=FALSE,timex=FALSE) > kiteChart(t(X),xlim=c(-400,400),timelabels=c("2-3cm","1-2cm","0-1cm"), > normalize=FALSE,shownorm=FALSE,timex=FALSE) > > My first problem with the above approach is that the kites in both graphs > are overlapping. If I take out the xlim switch then the kites are too large > and you can't see anything. If I use the xlim switch then they are not > plotted next to each other as they should. Please note that I could use > normalize=TRUE and then they are plotted ok but I don't want to normalize > them. > > My second problem is that I have data which are way too smaller that the > values shown in data.frame X. So, if the first graph has large values and > the second very small values then on the second graph you see only a thin > line. Therefore I want to multiply the small values of data.frame X by a > factor to make the kites visible but then I need to place a scalebar on each > graph showing e.g. that for the 0-1cm the top graph is 0-300 and the lower > graph is 0-30. >Hi bodiless, You have just contributed to the development of kiteChart. I have inserted another argument (varpos) that allows the user to place the "kiteline" along the axis orthogonal to the "time" axis. With the following code, I think you will get what you want. kiteChart(t(Y),xlim=c(-400,400), timelabels=c("2-3cm","1-2cm","0-1cm"), normalize=FALSE,shownorm=FALSE,timex=FALSE, varpos=c(-100,300)) axis(3,at=c(-400,-100,200,300,400),labels=c(-300,0,300,0,100)) The last line puts axis tick labels on the top of the plot, which is what I think you want. The revised function is attached, let me know if any other mods are needed. The revised function will appear shortly in a new version. Jim
On 04/28/2012 09:29 PM, Jim Lemon wrote: >... Oops, the function is attached to this email. Jim
On 04/28/2012 10:00 PM, Jim Lemon wrote:> On 04/28/2012 09:29 PM, Jim Lemon wrote: > >... > > Oops, the function is attached to this email. >Arrrgh, forgot to put it inline... Jim kiteChart<-function(x,xlim=NA,ylim=NA,timex=TRUE,main="Kite chart", xlab=ifelse(timex,"Time","Groups"),ylab=ifelse(timex,"Groups","Time"), fill=NULL,border=par("fg"),varpos=NA,varlabels=NA,timepos=NA,timelabels=NA, mar=c(5,4,4,4),axlab=c(1,2,3,4),normalize=TRUE,shownorm=TRUE,...) { oldmar<-par(mar=mar) dimx<-dim(x) if(is.na(xlim[1])) { if(timex) xlim<-c(1,dimx[2]) else xlim<-c(0.5,dimx[1]+0.5) } if(is.na(ylim[1])) { if(timex) ylim<-c(0.5,dimx[1]+0.5) else ylim<-c(1,dimx[2]) } plot(0,xlim=xlim,ylim=ylim,main=main,xlab=xlab,ylab=ylab,type="n",axes=FALSE,...) if(is.na(varlabels[1])) { if(is.null(rownames(x))) varlabels<-1:dimx[1] else varlabels<-rownames(x) } if(is.na(varpos[1])) varpos<-1:dimx[1] axis(ifelse(timex,axlab[2],axlab[1]),at=varpos[1:dimx[1]],labels=varlabels) if(is.na(timepos[1])) timepos<-1:dimx[2] if(is.na(timelabels[1])) { if(is.null(colnames(x))) timelabels<-timepos else timelabels<-colnames(x) } axis(ifelse(timex,axlab[1],axlab[2]),at=timepos,labels=timelabels) box() if(is.null(fill)) fill<-rainbow(dimx[1]) if(length(fill) < dimx[1]) fill<-rep(fill,length.out=dimx[1]) for(krow in 1:dimx[1]) { if(normalize) { if(shownorm) mtext(paste("*",signif(1/max(x[krow,]),digits=3)), ifelse(timex,axlab[4],axlab[3]),at=varpos[krow],las=1) x[krow,]<-x[krow,]/(max(x[krow,])*2) } xpos<-1:length(x[krow,]) if(timex) polygon(c(xpos,rev(xpos)),c(varpos[krow]+x[krow,],varpos[krow]-rev(x[krow,])), col=fill[krow],border=border) else polygon(c(varpos[krow]+x[krow,],varpos[krow]-rev(x[krow,])),c(xpos,rev(xpos)), col=fill[krow],border=border) } invisible(oldmar) }