Re: [R] Line Graphs
I want to plot 6 line graphs. I have 10 points 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 and 1.0. At each point say 0.1, I have 6 variables A, B, C, D, E and F. The variables all have values between 0 and 1 (and including 0 and 1). I also want to label the x axis from 0.1 to 1.0 and the y axis from 0.1 to 1.0. My goal is to plot a line graph representing the mean of the variables at each level. SO for 0.1 on the xaxis, we should expect 6 values for y. This is what I have so far. The plot omits 1.0 and the abline function does not make the line y = x on the plot This is what I have so far: # Calculate range from 0 to max value of cars and trucks g_range - range(0, 1) # Graph autos using y axis that ranges from 0 to max # value in cars or trucks vector. Turn off axes and # annotations (axis labels) so we can specify them ourself plot(B, type=o, pch = 0, lty=1,col=blue, ylim=g_range, axes=FALSE, ann=FALSE) As you are currently doing it, you are not specifying a x variable. This means you are getting an 'index plot'. If I understand what you want it would be simpler to just specify x in your plot statement. From there if you absolutely need EVERY 0.1 labeled you could suppress the axis and label by hand if you want. Something along the line of: A =runif(10) B =runif(10) C =runif(10) D =runif(10) E =runif(10) F =runif(10) x = seq(0.1, 1.0, 0.1) plot(x, B, type=o, pch = 0, lty=1,col=blue, xlim = c(0,1), ylim = c(0,1), xlab=expression(paste(lambda[0])), ylab= expression(paste(Estimate of , lambda[0]))) # Graph trucks with red dashed line and square points lines(x, A, type=o, pch=2, lty=1, col=red) lines(x, C, type=o, pch=3, lty=1, col=green) lines(x, D, type=o, pch=4, lty=1, col=orange) lines(x, E, type=o, pch=6, lty=1, col=brown) lines(x, F, type=o, pch=8, lty=1, col=yellow) abline(0, 1, col = black) # Create a title with a red, bold/italic font title(main=Methods, col.main=red, font.main=4) # Create a legend at (1, g_range[2]) that is slightly smaller # (cex) and uses the same line colors and points used by # the actual plots legend(1, g_range[2], c(B,A, C, D, E, F, Actual), cex=0.6, col=c(blue,red, green, orange, brown,yellow, black), pch=c(0,2,3,4,6,8,9), lty=1) Rob # Make x axis using the values of pi_0 labels # axis(1, at=1:10, lab=c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0)) # Make y axis with horizontal labels that display ticks at del = seq(0.1,1, 0.1) axis(2, at=del, lab=c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0)) # Create box around plot box() # Graph trucks with red dashed line and square points lines(A, type=o, pch=2, lty=1, col=red) lines(C, type=o, pch=3, lty=1, col=green) lines(D, type=o, pch=4, lty=1, col=orange) lines(E, type=o, pch=6, lty=1, col=brown) lines(F, type=o, pch=8, lty=1, col=yellow) abline(0, 1, col = black) # Create a title with a red, bold/italic font #title(main=Methods, col.main=red, font.main=4) # Label the x and y axes title(xlab=expression(paste(lambda[0]))) title(ylab= expression(paste(Estimate of , lambda[0]))) # Create a legend at (1, g_range[2]) that is slightly smaller # (cex) and uses the same line colors and points used by # the actual plots legend(1, g_range[2], c(B,A, C, D, E, F, Actual), cex=0.6, col=c(blue,red, green, orange, brown,yellow, black), pch=c(0,2,3,4,6,8,9), lty=1) -- Thanks, Jim. [[alternative HTML version deleted]] __ 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. -- Robert W. Baer, Ph.D. Professor of Physiology Kirksville College of Osteopathic Medicine A. T. Still University of Health Sciences 800 W. Jefferson St. Kirksville, MO 63501 660-626-2322 FAX 660-626-2965 __ 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] Line Graphs
Thanks Rob, but the legend is not appearing in the plot. I think the best place for it is on the top left. Is there anyway I can also get it broken down in tenths instead of fifths? The legend is easy; just specify where you want it. The first 2 parameters specify the x, y of the top left coroner. See ?legend. As to getting tenths on the axes, using axes = FALSE and drawing them manually where you want them is as easy as anything. The following should work: A =runif(10) B =runif(10) C =runif(10) D =runif(10) E =runif(10) F =runif(10) x = seq(0.1, 1.0, 0.1) plot(x, B, type=o, pch = 0, lty=1,col=blue, xlim = c(0,1), ylim = c(0,1), axes = FALSE, xlab=expression(paste(lambda[0])), ylab= expression(paste(Estimate of , lambda[0]))) axis(1, at = seq(0,1,0.1)) axis(2, at = seq(0,1,0.1)) box() # Graph trucks with red dashed line and square points lines(x, A, type=o, pch=2, lty=1, col=red) lines(x, C, type=o, pch=3, lty=1, col=green) lines(x, D, type=o, pch=4, lty=1, col=orange) lines(x, E, type=o, pch=6, lty=1, col=brown) lines(x, F, type=o, pch=8, lty=1, col=yellow) abline(0, 1, col = black) # Create a title with a red, bold/italic font title(main=Methods, col.main=red, font.main=4) # Create a legend at (1, g_range[2]) that is slightly smaller # (cex) and uses the same line colors and points used by # the actual plots legend(0, 1, c(B,A, C, D, E, F, Actual), cex=0.6, col=c(blue,red, green, orange, brown,yellow, black), pch=c(0,2,3,4,6,8,9), lty=1) HTH, Rob I want to plot 6 line graphs. I have 10 points 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 and 1.0. At each point say 0.1, I have 6 variables A, B, C, D, E and F. The variables all have values between 0 and 1 (and including 0 and 1). I also want to label the x axis from 0.1 to 1.0 and the y axis from 0.1 to 1.0. My goal is to plot a line graph representing the mean of the variables at each level. SO for 0.1 on the xaxis, we should expect 6 values for y. This is what I have so far. The plot omits 1.0 and the abline function does not make the line y = x on the plot This is what I have so far: # Calculate range from 0 to max value of cars and trucks g_range - range(0, 1) # Graph autos using y axis that ranges from 0 to max # value in cars or trucks vector. Turn off axes and # annotations (axis labels) so we can specify them ourself plot(B, type=o, pch = 0, lty=1,col=blue, ylim=g_range, axes=FALSE, ann=FALSE) As you are currently doing it, you are not specifying a x variable. This means you are getting an 'index plot'. If I understand what you want it would be simpler to just specify x in your plot statement. From there if you absolutely need EVERY 0.1 labeled you could suppress the axis and label by hand if you want. Something along the line of: A =runif(10) B =runif(10) C =runif(10) D =runif(10) E =runif(10) F =runif(10) x = seq(0.1, 1.0, 0.1) plot(x, B, type=o, pch = 0, lty=1,col=blue, xlim = c(0,1), ylim = c(0,1), xlab=expression(paste(lambda[0])), ylab= expression(paste(Estimate of , lambda[0]))) # Graph trucks with red dashed line and square points lines(x, A, type=o, pch=2, lty=1, col=red) lines(x, C, type=o, pch=3, lty=1, col=green) lines(x, D, type=o, pch=4, lty=1, col=orange) lines(x, E, type=o, pch=6, lty=1, col=brown) lines(x, F, type=o, pch=8, lty=1, col=yellow) abline(0, 1, col = black) # Create a title with a red, bold/italic font title(main=Methods, col.main=red, font.main=4) # Create a legend at (1, g_range[2]) that is slightly smaller # (cex) and uses the same line colors and points used by # the actual plots legend(1, g_range[2], c(B,A, C, D, E, F, Actual), cex=0.6, col=c(blue,red, green, orange, brown,yellow, black), pch=c(0,2,3,4,6,8,9), lty=1) Rob # Make x axis using the values of pi_0 labels # axis(1, at=1:10, lab=c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0)) # Make y axis with horizontal labels that display ticks at del = seq(0.1,1, 0.1) axis(2, at=del, lab=c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0)) # Create box around plot box() # Graph trucks with red dashed line and square points lines(A, type=o, pch=2, lty=1, col=red) lines(C, type=o, pch=3, lty=1, col=green) lines(D, type=o, pch=4, lty=1, col=orange) lines(E, type=o, pch=6, lty=1, col=brown) lines(F, type=o, pch=8, lty=1, col=yellow) abline(0, 1, col = black) # Create a title with a red, bold/italic font #title(main=Methods, col.main=red, font.main=4) # Label the x and y axes title(xlab=expression(paste(lambda[0]))) title(ylab= expression(paste(Estimate of , lambda[0]))) # Create a legend at (1, g_range[2]) that is slightly smaller # (cex) and uses the same line colors and points used by # the actual plots legend(1, g_range[2], c(B,A, C, D, E, F, Actual), cex=0.6, col=c(blue,red, green, orange, brown,yellow, black), pch=c(0,2,3,4,6,8,9), lty=1) -- Thanks, Jim. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help
Re: [R] Line Graphs
Hello, I want to plot 6 line graphs. I have 10 points 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 and 1.0. At each point say 0.1, I have 6 variables A, B, C, D, E and F. The variables all have values between 0 and 1 (and including 0 and 1). I also want to label the x axis from 0.1 to 1.0 and the y axis from 0.1 to 1.0. My goal is to plot a line graph representing the mean of the variables at each level. SO for 0.1 on the xaxis, we should expect 6 values for y. This is what I have so far. The plot omits 1.0 and the abline function does not make the line y = x on the plot This is what I have so far: # Calculate range from 0 to max value of cars and trucks g_range - range(0, 1) # Graph autos using y axis that ranges from 0 to max # value in cars or trucks vector. Turn off axes and # annotations (axis labels) so we can specify them ourself plot(B, type=o, pch = 0, lty=1,col=blue, ylim=g_range, axes=FALSE, ann=FALSE) # Make x axis using the values of pi_0 labels # axis(1, at=1:10, lab=c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0)) # Make y axis with horizontal labels that display ticks at del = seq(0.1,1, 0.1) axis(2, at=del, lab=c(0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0)) # Create box around plot box() # Graph trucks with red dashed line and square points lines(A, type=o, pch=2, lty=1, col=red) lines(C, type=o, pch=3, lty=1, col=green) lines(D, type=o, pch=4, lty=1, col=orange) lines(E, type=o, pch=6, lty=1, col=brown) lines(F, type=o, pch=8, lty=1, col=yellow) abline(0, 1, col = black) # Create a title with a red, bold/italic font #title(main=Methods, col.main=red, font.main=4) # Label the x and y axes title(xlab=expression(paste(lambda[0]))) title(ylab= expression(paste(Estimate of , lambda[0]))) # Create a legend at (1, g_range[2]) that is slightly smaller # (cex) and uses the same line colors and points used by # the actual plots legend(1, g_range[2], c(B,A, C, D, E, F, Actual), cex=0.6, col=c(blue,red, green, orange, brown,yellow, black), pch=c(0,2,3,4,6,8,9), lty=1) -- Thanks, Jim. [[alternative HTML version deleted]] __ 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] Line graphs with NA
Hi, I have sets of three points provided by subjects that I want to graph as lines over a specific range, but the subjects were split into two groups and provided different points. The subjects provided a y-value for the given x-value, for example: Subject: 1 2 3 4 ... 127 1NA3 2 NA ... 24NANA 4 366.5 6 5.5 47NA NA7 5 NA8 7.5NA Using matplot() or xyplot() I can easily get R to plot the lines for subjects 1 and 4, but R wont draw lines connecting the points for subjects 2 and 3 since there are missing values. I want R to just connect the points for B and C as if the missing values don't matter and make it look as if each subject provided 5 points. What is the best way to do this? - Chris __ 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] Line graphs with NA
Try this. na.approx fills in missing values. See ?na.approx, ?approx and ?plot.zoo and the three zoo vignettes. Lines - 'Subject: 1 2 3 4 1NA3 2 NA 24NANA 4 366.5 6 5.5 47NA NA7 5 NA8 7.5NA' DF - read.table(textConnection(Lines), header = TRUE) library(zoo) z - zoo(as.matrix(DF[-1])) plot(na.approx(z, rule = 2), screen = 1, type = o, pch = 20) On Sun, Dec 28, 2008 at 1:39 PM, Chris Poliquin poliq...@sas.upenn.edu wrote: Hi, I have sets of three points provided by subjects that I want to graph as lines over a specific range, but the subjects were split into two groups and provided different points. The subjects provided a y-value for the given x-value, for example: Subject: 1 2 3 4 ... 127 1NA3 2 NA ... 24NANA 4 366.5 6 5.5 47NA NA7 5 NA8 7.5NA Using matplot() or xyplot() I can easily get R to plot the lines for subjects 1 and 4, but R wont draw lines connecting the points for subjects 2 and 3 since there are missing values. I want R to just connect the points for B and C as if the missing values don't matter and make it look as if each subject provided 5 points. What is the best way to do this? - Chris __ 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.