首页 > 解决方案 > 如何使用范围表类在 R 中创建直方图?

问题描述

请帮帮我!我是统计学的初学者,我必须创建这个表的直方图(持续时间以小时为单位 x 灯的数量):

0-100: 82
100-200: 71
200-300: 68
300-400: 56
400-500: 43
500-800: 15

标签: r

解决方案


阿克伦是对的;该数据已经汇总,因此您可以制作条形图。

这是一种方法:

# load packages
library(dplyr)
library(ggplot2)
library(magrittr)

# set up our data frame, making the range into a factor for ordering
df <- tribble(~range, ~count,
"0-100", 82,
"100-200", 71,
"200-300", 68,
"300-400", 56,
"400-500", 43,
"500-800", 15) %>%
  mutate(range = factor(range))

# make a bar plot
df %>%
  ggplot() +
  geom_col(aes(x=range, y = count), width = 1)

推荐阅读