在Barplot中使用DataFrame

时间:2019-04-28 19:25:38

标签: r

具有以下df

Year Qty
2005 400
2006 555
2007 234
...

如何在barplot中使用它? 试过这个,但是没用

barplot(df1,xlab="Quantity",ylab="Year",main="foo")
'height' must be a vector or a matrix

1 个答案:

答案 0 :(得分:0)

它可以是命名向量

barplot(setNames(df$Qty, df$Year), xlab="Year", ylab="Quantity", main="foo")

数据

df <- structure(list(Year = 2005:2007, Qty = c(400L, 555L, 234L)),
     class = "data.frame", row.names = c(NA, -3L))

-情节

enter image description here