3

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.

Thomas
  • 43,637
  • 12
  • 109
  • 140
Waddi
  • 31
  • 1
  • 1
  • 2
  • You don't need to wrap your parameters in `c()`. – Thomas Aug 01 '13 at 08:53
  • 1
    You can pass in the `character`s to pch to specify exactly what you want to use, including unicode characters, eg `plot(1:2,1:2,pch=c("\u2191","\u2193"))`. – James Aug 01 '13 at 09:28
  • Thanks for the quick reply! Well, I tried this before, and although it works when you have two parameters, adding the third give only error messages. – Waddi Aug 01 '13 at 10:21

3 Answers3

4

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)]))
Richie Cotton
  • 118,240
  • 47
  • 247
  • 360
  • I don't get this one. I might have been a bit unclear in my question. I have no problem adding any symbol to a normal regression. However, when I want to add an additional factor with, let say two levels, I cannot find a soloution for chosing symbols for these two levels? – Waddi Aug 01 '13 at 10:25
  • Oh, I thought you wanted to know what each `pch` value looked like so you could choose values for each level. – Richie Cotton Aug 01 '13 at 12:36
  • Ah, no, sorry. I want to be able to choose the pch of the factor levels in an Ancova. I'm obviously useless speaking the statistic-language. – Waddi Aug 01 '13 at 12:39
3

A graphical representation of the pch symbols and the associated values can be found on many pages, e.g., here.

enter image description here

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168
1

Two answers, the choice of which depends on how your factor levels are set up:

First, if your factor levels start at 1, and are sequential after that (so factors levels are 1,2,3,4 in the example below):

plot(data.3$age,data.3$tl, pch = c(21,10,22,7)[as.numeric(pch=c(data.3$mu))] )

Second, if your factor levels are not sequential (say you have subsetted a larger data set, with 7 factors, but you are only interested in plotting 4 of them):

plot(data.3$age,data.3$tl, pch = c(21,10,22,7)[as.numeric(as.factor(as.character(pch=c(data.3$mu))))] )
Rohan Kandwal
  • 9,112
  • 8
  • 74
  • 107
AlCan2
  • 11
  • 3
  • The syntax in the first suggestion here didn't work for me. This post was better: http://stackoverflow.com/questions/12919816/plotting-in-different-shapes-using-pch-argument – Nova Oct 26 '15 at 15:58