[R] fill colour in grid
Pascal Oettli
kridox at ymail.com
Thu Feb 14 03:07:40 CET 2013
Hi,
?rect
par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i")
plot.new()
plot.window(xlim= c(0,8), ylim=c(0,8),col="blue",lwd=3, bg=5)
axis(1)
axis(2)
title(main="The Overall Title")
title(xlab="An x-axis label")
title(ylab="A y-axis label")
box()
rect(0,0,4,4,col='blue',border=NA)
rect(3,3,4,4,col='red',border=NA)
grid(nx = 8)
The same using "polygon"
par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i")
plot.new()
plot.window(xlim= c(0,8), ylim=c(0,8),col="blue",lwd=3, bg=5)
axis(1)
axis(2)
title(main="The Overall Title")
title(xlab="An x-axis label")
title(ylab="A y-axis label")
box()
polygon(c(0,4,4,0),c(0,0,4,4),col='blue',border=NA)
polygon(c(3,4,4,3),c(3,3,4,4),col='red',border=NA)
grid(nx = 8)
HTH,
Pascal
Le 14/02/2013 10:56, Roslina Zakaria a écrit :
> Dear all r-users,
>
> I have this code below to draw two squares, small and big square. I would like to colour the small square with red and the big square with blue for example. I tried using polygon but fail. Thank you so much for your help.
>
>
> par(mar=c(4,4,2,1.2),oma=c(0,0,0,0),xaxs="i", yaxs="i")
> plot.new()
> plot.window(xlim= c(0,8), ylim=c(0,8),col="blue",lwd=3, bg=5)
> axis(1)
> axis(2)
> title(main="The Overall Title")
> title(xlab="An x-axis label")
> title(ylab="A y-axis label")
> box()
> #segments(x0, y0, x1, y1, col = par("fg"), lty = par("lty"), lwd = par("lwd"))
> segments(0, 0, 4, 0, col=1, lty = 1, lwd = 3)
> segments(4, 0, 4, 4, col=2, lty = 1, lwd = 3)
> segments(0, 0, 0, 4, col=3, lty = 1, lwd = 3)
> segments(0, 4, 4, 4, col=2, lty = 1, lwd = 3)
> segments(3, 3, 4, 3, col=5, lty = 1, lwd = 3)
> segments(3, 3, 3, 4, col=5, lty = 1, lwd = 3)
> polygon(c(3,4) , col="purple")
> #grid(nx = NULL, ny = nx, col = "lightgray", lty = "dotted", lwd = par("lwd"), equilogs = TRUE)
> grid(nx = 8)
> [[alternative HTML version deleted]]
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>
More information about the R-help
mailing list