Join positive and negative numbers with different direction in one plot in R [closed]












1















I have posite and negative numbers, but in different direction. There is undesirable step change. How to put correctly values. Numbers -1 and 1 must be on the same level. Negative numbers on top half and vice versa.



Example:



x <- 1:10 
y <- c(0.9, 0.92, 0.94, 0.96, 0.98, 1, -0.98, -0.96, -0.94,-0.92)
plot(x, y, type="b", ylab = "Value", xlab = "Time [seconds]")


plot with undesirable step change










share|improve this question















closed as unclear what you're asking by RLave, phiver, Patrick Mevzek, zx485, KittMedia Jan 20 at 0:16


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.



















  • Something like this ? plot(x, abs(y), type = "b", ylim = c(0, 1))

    – Darren Tsai
    Jan 19 at 9:57











  • No. Ok maybe more accurate question: How to reverse only top half y axis in plot?

    – Joseph
    Jan 19 at 10:02
















1















I have posite and negative numbers, but in different direction. There is undesirable step change. How to put correctly values. Numbers -1 and 1 must be on the same level. Negative numbers on top half and vice versa.



Example:



x <- 1:10 
y <- c(0.9, 0.92, 0.94, 0.96, 0.98, 1, -0.98, -0.96, -0.94,-0.92)
plot(x, y, type="b", ylab = "Value", xlab = "Time [seconds]")


plot with undesirable step change










share|improve this question















closed as unclear what you're asking by RLave, phiver, Patrick Mevzek, zx485, KittMedia Jan 20 at 0:16


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.



















  • Something like this ? plot(x, abs(y), type = "b", ylim = c(0, 1))

    – Darren Tsai
    Jan 19 at 9:57











  • No. Ok maybe more accurate question: How to reverse only top half y axis in plot?

    – Joseph
    Jan 19 at 10:02














1












1








1








I have posite and negative numbers, but in different direction. There is undesirable step change. How to put correctly values. Numbers -1 and 1 must be on the same level. Negative numbers on top half and vice versa.



Example:



x <- 1:10 
y <- c(0.9, 0.92, 0.94, 0.96, 0.98, 1, -0.98, -0.96, -0.94,-0.92)
plot(x, y, type="b", ylab = "Value", xlab = "Time [seconds]")


plot with undesirable step change










share|improve this question
















I have posite and negative numbers, but in different direction. There is undesirable step change. How to put correctly values. Numbers -1 and 1 must be on the same level. Negative numbers on top half and vice versa.



Example:



x <- 1:10 
y <- c(0.9, 0.92, 0.94, 0.96, 0.98, 1, -0.98, -0.96, -0.94,-0.92)
plot(x, y, type="b", ylab = "Value", xlab = "Time [seconds]")


plot with undesirable step change







r ggplot2 plot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 10:31









Darren Tsai

2,1261427




2,1261427










asked Jan 19 at 9:36









JosephJoseph

135




135




closed as unclear what you're asking by RLave, phiver, Patrick Mevzek, zx485, KittMedia Jan 20 at 0:16


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by RLave, phiver, Patrick Mevzek, zx485, KittMedia Jan 20 at 0:16


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.















  • Something like this ? plot(x, abs(y), type = "b", ylim = c(0, 1))

    – Darren Tsai
    Jan 19 at 9:57











  • No. Ok maybe more accurate question: How to reverse only top half y axis in plot?

    – Joseph
    Jan 19 at 10:02



















  • Something like this ? plot(x, abs(y), type = "b", ylim = c(0, 1))

    – Darren Tsai
    Jan 19 at 9:57











  • No. Ok maybe more accurate question: How to reverse only top half y axis in plot?

    – Joseph
    Jan 19 at 10:02

















Something like this ? plot(x, abs(y), type = "b", ylim = c(0, 1))

– Darren Tsai
Jan 19 at 9:57





Something like this ? plot(x, abs(y), type = "b", ylim = c(0, 1))

– Darren Tsai
Jan 19 at 9:57













No. Ok maybe more accurate question: How to reverse only top half y axis in plot?

– Joseph
Jan 19 at 10:02





No. Ok maybe more accurate question: How to reverse only top half y axis in plot?

– Joseph
Jan 19 at 10:02












2 Answers
2






active

oldest

votes


















0














I've created a new vector new_y by adding 2 if y is negative and keeping y otherwise. But now the y axis ranges from 0 to 1,1 approximately



