我有一个从列表中创建的向量:
l1 = list()
l1["a"] = 5.5
l1["b"] = 3.4
l1["c"] = 9.2
v1 = unlist(l1)
v1 = sort(v1, decreasing = F, index.return = T)
使用这个新的矢量,我试图绘制一个折线图,以便'键' (" a"," b"," c")在x轴上标记,'值' (5.5,3.4,9.2)在y轴上标记。到目前为止,我已尝试过以下内容。
plot(v1, col = "red")
line(v1, col = "black")
我收到错误
Error in xy.coords(x, y, xlabel, ylabel, log) :
'x' is a list, but does not have components 'x' and 'y'
Calls: plot -> plot -> plot.default -> xy.coords
答案 0 :(得分:1)
试试这个:
plot(v1$x, type = "l", xaxt = "n")
axis(1, at = v1$ix, label = names(v1$x))