Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
278 views
in Technique[技术] by (71.8m points)

pch in plot with R

I have a dataset that I have plotted, I am now trying to build a legend with the corresponding point styles, the points are plotted correctly on the graph but the legend shows the same symbol for the binary response set. I am a bit confused as to why and hope it is something small. Here is my code

# data should already be loaded in from the project on the school drive
library(survival)
attach(lace)
lace

# To control the type of symbol we use we will use psymbol, it takes
# value 1 and 2
psymbol <- FAILURE + 1 
table(psymbol)
plot(AGE, TOTAL.LACE, pch=(psymbol))
legend(0, 15, c("FAILURE = 1", "FAILURE = 0"), pch=(psymbol))]

picture

Thank you,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

pysmbol is a vector of length n, where n is the number of data points in your data set. Your legend call is passing this entire vector to pch where you really only need a vector of length 2. Hence legend uses the first two elements of psymbol for pch. Now, go look at psymbol[1:2]. I'll be very surprised if that doesn't return two 1s.

I'd suggest you do pch = unique(psymbol). It looks like it should be a numeric vector so that should work.

Note that you don't need parentheses around psymbol in your calls, and attach()ing an object is considered poor practice unless you quickly detach() immediately after. See ?with for an alternative approach.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...