colorpoints | R Documentation |
The function is a wrapper around the points
function, controlling the color of the points similar to ggplot
, but using S-style plotting.
If neither ramp
, nor col
or breaks
are given, the function will default to using the internal gradinv
palette with 256 levels evenly distributed from the minimum to the maximum of z
.
colorpoints(
x,
y = NULL,
z,
ramp = NULL,
col = NULL,
breaks = NULL,
legend = list(x = "topleft"),
...
)
x |
The |
y |
The |
z |
|
ramp |
A |
col |
A vector of colors. Used only if |
breaks |
A vector of breaks. If given, this has to be one element longer than the length of |
legend |
A list of arguments passed to the |
... |
Arguments passed to the |
The function has no return value.
# random points
set.seed(1)
x <- rnorm(5000) # x coord
y <- rnorm(5000) # y coord
dist <- sqrt(x^2+y^2) # distance from origin
# default plotting
plot(x,y, col=NA)
colorpoints(x=x, y=y, z=dist)
# custom color scheme
levs<- data.frame(color=rainbow(5), z=c(0, 0.5,1, 3, 4.5))
ramp <-expand(levs, n=256)
# very customized (experiment with difference device sizes!)
plot(x,y, col=NA, main="Distance to origin")
colorpoints(x=x, y=y, z=dist,
col=paste0(ramp$col, "BB"),
breaks=ramp$breaks,
pch=16,
legend=list(x=3,y=0,cex=0.7, box.args=list(border=NA)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.