[R] Multi-line graph?
Hi, I am relatively new to R but not to graphing, which I used to do in Excel and a few other environments on the job. I'm going back to school for a PhD and am teaching myself R beforehand. So I hope this question is not unacceptably ignorant but I have perused every entry level document I can find and so far I'm out of luck. I'm trying to graph some simple music psychology data. Columns are musical intervals, rows are the initials of the subjects. Numbers are in beats per minute (this is the value at which they hear the melodic interval split into two streams). So here's my table: Tenth Fifth Third GG 112152 168 EC 100120 140 SQ 160 184NA SK 120 100 180 I want a multi-line graph where the intervals are on the X axis, and the y axis is the beats per minute, and each subject has a different line. In Excel this would be no problem but I am having trouble in R. The only way I can figure out how to plot this in R is if the columns or rows are taken as variables. But the variable is beats per minute. Any suggestions? I appreciate the help. -Eric -- View this message in context: http://r.789695.n4.nabble.com/Multi-line-graph-tp2997402p2997402.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Multi-line graph?
barnhillec wrote: I'm trying to graph some simple music psychology data. Columns are musical intervals, rows are the initials of the subjects. Numbers are in beats per minute (this is the value at which they hear the melodic interval split into two streams). So here's my table: Tenth Fifth Third GG 112152 168 EC 100120 140 SQ 160 184NA SK 120 100 180 I want a multi-line graph where the intervals are on the X axis, and the y axis is the beats per minute, and each subject has a different line. The most difficult part of it (at least that's what my students think) is getting the data into the right format. If you have the changes to start with the data in the long format, use it. What you need is: init interval beats GC Tenth112 In this case, reformatting almost works with the default version of the melt function in package reshape. It's good that you supplied a data example, but in general it is better if you could provide it in a copy-and-paste format as shown below. I needed more time to reformat the data than to write the rest. Dieter library(lattice) library(reshape) dt = data.frame( init = c(GG,EC, SQ,SK), Tenth = c(112,100,160,120), Fifth = c(152,120,184,100), Third = c(168,140,NA,180)) # The data should look like this #init interval beats #GC Tenth112 #dtlong = melt(dt) # almost does it, but column variable is ugly dtlong = melt(dt,variable_name=beats) # better dtlong xyplot(value~variable,groups=init,data=dtlong,type=l, auto.key=list(lines=TRUE)) -- View this message in context: http://r.789695.n4.nabble.com/Multi-line-graph-tp2997402p2997435.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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.
Re: [R] Multi-line graph?
?matplot e.g., copy your data to the clipboard then library(psych) my.data - read.clipboard() my.data Tenth Fifth Third GG 112 152 168 EC 100 120 140 SQ 160 184NA SK 120 100 180 matplot(t(my.data),type=b) Bill At 10:27 AM -0700 10/15/10, barnhillec wrote: Hi, I am relatively new to R but not to graphing, which I used to do in Excel and a few other environments on the job. I'm going back to school for a PhD and am teaching myself R beforehand. So I hope this question is not unacceptably ignorant but I have perused every entry level document I can find and so far I'm out of luck. I'm trying to graph some simple music psychology data. Columns are musical intervals, rows are the initials of the subjects. Numbers are in beats per minute (this is the value at which they hear the melodic interval split into two streams). So here's my table: Tenth Fifth Third GG 112152 168 EC 100120 140 SQ 160 184NA SK 120 100 180 I want a multi-line graph where the intervals are on the X axis, and the y axis is the beats per minute, and each subject has a different line. In Excel this would be no problem but I am having trouble in R. The only way I can figure out how to plot this in R is if the columns or rows are taken as variables. But the variable is beats per minute. Any suggestions? I appreciate the help. -Eric -- View this message in context: http://r.789695.n4.nabble.com/Multi-line-graph-tp2997402p2997402.html Sent from the R help mailing list archive at Nabble.com. __ R-help@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. __ R-help@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.