Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R legend pch mix of character and numeric

Tags:

r

Is it possible to use a mix of character and number as plotting symbols in R legend?

plot(x=c(2,4,8),y=c(5,4,2),pch=16)
points(x=c(3,5),y=c(2,4),pch="+")
legend(7,4.5,pch=c("+",16),legend=c("A","B")) #This is the problem
like image 406
rmf Avatar asked Nov 19 '12 11:11

rmf


2 Answers

Use the numerical equivalent of the "+" character:

plot(x=c(2,4,8),y=c(5,4,2),pch=16)
points(x=c(3,5),y=c(2,4),pch="+")
legend(7,4.5,pch=c(43,16),legend=c("A","B"))
like image 147
Gene Avatar answered Oct 23 '22 11:10

Gene


There are actually numerical equivalents for all symbols!

enter image description here

Source: Dave Roberts

The pch code is the concatenation of the Y and X coordinates of the above plot.

  • For example, the + symbol is in row (Y) 4 and column (X) 3, and therefore can be drawn using pch = 43.

Example:

plot(x=c(2,4,8),y=c(5,4,2),pch=16)
points(x=c(3,5),y=c(2,4),pch="+")
legend(7,4.5,pch=c(43,16),legend=c("A","B"))
like image 20
theforestecologist Avatar answered Oct 23 '22 11:10

theforestecologist