4

我将如何使用 R 绘制非数值数据频率的条形图?

例如,如果给定v = c("B","A","B","A","B","D","C","D","D","D","C")

我想得到一个条形图,其中每个条形代表向量中的一个唯一值,每个条形的高度与该值的频率相对应:

在此处输入图像描述

4

1 回答 1

11

Calculate the table of values for the barplot using the table() function, e.g.:

v <- c("B","A","B","A","B","D","C","D","D","D","C")
barplot(table(v))

This produces

barplot example figure

于 2012-09-18T22:18:00.897 回答