[英]Plot R vector with keys as X-axis and values as Y-axis
I have a vector created from a list as such: 我有一个从列表创建的向量,例如:
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)
With this new vector I am trying to plot a line graph so that the 'keys' ("a", "b", "c") are labeled on the x-axis and the 'values' (5.5, 3.4, 9.2) are labeled on the y-axis. 借助这个新矢量,我试图绘制线形图,以便在x轴上标记“键”(“ a”,“ b”,“ c”),并在“值”上标记(5.5、3.4、9.2)在y轴上标记。 So far I have tried the following.
到目前为止,我已经尝试了以下方法。
plot(v1, col = "red")
line(v1, col = "black")
I receive the error 我收到错误
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
Try this: 尝试这个:
plot(v1$x, type = "l", xaxt = "n")
axis(1, at = v1$ix, label = names(v1$x))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.