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...{{dropped:12}}

