Question

I am new to R. I would like to create a plot in R by combining all the data in one graph with colour curves and legends.

My data file is in zipped format: http://www.datafilehost.com/d/e115550e

As I am beginner in R, I have learned to create one curve

$R

curve_17 <- read.table("samp_17.txt")

plot(curve_17[2:50,],type="l")

which produced one curve. But I need to combine all data samp_17.txt, samp_25.txt and samp_30.txt in one graph as given below

enter image description here

Was it helpful?

Solution

First, what you did with plot is not a histogram. It is just the plot of your data. You can try something like this:

> curve_17 <- read.table("C:/.../samp_17.txt")
> curve_25 <- read.table("C:/.../samp_25.txt")
> curve_30 <- read.table("C:/.../samp_30.txt")
> 
> plot(curve_17[2:50,],type="l",ylim=range(curve_17[2:50,],curve_25[2:50,],curve_30[2:50,]))
> points(curve_25[2:50,],type="l",col="blue",lwd=2)
> points(curve_30[2:50,],type="l",col="red",lwd=3)
> legend("topright",col=c("black","blue","red"),legend=c("curve_17","curve_25","curve_17"),lty=rep(1,3),lwd=1:3)
> 

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top