I want to plot two graphs on one figure. In matlab i plot the first graph and then use hold on
and then ask it to plot the second graph. This is the code I have written so far. The retrieval of the data is correct. Each list has 6 numbers. I tried using the ''' par''' but i it plots one plot on a graph but overlaps the names.
tempLength <- dim(R_to_C_03M)
tempLength <- tempLength ## gives me the width of R_to_C_03M
tempnames <- colnames(R1)
if (tempLength>2){
for( i in 2:tempLength){
lipid1<-as.numeric(R_to_C_03M[1,i]) # Gets the column number of the first lipid
lipid2<-as.numeric(R_to_C_03M[2,i]) # Gets the column number of the seccond lipid
list1<- R1_table[,lipid1] #Retrives the data from the colum.
list2<- R1_table[,lipid2]
list3<- C1_table[,lipid1]
list4<- C1_table[,lipid2]
plot(lipid1,lipid2,xlab = tempnames[lipid1], ylab =tempnames[lipid2])
par(new=TRUE)
plot(list3,list4)
}
}
I want two plots to be displayed on one graph, using the same axis if possible. First plot being list2 against list1, and the second being list4 against list3. The x axis values for the different graphs are different however i want to the axis to be the same, other questions and answers have used the same x axis values
Solution:
if (tempLength>2){
for( i in 2:tempLength){
lipid1<-as.numeric(R_to_C_03M[1,i])
lipid2<-as.numeric(R_to_C_03M[2,i])
list1<- R1_table[,lipid1] #Retrives the data from the colum.
list2<- R1_table[,lipid2]
list3<- C1_table[,lipid1]
list4<- C1_table[,lipid2]
lipid1name <- tempnames[lipid1]
lipid2name <-tempnames[lipid2]
plot(list1,list2,xlab = lipid1name, ylab =lipid2name)
par(new=TRUE)
plot(list3,list4,xlab='', ylab='',axes=FALSE)
par(new=FALSE)
}
}