Andrew Roberts
2013-Feb-16 06:30 UTC
[R] subplot (Hmisc) and radial.plot (plotrix) problem
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)
On 02/16/2013 05:30 PM, Andrew Roberts wrote:> 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? >Hi Andrew, I'm not quite sure, but the radial plot function may be working as I changed the ylim in the initial call to plot to: ylim=c(-5,5), added the lines: print(ang) print(freq) to the loop in your code. What is printed is: [1] -0.0715503 0.0000000 [1] 1 1 ang 0.0715503 freq 3 [1] -0.0715503 0.0715503 0.1438370 [1] 1 2 1 [1] 0.0715503 0.1438370 [1] 1 3 [1] 0.0715503 0.1438370 [1] 1 1 and this does look like what is being displayed. Five of the lines are in much the same place and are overplotted and there are five "centroids" displayed. I'm not completely familiar with the "subplot" function, so I'll let Greg comment on that. Clearly the successive radial plots are not being offset as expected. Jim