How to customize shape in scale_shape

18 views
Skip to first unread message

Changhong Yu

unread,
Apr 1, 2009, 9:54:32 AM4/1/09
to ggp...@googlegroups.com
Dear list users,

I would like to make a plot of the predicted values (preds) versus the observed  (obs). I also want to mark the points as "+" if a disease status (di) is TRUE, but "-" if id is FALSE.
Here is the example code.

set.seed(1000)
dat <- data.frame( preds= runif(20), obs = runif(20),
     di = sample(c("FALSE", "TRUE"),20,TRUE))
>dat
  > dat
        preds        obs    di
1  0.32787871 0.16294456  TRUE
2  0.75884649 0.80494934  TRUE
3  0.11393640 0.28962222 FALSE
4  0.69075515 0.07177347  TRUE
5  0.51640240 0.54830544  TRUE
6  0.06773796 0.67655327  TRUE
7  0.73871486 0.45189608  TRUE
8  0.58353505 0.82412502  TRUE
9  0.21577140 0.09076793 FALSE
10 0.25612240 0.12221227  TRUE
11 0.34993746 0.56751754  TRUE
12 0.75546158 0.04970992  TRUE
13 0.31708425 0.56162037 FALSE
14 0.86581282 0.96617891  TRUE
15 0.76416075 0.50994534  TRUE
16 0.07288487 0.70093692  TRUE
17 0.49261774 0.02034940  TRUE
18 0.63516203 0.78356903  TRUE
19 0.08485787 0.58439662  TRUE
20 0.58392103 0.31729282 FALSE
qplot(preds,obs,data = dat,shape=di)

How can I change the default shapes (i.e. diamond and triangle) into "-" and "+" ? Thanks.

Changhong

Gary Collins

unread,
Apr 1, 2009, 10:09:02 AM4/1/09
to ggp...@googlegroups.com
how about...

p <- qplot(preds, obs, data = dat, shape = di)
p + scale_shape_manual(name = "disease status", values = c("+", "-"),
labels = c("positive", "negative"))

hope that helps

Gary
------------------------------------
Dr Gary S Collins
Centre for Statistics in Medicine
Wolfson College Annexe
University of Oxford
Linton Road
Oxford, OX2 6UD

Tel: +44 (0)1865 284418
Fax: +44 (0)1865 284424
www.csm-oxford.org.uk
------------------------------------

Changhong Yu

unread,
Apr 1, 2009, 10:16:51 AM4/1/09
to Gary Collins, ggp...@googlegroups.com
It works. Thanks very much.

Changhong
Reply all
Reply to author
Forward
0 new messages