在 R 中创建一个直方图,显示三组错误数量的差异

Creating a histogram in R that shows the difference in the number of errors made by three groups

我必须在 RStudio 中创建一个直方图,其中包含三 (3) 个数据组的错误数。有 A 组、B 组和 C 组。它们每个都有 4 个变量,其中之一是 "errors" 变量。所以它就像 GroupA$errors 等..

我如何组合这 3 个组并制作一个图,在该图上 x 轴显示 3 个条形图(每个条形图代表每个组),y 轴显示错误数量?

输入:http://pastebin.com/vGEPDNFf

你的数据:

myData <- data.frame(case = 1:48,
                     group = c(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3),
                     age = c(70,68,61,68,77,72,64,65,69,67,71,75,73,68,65,69,63,70,78,73,76,78,65,68,75,65,62,69,70,71,60,69,60,66,75,70,62,63,79,79,66,76,64,61,70,67,69,63),
                     errors = c(9,6,7,8,10,11,4,5,5,6,12,8,9,3,7,6,8,6,12,7,13,10,8,8,11,5,9,6,9,6,9,7,5,3,6,6,7,5,9,8,6,6,3,4,7,5,4,5))

这是您必须在 R 中 运行 的代码:

library(ggplot2)
library(dplyr)

myData %>%
  group_by(group) %>%
  summarize(total.errors=sum(errors)) %>%
  ggplot(aes(x=factor(group), y=total.errors)) + geom_bar(stat = "identity")

它给你下图: