2015-03-18 80 views
1

我有从列表创建为这样的载体:剧情ř矢量

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

在一个不相关的音符,那就是创造你的数据确实迂回的方式。你可以刚刚完成:'sort(c(a = 5.5,b = 3.4,c = 9.2),index.return = TRUE)' – thelatemail 2015-03-18 23:48:40

回答

1

试试这个:

plot(v1$x, type = "l", xaxt = "n") 
axis(1, at = v1$ix, label = names(v1$x)) 

enter image description here

+0

是的,这是可行的,谢谢!我感兴趣的是为每个x轴项目在我的折线图上绘制点。我怎么能把它们添加到这个图表? – 2015-03-18 23:47:21

+1

@Ameen - 'type =“o”' – thelatemail 2015-03-18 23:49:58