Dear members,
I wish to create many circles and split them into sectors then colour the
sectors based on value attributed to the plot, then plot a colormap.
I have thus far been able to create the polygons, create the colorbar and colour
the sectors, but i know for a fact the colour isn't representative of the
value inside the sectors.
Any ideas how to adjust the function(s) so that the colour is representative of
the value attributed to the sector?
## Get circle pointscircs <- 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 figuredrawCirc <- 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]]
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]]
Hi bryar, I think your problem is in the distribution of the range of colors. Look at the examples for the "color.legend" and "barp" functions in the plotrix package to get this right. Jim On Tue, Jun 30, 2015 at 1:15 AM, bryar kadir <bryar-ahmed at hotmail.co.uk> wrote:> 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]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.