【问题标题】:Plot - Invalid xlim value绘图 - 无效的 xlim 值
【发布时间】:2014-03-06 01:21:27
【问题描述】:

我想在一个简单的线图中绘制两个向量,然后想在 0 x 轴点处添加一条线。

这就是我尝试实现它的方式:

sale <- 
structure(c(-0.049668136, 0.023675638, -0.032249731, -0.071487224, 
-0.034017265, -0.031278933, -0.052070721, -0.034305542, -0.019041209, 
-0.050459175, -0.017315808, -0.012787003, -0.03341208, -0.045078144, 
-0.036638132, -0.036533367, -0.012683656, -0.014388251, -0.006775188, 
-0.037153807, -0.008941402, -0.011760677, -0.005077979, -0.041187417, 
-0.001966554, -0.028822067, 0.021828558, 0.016208791, -0.026897492, 
-0.032107207, -0.008496522, -0.028027096, -0.013746662, -0.004545603, 
-0.005679941, -0.004614187, 0.004083014, -0.012624954, -0.016362079, 
-0.006350167, -0.019551277), na.action = structure(42:45, class = "omit"))

purchase <- 
structure(c(0.042141187, 0.075875128, 0.090953485, 0.050951625, 
0.082566915, 0.184396833, 0.136625887, 0.042725409, 0.135028692, 
0.13201904, 0.093634104, 0.16776844, 0.13645719, 0.201365036, 
0.227589832, 0.236473792, 0.269064385, 0.200981722, 0.144739536, 
0.145256493, 0.040205545, 0.031577107, 0.014767345, 0.005843065, 
0.034805051, 0.082493053, 0.010572227, 0.000645763, 0.033368236, 
0.024326153, 0.038601182, 0.025446045, 0.000556418, 0.017201608, 
0.008316872, 0.059722053, 0.059695415, 0.076940829, 0.067650014, 
0.002029566, 0.008466334), na.action = structure(42:45, class = "omit"))


timeLine <- c(-20:+20)
plot(sale,type="b", xlim=timeLine)

Error in plot.window(...) : invalid 'xlim' value
par(new=T)

plot(purchase,type="b", xlim=timeLine)

Error in plot.window(...) : invalid 'xlim' value
par(new=F)

但是我得到Error in plot.window(...) : invalid 'xlim' value。为什么我的 timeLine false 实现了?

非常感谢您的回答!

【问题讨论】:

    标签: r plot statistics


    【解决方案1】:

    提供给“xlim”的向量只需有两个元素c(max,min)。试试这个:

    timeLine <- c(-20 , +20)
    plot(sale, type="b", xlim=timeLine)
    

    然后要绘制第二个项目,您应该使用线条(并且您不应该尝试重新指定 xlim:

    lines( purchase, type="b")
    

    除非你发现 ylimits 没有设置,并且 'purchase' 中的值范围与 'sale' 的值不重叠,所以你需要在 hte first plot cal 中设置 ylimits:

    plot(sale,type="b", xlim=timeLine, ylim=c(-.1,.4) )
    lines( purchase, type="b")
    

    这一切都可以更简单地处理:

    matplot( cbind( sale, purchase), type="b")
    

    【讨论】:

    • 感谢您的回答!是不是也可以在0点加一条直线?
    猜你喜欢
    • 2017-11-28
    • 1970-01-01
    • 2018-01-26
    • 1970-01-01
    • 2012-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多