Customize pch

7 views
Skip to first unread message

Christoph Ruehlemann

unread,
Mar 1, 2018, 10:34:31 AM3/1/18
to corplin...@googlegroups.com
Hi all,

How do you customize point characters for one variable depending on levels in another variable?

For example, in this dataframe:

> dat
             A B
1   0.11254994 X
2   0.12960958 Y
3   0.13028834 X
4   0.14787580 X
5   0.14313576 Y
6  -0.01997931 X
7   0.13029203 X
8   0.15085300 X
9   0.01596402 X
10  0.06396085 Y

how do assign

Christoph Ruehlemann

unread,
Mar 1, 2018, 10:36:31 AM3/1/18
to corplin...@googlegroups.com
Sorry, that got sent off too early:


Hi all,

How do you customize point characters for one variable depending on levels in another variable?

For example, in this dataframe:

> dat
             A         B
1   0.11254994 X
2   0.12960958 Y
3   0.13028834 X
4   0.14787580 X
5   0.14313576 Y
6  -0.01997931 X
7   0.13029203 X
8   0.15085300 X
9   0.01596402 X
10  0.06396085 Y

how do you assign, say, pch=1 to all A-values that have "X" on Variable B and pch=20 to all A-values that have "Y" on Variable B?

Best
Chris

Matías Guzmán Naranjo

unread,
Mar 1, 2018, 10:37:56 AM3/1/18
to corplin...@googlegroups.com
dat$pch <- 1
dat[dat$B==Y, "pch"] <- 20

2018-03-01 16:36 GMT+01:00 'Christoph Ruehlemann' via CorpLing with R <corplin...@googlegroups.com>:
Sorry, that got sent off too early:

Hi all,

How do you customize point characters for one variable depending on levels in another variable?

For example, in this dataframe:

> dat
             A         B
1   0.11254994 X
2   0.12960958 Y
3   0.13028834 X
4   0.14787580 X
5   0.14313576 Y
6  -0.01997931 X
7   0.13029203 X
8   0.15085300 X
9   0.01596402 X
10  0.06396085 Y

how do you assign, say, pch=1 to all A-values that have "X" on Variable B and pch=20 to all A-values that have "Y" on Variable B?

Best
Chris

On Thu, Mar 1, 2018 at 4:34 PM, Christoph Ruehlemann <chrisruehlemann@googlemail.com> wrote:
Hi all,

How do you customize point characters for one variable depending on levels in another variable?

For example, in this dataframe:

> dat
             A B
1   0.11254994 X
2   0.12960958 Y
3   0.13028834 X
4   0.14787580 X
5   0.14313576 Y
6  -0.01997931 X
7   0.13029203 X
8   0.15085300 X
9   0.01596402 X
10  0.06396085 Y

how do assign



--

--
You received this message because you are subscribed to the Google Groups "CorpLing with R" group.
To unsubscribe from this group and stop receiving emails from it, send an email to corpling-with-r+unsubscribe@googlegroups.com.
To post to this group, send email to corpling-with-r@googlegroups.com.
Visit this group at https://groups.google.com/group/corpling-with-r.
For more options, visit https://groups.google.com/d/optout.

Stefan Th. Gries

unread,
Mar 1, 2018, 11:31:32 AM3/1/18
to CorpLing with R
Three suggestions:

# for 2 plotting symbols
set.seed(12)
head(dat <- data.frame(X=rnorm(20), Y=rnorm(20),
PCH=sample(letters[1:2], 20, replace=TRUE))) #
2 plotting symbols
with(dat, plot(X, Y, pch=ifelse(PCH=="a", 1, 20)))

# for n plotting symbols, simpler
set.seed(12)
head(dat <- data.frame(X=rnorm(20), Y=rnorm(20),
PCH=sample(letters[1:5], 20, replace=TRUE)))
with(dat, plot(X, Y, pch=as.numeric(PCH)))
# and of course as.numeric(PCH) could be used with subsetting

# for n plotting symbols, more customizable
with(dat, plot(X, Y, pch=c(20, 18, 16, 1, 10)[as.numeric(PCH)]))

Best,
STG
--
Stefan Th. Gries
----------------------------------
Univ. of California, Santa Barbara
http://tinyurl.com/stgries
----------------------------------
Reply all
Reply to author
Forward
0 new messages