【问题标题】:Break X Axis in R在 R 中断开 X 轴
【发布时间】:2013-11-05 21:36:23
【问题描述】:

我想在我的情节中获得一个损坏的 X 轴。在 x 轴上,我喜欢插入一个断轴符号 < // > [从 2 开始,到 8 结束,这意味着 2-8 将隐藏在 < // > 符号中],因此可以强调其他值。在 Matlab 中,这个任务是通过使用BreakXAxis 来执行的。在 R 中,plotrix 库仅有助于插入断轴符号,仅此而已。

x <- c(9.45, 8.78, 0.93, 0.47, 0.24, 0.12)
y <- c(10.72, 10.56, 10.35, 10.10, 9.13, 6.72)
z <- c(7.578, 7.456, 6.956, 6.712, 4.832, 3.345)
plot(x, y, col='blue', pch=16, xlab= 'x', ylab='y, z')
points(x, z, col='red', pch=17)
library(plotrix)
axis.break(1,2,style="slash") 

【问题讨论】:

    标签: r plotrix


    【解决方案1】:

    听起来你需要gap.plot

    library(plotrix)
    par(bty="n") # deleting the box
    gap.plot(x,y, gap=c(2,7.5), gap.axis="x", pch=16,
             col="blue", ylim=range(c(y,z)),
             xtics=c(0:3,8:10), xticlab=c(0:3,8:10))
    
    gap.plot(x,z, gap=c(2,7.5), gap.axis="x", pch=17,
             col="red", ylim=range(c(y,z)), add=TRUE); axis(2)
    
    abline(v=seq(1.99,2.09,.001), col="white")  # hiding vertical lines
    axis.break(1,2,style="slash")               # plotting slashes for breakpoints
    

    【讨论】:

      【解决方案2】:
      xgap <- ifelse(x > 8, x-6, x)
      #Possibly you'd want to check if there are values between 2 and 8.
      plot(xgap, y, col='blue', pch=16, xlab= 'x', ylab='y, z', xaxt="n")
      points(xgap, z, col='red', pch=17)
      xat <- pretty(xgap)
      xat <- xat[xat!=2]
      xlab <- ifelse(xat>2, xat+6, xat)
      axis(1,at=xat, labels=xlab)
      library(plotrix)
      axis.break(1,2,style="slash") 
      

      不要这样做。 gap.plot 提供了一个更好的选择,但我可能会使用 facets,例如 ggplot2。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-04-13
        • 2020-08-29
        • 1970-01-01
        • 1970-01-01
        • 2018-10-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多