简体   繁体   English

使用键作为X轴和值作为Y轴绘制R向量

[英]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.

相关问题 y 轴上的名称和 x 轴上的值的 R 图 - R plot with names on the y-axis and values on the x-axis R图,x轴和y轴接触 - R plot, x-axis and y-axis touching Plot 日期在 x 轴和 y 轴“时间序列”R - Plot dates on x-axis and y-axis 'timeseries' R Plot 个使用 geom_rect 的矩形,x 轴为连续值,y 轴为离散值 (R) - Plot rectangles using geom_rect with continous x-axis and discrete values in y-axis (R) 除了R的默认图外,如何更改r中的x轴和y轴值? - How to change x-axis and y-axis value in r other than default plot by R? 使用r中的ggplot在y轴上使用相同的x轴绘制多个变量 - Plot multiple variables on y-axis with the same x-axis using ggplot in r 如何在以年为x轴和y轴为计数的R中绘制线形图? - How to plot line graph in R with years as x-axis and y-axis as count? 如何按收集日期(x 轴)和其他因素(R)plot % 阳性病例(y 轴)? - How to plot % positive cases (y-axis) by collection date (x-axis) and by other factors (R)? 如何使用R中的绘图功能更改散点图中x轴和y轴标签的字体大小和颜色? - How to change the font size and color of x-axis and y-axis label in a scatterplot with plot function in R? 在 R 基础 plot 和 GGPlot2 中的 x 轴和 y 轴上显示相应的虚线 - Show corresponding dash line on x-axis and y-axis in R base plot and GGPlot2
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM