[R] subplot (Hmisc) and radial.plot (plotrix) problem

Andrew Roberts andrew at thinkingbone.org
Sat Feb 16 07:30:55 CET 2013


Folks,

I am having problems with a plot I want to create to give an impression 
of changes in an ordinal scale measure (1-5)  at three time points  (0, 
14 and 21 days). I can produce a radial plot of bare vectors but getting 
this to appear on the base plot is not possible as it always seems to 
end up below the plot area and even outside the plot window.

It seems I have not understood something about the coordinate system, Is 
anyone able to shed any light on this?

many thanks,

Andrew Roberts

# Example #######################################
library(Hmisc)
library(plotrix)
library(plyr)
# Create a data frame of ordinal results #####################
X <-c(1,3,4,5,3,2,4,4,5,2,1,3,3,2,4)
Y <-c(1,2,2,4,1,1,2,3,3,1,2,2,4,1,2)
Z <-c(1,2,1,2,1,1,3,2,2,2,1,2,2,1,1)
data <-as.data.frame(cbind(X,Y,Z))
data$xydiff <-data$X - data$Y
data$yzdiff <-data$Y - data$Z

# Create the background frame for the subplots #################
plot(1, type="n", xlim=c(0,21),
                 ylim = c(1,5),
                 main="Score Changes",
                 xlab="Days" , ylab="Ashworth Scale")
# Work through each level of the scale #########################
for(i in 1:5){
   t  <-subset(data, X==i)
   t2 <-count(t,vars="xydiff")
   t2$ang <-tan(t2$xydiff/14)
   ang <-as.matrix(t2)[,3]
   freq <-as.matrix(t2)[,2]
   subplot(radial.plot(freq,ang, labels=" ", clockwise=TRUE, 
show.grid=FALSE,radial.lim=c(0,8),
                     point.symbols=12,point.col="green", show.centroid=TRUE,
                     show.grid.labels=TRUE, show.radial.grid=FALSE, 
line.col="red",
                     lwd=3,add=TRUE),
   0,i)
   rm(ang,freq,t,t2)
             }
# But this exmple works! ######################################
subplot( hist(rnorm(100)), 1, 4)



More information about the R-help mailing list