new_y <- ifelse(y<0,y+2,y)

plot(x, new_y, type="b", ylab = "Value", xlab = "Time [seconds]")





share|improve this answer


























  • No, it doesnt work.. It is not so simply, because "ylim" does not change direction of positive or negative numbers...

    – Joseph
    Jan 19 at 9:43











  • I think I did not understand your question then, what do you mean by "change direction" ?

    – fmarm
    Jan 19 at 9:46











  • Make reverse only part y axis an then is -1 and 1 are on the same level without stepchange.

    – Joseph
    Jan 19 at 9:54











  • Ok I have seen your image, and updated my answer

    – fmarm
    Jan 19 at 10:40











  • THX but plot should be approximately : imgur.com/a/uUYEwuT

    – Joseph
    Jan 19 at 10:45



















0















x <- 1:10



y <- c(0.9, 0.92, 0.94, 0.96, 0.98, 1, -0.98, -0.96, -0.94,-0.92)



cols <- ifelse(y >= 0, 2, 4)



yy <- y yy[y < 0] <- yy[y < 0] + 2



plot(x, yy, col=cols, yaxt="n", pch=19, type="b", ylab = "Value", xlab
= "Time [seconds]")



axis(2, at=yy, labels=y, las=2)




Plot solution



I am not author of solution.






