【问题标题】:R: basic Barplot from a named listR:命名列表中的基本条形图
【发布时间】:2016-10-03 01:22:52
【问题描述】:
我在网上搜索了 2 个多小时,以找到一种方法来制作列表的条形图。我想将名称(my_list)作为 x 标签,将列表元素的值作为它们的高度。但我真的对 R 的不同语法感到困惑。谁能给我一个提示吗?!
barplot(unlist(my_list))
有效,但没有元素的 x 轴标签。
barplot(unlist(my_list))
得到:
Error in -0.01 * height : non-numeric argument to binary operator
【问题讨论】:
标签:
r
histogram
bar-chart
【解决方案1】:
所以看看这个问题,这似乎是你走在正确的道路上。您的列表声明可能有问题。例如,如果我将列表定义为
testList = list(first=1, second=2, third=3)
在 R 中通过 print(testList) 打印时的样子
$first
[1] 1
$second
[1] 2
$third
[1] 3
我能够按照您描述的方式创建条形图。我运行命令barplot(unlist(testList)) 并得到以下图表
Barplot Picture
希望这会有所帮助!如果您以其他方式定义您的列表,只需发表评论,我们可以在需要时讨论该问题。