Home > OS >  R Correction of curves and scale
R Correction of curves and scale

Time:12-07

I have my code that generates curves for me:


C=c(0,0.3,1.5,3.5,19.5)
v1=c(0.00, 0.00, 0.01, 0.22, 0.84) 
v2=c(0.10, 0.74, 1.00, 1.00, 1.00)
mlist_procent = c(0.9852836, 0.7762951, 0.3899078, 0.2281043, 0.0602995)


plot_c <-plot(C, mlist_procent, type = "b", pch = 19, ylim = range(mlist_procent),
              col = "black",  xlab = "C", ylab = "means")

par(new=TRUE)
plot_c4 <-plot(C, v1, type = "b", pch = 19, ylim = range(mlist_procent),
               col = "blue", xlab = "C", ylab = "means")
par(new=TRUE)
plot_c5 <-plot(C, v2, type = "b", pch = 19, ylim = range(mlist_procent),
               col = "red", xlab = "C", ylab = "means")

I want to get a plot where the blue and red curves are inverse and there is only one scale on the y-axis.

I try :


plot_c <- plot(C, mlist_procent, type = "b", pch = 19, ylim = range(mlist_procent),
               col = "black", xlab = "C", ylab = "means", ann = FALSE)
par(new = TRUE)
plot_c4 <- plot(C, v1, type = "b", pch = 19, ylim = rev(range(mlist_procent)),
                col = "blue", xlab = "C", ylab = "means", ann = FALSE)
par(new = TRUE)
plot_c5 <- plot(C, v2, type = "b", pch = 19, ylim = rev(range(mlist_procent)),
                col = "red", xlab = "C", ylab = "means", ann = FALSE)

I get more scales on the y-axis and also fewer points for the blue curve I need all curves to have 5 points how change it for the blue curve? Do I need to somehow normalize the data before plotting? I don't know how to fix my plot so please help me

CodePudding user response:

I think you just need to use one plot statement and a custom ylim values if I follow what you are after

This:

plot_c <-plot(C, mlist_procent, type = "b", pch = 19, ylim = c(0,1.1),
              col = "black",  xlab = "C", ylab = "means")
lines(C,v1,col="blue")
points(C,v1,col="blue",pch=19)
lines(C,v2,col="red")
points(C,v2,col="red",pch=19)

To invert the red and blue curves you can just do:

plot_c <-plot(C, mlist_procent, type = "b", pch = 19, ylim = c(0,1.1),
              col = "black",  xlab = "C", ylab = "means")
lines(C,1-v1,col="blue")
points(C,1-v1,col="blue",pch=19)
lines(C,1-v2,col="red")
points(C,1-v2,col="red",pch=19)

produces

enter image description here

  • Related