Ein eingebundener Text mit undefiniertem Zeichensatz wurde abgetrennt. Name: nicht verf?gbar URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20120216/6192b6e7/attachment.pl>
Multiple line-plot
3 messages · David Studer, Dallas, John Kane
I think this is what you are getting at. Hope this helps.
#index data to determine what low and high levels of tvHrs are (I said
anything over 15 hours is considered 'high')
index=which(tvHrs > 15)
#Plot the first plot, which is the 'high', only using values from crimeDvp
that are in 'index' (corresponding to high levels of tvHrs
plot(prop.table(table(crimeDvp[index])),type='b',ylab='percent',xlab='crime
dev',col='red')
lines(prop.table(table(crimeDvp[-index])),type='b', col='black')
lines(prop.table(table(crimeDvp)),type='b',col='green')
legend("topright", inset=.05, title="TV consume", c("high","low","all"),
fill=c('red','black','green'))
--
View this message in context: http://r.789695.n4.nabble.com/Multiple-line-plot-tp4394539p4395262.html
Sent from the R help mailing list archive at Nabble.com.
What are you expecting to get? At the moment it appears that you are just ploting one data vector. table() is giving you a one row table. BTW you probably should not use data as a data.frame name. It is a reserved word. John Kane Kingston ON Canada
-----Original Message-----
From: studerov at gmail.com
Sent: Thu, 16 Feb 2012 17:18:32 +0100
To: r-help at r-project.org
Subject: [R] Multiple line-plot
Hello everybody!
I have again another newbie-question. I was trying to plot three curves
within one single
plot: Crime development (relative frequencies) according to the hours of
tv
consume per week (high/low/all together).
Here are the data:
par(mfrow=c(1,1))
# Data input
tvHrs<-c(21,22,23,24,25,26,27,28,21,22,23,24,25,26,27,28,2,3,4,5,6,7,8,9,10,11,12,13,14)
crimeDvp<-c(2,2,2,2,2,3,3,3,3,3,3,3,4,4,5,5,2,2,3,3,3,3,3,4,4,4,4,5,5)
crimeDvp<-factor(crimeDvp, levels=1:5,
labels=c("strongly\nincreased","increased","equal","decreased","strongly\ndecreased"),
ordered=T)
data<-data.frame(tvHrs, crimeDvp)
# Plotting lines
plot(prop.table(table(crimeDvp)), type='b', ylab='percent', xlab='crime
development')
legend("topright", inset=.05, title="TV consume", c("high","low","all"),
fill=c("red","black","green"))
I have experimented with the lines()-function, but couldnt do it. Thank
you
for any hints!
David
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
____________________________________________________________ Share photos & screenshots in seconds... TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if1 Works in all emails, instant messengers, blogs, forums and social networks.