share|improve this answer






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    I've created a new vector new_y by adding 2 if y is negative and keeping y otherwise. But now the y axis ranges from 0 to 1,1 approximately



    new_y <- ifelse(y<0,y+2,y)

    plot(x, new_y, type="b", ylab = "Value", xlab = "Time [seconds]")





    share|improve this answer


























    • No, it doesnt work.. It is not so simply, because "ylim" does not change direction of positive or negative numbers...

      – Joseph
      Jan 19 at 9:43











    • I think I did not understand your question then, what do you mean by "change direction" ?

      – fmarm
      Jan 19 at 9:46











    • Make reverse only part y axis an then is -1 and 1 are on the same level without stepchange.

      – Joseph
      Jan 19 at 9:54











    • Ok I have seen your image, and updated my answer

      – fmarm
      Jan 19 at 10:40











    • THX but plot should be approximately : imgur.com/a/uUYEwuT

      – Joseph
      Jan 19 at 10:45
















    0














    I've created a new vector new_y by adding 2 if y is negative and keeping y otherwise. But now the y axis ranges from 0 to 1,1 approximately



    new_y <- ifelse(y<0,y+2,y)

    plot(x, new_y, type="b", ylab = "Value", xlab = "Time [seconds]")





    share|improve this answer


























    • No, it doesnt work.. It is not so simply, because "ylim" does not change direction of positive or negative numbers...

      – Joseph
      Jan 19 at 9:43











    • I think I did not understand your question then, what do you mean by "change direction" ?

      – fmarm
      Jan 19 at 9:46











    • Make reverse only part y axis an then is -1 and 1 are on the same level without stepchange.

      – Joseph
      Jan 19 at 9:54











    • Ok I have seen your image, and updated my answer

      – fmarm
      Jan 19 at 10:40











    • THX but plot should be approximately : imgur.com/a/uUYEwuT

      – Joseph
      Jan 19 at 10:45














    0












    0








    0







    I've created a new vector new_y by adding 2 if y is negative and keeping y otherwise. But now the y axis ranges from 0 to 1,1 approximately



    new_y <- ifelse(y<0,y+2,y)

    plot(x, new_y, type="b", ylab = "Value", xlab = "Time [seconds]")





    share|improve this answer















    I've created a new vector new_y by adding 2 if y is negative and keeping y otherwise. But now the y axis ranges from 0 to 1,1 approximately



    new_y <- ifelse(y<0,y+2,y)

    plot(x, new_y, type="b", ylab = "Value", xlab = "Time [seconds]")






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jan 19 at 10:39

























    answered Jan 19 at 9:39









    fmarmfmarm

    77210




    77210













    • No, it doesnt work.. It is not so simply, because "ylim" does not change direction of positive or negative numbers...

      – Joseph
      Jan 19 at 9:43











    • I think I did not understand your question then, what do you mean by "change direction" ?

      – fmarm
      Jan 19 at 9:46











    • Make reverse only part y axis an then is -1 and 1 are on the same level without stepchange.

      – Joseph
      Jan 19 at 9:54











    • Ok I have seen your image, and updated my answer

      – fmarm
      Jan 19 at 10:40











    • THX but plot should be approximately : imgur.com/a/uUYEwuT

      – Joseph
      Jan 19 at 10:45



















    • No, it doesnt work.. It is not so simply, because "ylim" does not change direction of positive or negative numbers...

      – Joseph
      Jan 19 at 9:43











    • I think I did not understand your question then, what do you mean by "change direction" ?

      – fmarm
      Jan 19 at 9:46











    • Make reverse only part y axis an then is -1 and 1 are on the same level without stepchange.

      – Joseph
      Jan 19 at 9:54











    • Ok I have seen your image, and updated my answer

      – fmarm
      Jan 19 at 10:40











    • THX but plot should be approximately : imgur.com/a/uUYEwuT

      – Joseph
      Jan 19 at 10:45

















    No, it doesnt work.. It is not so simply, because "ylim" does not change direction of positive or negative numbers...

    – Joseph
    Jan 19 at 9:43





    No, it doesnt work.. It is not so simply, because "ylim" does not change direction of positive or negative numbers...

    – Joseph
    Jan 19 at 9:43













    I think I did not understand your question then, what do you mean by "change direction" ?

    – fmarm
    Jan 19 at 9:46





    I think I did not understand your question then, what do you mean by "change direction" ?

    – fmarm
    Jan 19 at 9:46













    Make reverse only part y axis an then is -1 and 1 are on the same level without stepchange.

    – Joseph
    Jan 19 at 9:54





    Make reverse only part y axis an then is -1 and 1 are on the same level without stepchange.

    – Joseph
    Jan 19 at 9:54













    Ok I have seen your image, and updated my answer

    – fmarm
    Jan 19 at 10:40





    Ok I have seen your image, and updated my answer

    – fmarm
    Jan 19 at 10:40













    THX but plot should be approximately : imgur.com/a/uUYEwuT

    – Joseph
    Jan 19 at 10:45





    THX but plot should be approximately : imgur.com/a/uUYEwuT

    – Joseph
    Jan 19 at 10:45













    0















    x <- 1:10



    y <- c(0.9, 0.92, 0.94, 0.96, 0.98, 1, -0.98, -0.96, -0.94,-0.92)



    cols <- ifelse(y >= 0, 2, 4)



    yy <- y yy[y < 0] <- yy[y < 0] + 2



    plot(x, yy, col=cols, yaxt="n", pch=19, type="b", ylab = "Value", xlab
    = "Time [seconds]")



    axis(2, at=yy, labels=y, las=2)




    Plot solution



    I am not author of solution.






    share|improve this answer




























      0















      x <- 1:10



      y <- c(0.9, 0.92, 0.94, 0.96, 0.98, 1, -0.98, -0.96, -0.94,-0.92)



      cols <- ifelse(y >= 0, 2, 4)



      yy <- y yy[y < 0] <- yy[y < 0] + 2



      plot(x, yy, col=cols, yaxt="n", pch=19, type="b", ylab = "Value", xlab
      = "Time [seconds]")



      axis(2, at=yy, labels=y, las=2)




      Plot solution



      I am not author of solution.






      share|improve this answer


























        0












        0








        0








        x <- 1:10



        y <- c(0.9, 0.92, 0.94, 0.96, 0.98, 1, -0.98, -0.96, -0.94,-0.92)



        cols <- ifelse(y >= 0, 2, 4)



        yy <- y yy[y < 0] <- yy[y < 0] + 2



        plot(x, yy, col=cols, yaxt="n", pch=19, type="b", ylab = "Value", xlab
        = "Time [seconds]")



        axis(2, at=yy, labels=y, las=2)




        Plot solution



        I am not author of solution.






        share|improve this answer














        x <- 1:10



        y <- c(0.9, 0.92, 0.94, 0.96, 0.98, 1, -0.98, -0.96, -0.94,-0.92)



        cols <- ifelse(y >= 0, 2, 4)



        yy <- y yy[y < 0] <- yy[y < 0] + 2



        plot(x, yy, col=cols, yaxt="n", pch=19, type="b", ylab = "Value", xlab
        = "Time [seconds]")



        axis(2, at=yy, labels=y, las=2)




        Plot solution



        I am not author of solution.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Jan 19 at 12:57









        JosephJoseph

        135




        135















            Popular posts from this blog

            Homophylophilia

            Updating UILabel text programmatically using a function

            Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage