|
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. |
|
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. > 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 ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
On 04/28/2012 09:29 PM, Jim Lemon wrote:
>... Oops, the function is attached to this email. Jim ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
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) } ______________________________________________ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. |
|
In reply to this post by Jim Lemon
On 04/28/2012 02:32 PM, Jim Lemon [via R] wrote:
> 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 > Hi Jim, Fantastic! I would never thought that my message would create such a great and immediate respond. With your new "varpos" function and the code you suggested I managed to make the kites look exactly the way I want. I wonder however, if you could add some automation to this function. Have a look at the new data below and the kite charts which are created after using your code: Y<- read.table(textConnection("Sample1 Sample2 60 20 150 50 300 300"),header=TRUE) X<- read.table(textConnection("Sample1 Sample2 6 2 15 5 30 7"),header=TRUE) par(las=1,mfrow=c(2,1)) kiteChart(t(Y),xlim=c(-650,650), timelabels=c("2-3cm","1-2cm","0-1cm"), normalize=FALSE,shownorm=FALSE,timex=FALSE, varpos=c(-350,350)) axis(3,at=c(-650,-350,-50,50,350,650),labels=c(0,"",300,0,"",150)) kiteChart(t(X),xlim=c(-65,65), timelabels=c("2-3cm","1-2cm","0-1cm"), normalize=FALSE,shownorm=FALSE,timex=FALSE, varpos=c(-35,35)) axis(3,at=c(-65,-35,-5,28,35,42),labels=c(0,"",30,0,"",7)) Now, look at the top kite. In order to find the values for the xlim switch one needs to do the following calculations manually: first find the largest value from data.frame.Y, (300), then double this value (600) and then add a small space, say 50, so that the two variables are not touching each other (otherwise the 300 of variable 1 and the 0 of variable 2 would overlap). Similarly, for the varpos switch, one needs to find the two centers of the xlim=c(-650,650) space to find varpos=c(-350,350). Finally, for the axis tick marks (for example see Sample 2 at the bottom kite) one has to find the max value of Sample 2 in data.frame.X (7) and then add and subtract this value from its varpos value (35) to find the correct positions of the tick marks (28,35,42). As you can imagine, this is not a big problem with two variables in a KiteChart but it could get frustrating if one has more than two variables. But maybe I am asking too much. Anyway, thanks again for your great work and help. Nikos -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. |
| Powered by Nabble | Edit this page |
