I'm trying to create 2 circles and then split them into 4 parts so that I get 8 sectors, then i want to attribute a value from 0-1 to each sector and colour the circle based on the value given to it.
Thus I have a vector
ratio<-c(0.02,0.04,0.67,0.9874,0.134552,0.753,0.9754,0.23460)
Which contains the ratio of each sector and need to attribute these with the sector and colour sector based on these values.
I have been able to create the circle but its just one polygon, how do i separate the polygon into 8 sectors then attribute a value to it? or maybe create a numbering system to number the sectors ?
I have been searching online for a sometime now can't find the answer.
I have used the following code to create the polygon,
circle1<-0
circle2=0
x1=0
y1=0
k=0
y2<-0
x2<-0
for(l in 1:2){
for(j in 1:4){
for(i in 0:180){
x1<-c(x1,l*cos(i*0.0087266462599716+k*180*0.0087266462599716))
y1<-c(y1,l*sin(i*0.0087266462599716+k*180*0.0087266462599716))
}
x2<-c(x2,x1,0)
y2<-c(y2,y1,0)
x1<-0
y1<-0
k=k+1
}
circle1<-c(circle1,x2)
circle2<-c(circle2,y2)
}
circle3<-cbind(circle1,circle2)
polymap(circle3,axes=T)
#below code is for creating the separate polygons
polys <- SpatialPolygons(list(
Polygons(list(Polygon(matrix(c(circle3[1:183,1],
circle3[1:183,2]), ncol=2))),c[1]),
Polygons(list(Polygon(matrix(c(circle3[184:366,1],
circle3[184:366,2]), ncol=2))), c[2]) ))
I was advised to use splancs package.
I appreciate any suggestion.
I have been able to draw the polygons BUT still can't colour the plotted polygon based on the ratio vector. I need the colour to reflect the ratio.
Here is a possibility, using base R,