[R] Shading specific region in R

Eliza Botto eliza_botto at outlook.com
Tue Mar 27 16:14:06 CEST 2018


Dear useRs,

Following the given codes below, I generated a plot that has 6 regions around a center point (IL), with 5 regions containing

a point (L1, L2 to L5) and sixth vacant region. I want background of all the filled regions turned "green", while "red" for the

vacant region. Can it be done through a quicker way?

Thanks in advance

###Codes start from here################################

plot(1:10,col="white",xlab=expression("D"[a]),ylab=expression("D"[b]),cex.lab=1.3, mgp = c(2, 1, 0))

rect(par("usr")[1],par("usr")[3],par("usr")[2],par("usr")[4],col = "white")

points(5,5,pch=19,col="green",lwd=2)

points(5,9,pch=19,col="yellow",lwd=2)

points(5,1,pch=19,col="yellow",lwd=2)

points(2,7,pch=19,col="yellow",lwd=2)

points(9,4,pch=19,col="yellow",lwd=2)

points(8,8,pch=19,col="yellow",lwd=2)

text(5.7,9.5,expression("L"[1]),cex=1.2)

text(8.7,8.5,expression("L"[2]),cex=1.2)

text(9.6,4.5,expression("L"[3]),cex=1.2)

text(5.6,1.5,expression("L"[4]),cex=1.2)

text(2.4,7.7,expression("L"[5]),cex=1.2)

text(5.5,4.4,expression("I"[L]),cex=1.2)

X1<-5

Y1<-5

X2<-5*X1

Y2<-Y1

base<-sqrt((X1-X2)^2+(Y1-Y2)^2)

Hyp =base/cos(60*pi/180)

Pre= Hyp*sin(60*pi/180)

Y3<-Pre+Y2

X3<-X2

segments((X3), (Y3), (X1-base), (Y1-Pre),type="l",col="red")

segments((X1-base), (Y3), (X3), (Y1-Pre),type="l",col="red")

segments((X2), (Y2), (X1-base), (Y1),type="l",col="red")



regards,

Eliza



	[[alternative HTML version deleted]]



More information about the R-help mailing list