show 0 in a log scale y axis of plot in R

后端 未结 3 1791
孤城傲影
孤城傲影 2021-01-22 05:25

Because the y values are too small, I need to use a log scale for y axis to show the differences. In the data, some entries do not have any value (0). Is there any way to show \

3条回答
  •  滥情空心
    2021-01-22 05:51

    If I understand your question correctly, what you want is 0 (zero) just to show on the y axis

    How about this

    y=c(0.1, 0.001, 0.00001, 0.0000001, 0.000000001, 0.0000000001)
    x=c(1, 2, 3, 4, 5, 6)
    plot(x, y, log="y",yaxt="n")
    axis(2,at=c(0.1, 0.001, 0.00001, 0.0000001, 0.000000001, 0.0000000001) ,labels=c(0.1, 0.001, 0.00001, 0.0000001, 0.000000001,"0"))
    

    enter image description here

    in plot yaxt="n" disables the drawing of the yaxis then i manually draw a y axis with axis and set the ticks location with the at argument. Then I set the lowest value i have (in your case 0.0000000001) to the character "0" (at the label argument)

提交回复
热议问题