[R] Preparing data frame for Plotrix kiteChart
Ben Bolker
bbolker at gmail.com
Fri Sep 17 20:31:05 CEST 2010
Graham Smith <graham.smith <at> myotis.co.uk> writes:
>
> Although, I can fix this, I am trying to sort out something as
> straighforward as possible for my students, and I have some questions
> that hopefully someone can help me with.
>
> My data is:
>
> Species Distance Count
> A 5 0
> A 10 5
> A 15 5
> A 20 3
> A 25 1
> B 5 8
> B 10 20
> B 15 28
> B 20 12
> B 25 12
> C 5 5
> C 10 12
> C 15 19
> C 20 27
> C 25 34
>
> But I am struggling to get this into a data frame that does what I
> expect. I have tried various arrangements.
>
> What I am hoping for is:
>
> an x-axis labelled "Distance" with tick marks at 0, 5, 10,15,20 and 25.
>
> And, an y-axis labelled "Species" and tick marks labelled A, B and C.
>
> So I would appreciate some help on how the data should be prepared for
> kiteChart, to maximise the lablels being added automatically. If possible.
>
> Many thanks,
>
> Graham
>
>
####
X <- read.table(textConnection("Species Distance Count
A 5 0
A 10 5
A 15 5
A 20 3
A 25 1
B 5 8
B 10 20
B 15 28
B 20 12
B 25 12
C 5 5
C 10 12
C 15 19
C 20 27
C 25 34"),header=TRUE)
library(reshape)
X2 <- recast(X,Distance~Species,id.var=1:2)
X3 <- as.matrix(X2[,-1])
rownames(X3) <- X2$Distance
colnames(X3) <- names(X2)[-1]
library(plotrix)
kiteChart(t(X3),xlab="Distance",ylab="Species")
More information about the R-help
mailing list