i have some matrix which are without column and row names,I want to plot these matrices in single plot,but the thing is that this matrix has big difference in their value.like one matrix has value around 0.987,0.89,0.0757
and another matrix has values like 0.0000045,0.000000345450,0.000000045893
. how can I plot matrices which are differ in their scale value? What should be the best way to plot in a single plot?
I have tried to convert the all values between 0 and 1 but its affecting the graph so its not working
I have used following command but didn't work:
plot((as.numeric(matrx1[1,])),type ="l",col="black",lwd=2)
lines((as.numeric(Matrix2[1,])),type ="l",col="blue",lwd=2)
Matrix 1:
V1 V2 V3 V4 V5 V6
1 0.1302677 0.1338888 0.1375044 0.1411146 0.1447193 0.1483186
2 0.9863382 0.9848000 0.9832758 0.9817656 0.9802694 0.9787871
Matrix 2
V1 V2 V3 V4 V5 V6
1 1.355474e-06 0 0 1.355474e-06 1.355474e-06 0
2 1.804942e-06 1.804942e-06 1.804942e-06 1.804942e-06 1.804942e-06 0
CodePudding user response:
You could do it this way, if you're committed to base R:
mat1 <- read.table(text="V1 V2 V3 V4 V5 V6
0.1302677 0.1338888 0.1375044 0.1411146 0.1447193 0.1483186
0.9863382 0.9848000 0.9832758 0.9817656 0.9802694 0.9787871", sep=" ", header=TRUE)
mat2 <- read.table(text="V1 V2 V3 V4 V5 V6
1.355474e-06 0 0 1.355474e-06 1.355474e-06 0
1.804942e-06 1.804942e-06 1.804942e-06 1.804942e-06 1.804942e-06 0", sep=" ", header=TRUE)
par(mar=c(5,4,4,4) .1)
plot((as.numeric(mat1[1,])),type ="l",col="black",lwd=2, ylab="y1")
par(new=TRUE)
plot((as.numeric(mat2[1,])),type ="l",col="blue",lwd=2, axes=FALSE, xlab="", ylab="")
axis(4)
mtext("y2", side=4, line=2.5)
Created on 2022-05-31 by the reprex package (v2.0.1)
CodePudding user response:
It depends on what the values mean. If there is a relation between both matrices, you probably don't want to modify the values, though you will not be able to plot both matrices in a single plot. In order to do so, I would recommend scaling one of the matrices, so the max element in both matrices are the same.
For example, ratio = 0.9863382 / 1.804942e-06
which are the largest numbers in both matrices. Then we need to multiply each number of Matrix 2 by this ratio. By doing this before plotting, you will obtain a nice plot of both matrices. As said before, you will lose perception of the relationship between both matrices.
If you end up doing this, mention the scaling ratio, so everyone understands how the numbers are obtained.