lanselibai
lanselibai

Reputation: 1273

How to plot a 60x2 matrix with different colors and markers in R?

a is a 60*2 dimension matrix.

> dim(a)
[1] 60  2

plot(a) gives this enter image description here

How can I customise the plot, so that


Thank you very much for @Wietze314's help. I got this plot below. The yellow dots are very light, so is there a way to draw a black border for them?

enter image description here

Upvotes: 0

Views: 275

Answers (1)

Wietze314
Wietze314

Reputation: 6020

Use the col and pch arguments to specify color and shape for each data point.

a <- data.frame(x = rep(1:10,6), y = rep(1:6, each = 10))

WhRd <- colorRampPalette(c("white", "red"))
WhYl <- colorRampPalette(c("white", "yellow"))
WhBl <- colorRampPalette(c("white", "blue"))

plot(a,
     col = rep(c(WhRd(10),
             WhYl(10),
             WhBl(10)),2),
     pch = c(rep(15,30),
             rep(16,30)))

To add border just plot extra points over the original ones

points(a,
     col = 'black',
     pch = c(rep(0,30),
             rep(1,30)))

Upvotes: 2

Related Questions