簡體   English   中英

使用鍵作為X軸和值作為Y軸繪制R向量

[英]Plot R vector with keys as X-axis and values as Y-axis

我有一個從列表創建的向量,例如:

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)

借助這個新矢量,我試圖繪制線形圖,以便在x軸上標記“鍵”(“ a”,“ b”,“ c”),並在“值”上標記(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

嘗試這個:

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

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM