使用不显示频率分布的垂直条创建图形

时间:2016-05-10 09:12:23

标签: r bar-chart

我想知道如何绘制表示实际值的垂直双杠,而不是R中的频率分布。

1 个答案:

答案 0 :(得分:1)

以下是一些简单的例子。希望他们能帮忙。

df <- data.frame(x = 1:10, 
                 y = c(2, 3, 4, 5, 1, 2, 7, 8, 6, 4))

基本图形

barplot(height = df$y)

enter image description here

使用ggplot2

library(ggplot2)
ggplot(df, aes(x = x, y = y)) + 
  geom_bar(stat = "identity")

enter image description here

使用plotly

library(plotly)
plot_ly(df, x = x, y = y, type = "bar")

enter image description here

使用Lattice

library(lattice)
barchart(x~y, data = df)

enter image description here

相关问题