How to choose pch symbols for a factor in R?

Waddi picture Waddi · Aug 1, 2013 · Viewed 10.7k times · Source

I have tried to find out how to choose the symbols used for the factorial parameter in a case like this:

plot(data.3$age,data.3$tl,pch=c(data.3$mu),col=c(data.3$mu),
cex=1.5,cex.lab=1.3,cex.axis=1.5,las=1,bty="n",xlab="Age (years)",
ylab="Male Total Length (mm)",ylim=c(0,780),xlim=c(0,20))

I have used pch=as.numeric(factor) but I want to be able to choose the symbols myself because I find the default ones quite difficult to distinguish from each other.

I guess it's fairly simple but I have really tried to find out how to do this.

Answer

Richie Cotton picture Richie Cotton · Aug 1, 2013

You can see the values available for pch in this plot. (Make the figure window wide for best viewing.)

i <- -128:25
plot(i, pch = i, bg = "blue")

Negative numbers are ASCII values.


I think that this is what you are asking for, but I don't know why you are drawing a plot like this. A set of histograms or boxplots would make more sense.

dummy <- data.frame(
  x = 1:20, 
  y = factor(sample(letters[1:4], 20, replace = TRUE))
)
pch_lookup <- c(a = 3, b = 10, c = 15, d = 20)
with(dummy, plot(x, y, pch = pch_lookup[as.character(y)]))