[R] Adding colorbar to polygon plot
bryar kadir
bryar-ahmed at hotmail.co.uk
Mon Jun 29 17:15:40 CEST 2015
Sorry the code is suppose to look as follows:
## Get circle points
circs <- function(radii, sectors=4) {
radii <- sort(radii)
rads <- seq(0, 2*pi, length=2*length(radii)*sectors) # sample at these radians
do.call(rbind, lapply(radii, function(r) # points for drawing circles
data.frame(X=r*cos(rads), Y=r*sin(rads),
sector=rep(1:sectors, each=length(rads)/sectors),
theta=rads, radius=r)))
}
## Draw figure
drawCirc <- function(radii, sectors, hues=NULL, densities=NULL, ...) {
polys <- circs(radii, sectors)
if (missing(hues)) {
colors <- colorRampPalette(c("green","yellow","red","blue"))(sectors*length(radii))
} else
colors <- heat.colors(n=sectors*length(radii),alpha=hues)
ind=0
plot(polys[,1:2], type="n" ,...) # blank plot
for (i in seq_along(radii)) { # add polygons
for (j in 1:sectors) {
ind <- ind+1
color <- colors[ind]
with(polys[polys$sector==j,],
if (i == 1) {
polygon(x=c(0, X[radius==radii[i]], 0), y=c(0, Y[radius==radii[i]], 0),
col=color, density=densities[ind])
} else
polygon(x=c(X[radius==radii[i-1]], rev(X[radius==radii[i]])),
y=c(Y[radius==radii[i-1]], rev(Y[radius==radii[i]])),
col=color, density=densities[ind]))
}
}
cols<-colorRampPalette(c("blue","red","yellow","green"))(sectors*length(radii))
vertical.image.legend(col=cols, zlim=range(c(1,0)))
}
drawCirc(radii=1:50, sectors=24, main="Ratio by Colors")
Please note, that the hues allows for the transparency to take into account the values of the sectors but i want the colours to be fully opaque not transparent. As this causes issues with the colorbar on the right hand side.
Thank you in advance for any suggestion.
bryar
[[alternative HTML version deleted]]
More information about the R-help
mailing list