【问题标题】:Plot a line graph, error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ绘制折线图,​​xy.coords(x, y, xlabel, ylabel, log) 中的错误:“x”和“y”长度不同
【发布时间】:2013-11-17 02:32:01
【问题描述】:
a<- c(2,2)
b<- c(3,4)
plot(a,b) # It works perfectly here

然后我尝试了:

t<-xy.coords(a,b)
plot(t) # It also works well here

最后,我尝试了:

plot(t,1)

现在它告诉我:

xy.coords(x, y, xlabel, ylabel, log) 中的错误: “x”和“y”长度不同

它不起作用,在t内,a和b的长度都是2,为什么它显示x,y长度不同?

【问题讨论】:

  • 因为 length(t) 为 4,length(1) 为 1。
  • 嗨,我的朋友,我为 type = 1 做 1,这是线图
  • 这行得通吗? plot(t[[1]], t[[2]], type="l")

标签: r plot


【解决方案1】:

plot(t) 在这种情况下与

相同
plot(t[[1]], t[[2]])

正如错误消息所说,x 和 y 的长度不同,这是因为您针对 1 绘制了一个长度为 4 的列表:

> length(t)
[1] 4
> length(1)
[1] 1

在第二个示例中,您绘制了一个列表,其中包含名为 xy 的元素,两个向量的长度均为 2, 所以plot 绘制了这两个向量。

编辑:

如果你想画线使用

plot(t, type="l")

【讨论】:

  • 这有帮助。我遇到了类似的错误并尝试了这个并相应地调整了我的数组长度。谢谢。
猜你喜欢
  • 2021-07-05
  • 1970-01-01
  • 2017-06-26
  • 1970-01-01
  • 2015-03-23
  • 1970-01-01
  • 1970-01-01
  • 2016-10-29
  • 2021-08-18
相关资源
最近更新 更多