-1

I've got a 3-column .txt file where the first column is a contiguous integer index and the other 2 columns are floating-point values.

The task is to plot in x the first column and in y the remaining two columns

Sounds very simple but isn't actually very obvious to do for me because I'm very new to R, so excuse me for a question probably stupid.

rory
  • 19
  • 4
  • so you want one y-axis on the left and one y-axis on the right? which function do you use? plot? ggplot2? there some nice solutions on stackoverflow like http://stackoverflow.com/questions/6142944/how-can-i-plot-with-2-different-y-axes – rmuc8 Feb 10 '15 at 16:53
  • I would like to see in the same x-y plot the data took from my .txt file. the first column of the file would be my x and the remaining two column are the y. I was trying to use plot – rory Feb 10 '15 at 17:03
  • Please add reproducibility to your question. Most possible ways to do it have been [mentioned here](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Roman Luštrik Feb 11 '15 at 09:23
  • `library(lattice) data = c() head(s) data = data.frame("Mutual_information.txt", header = T, sep = ",") plot(1, 2, ylab="Mutual Information") par(new = TRUE) plot(1, 3, axes = F, ylab="Mutual Information", type="l")` – rory Feb 12 '15 at 13:43

1 Answers1

0

try this very basic example

x <- c(1:4)
y1 <- c(5:8)
y2 <- c(1,8,12,14)
df <- data.frame(x,y1,y2)
plot(x,y1,type="l",col="red")
par(new=TRUE)
plot(x,y2,type="l",col="blue")
axis(4)
rmuc8
  • 2,869
  • 7
  • 27
  • 36
  • I have tried this: data = data.frame("Mutual_information.txt", header = T, sep = ",") plot(1, 2, ylab="Mutual Information") par(new = TRUE) plot(1, 3, axes = F, ylab="Mutual Information", type="l") the problem is that what I've called 1,2 and 1,3 might be my file's column...they don't have a name so I don't know how to put them in my plot...sorry for the silly questions XD – rory Feb 10 '15 at 17:28
  • @laura try my example step by step. did you try to add `par(new=TRUE)` between your plots? – rmuc8 Feb 10 '15 at 17:32
  • yes I've tried your example and it is exactly what I have to do..and what I did...my problem now is to put the first column of my file in x and the other two columns in y. In my file the 3columns are not named they are just numbers so I don't know how to do that. thank you very much – rory Feb 10 '15 at 17:39