我在R中有一个数据框,看起来像这样:
Requirements Documentation Development Delivery
After After During During
Before After Before After
After Before Before During
During During After Before
...
我需要创建一个直方图,其外观必须类似于下图,但是我无法创建正确的数据集
任何帮助将不胜感激。
答案 0 :(得分:0)
请检查以下内容:https://stackoverflow.com/help/minimal-reproducible-example
df <- data.frame(
Requirement = c("After", "Before", "After", "During"),
Documentation = c("After", "After", "Before", "During"),
Development = c("During", "Before", "Before", "After"),
Delivery = c("During", "After", "During", "Before")
)
您首先必须以长格式重塑数据框
library(tidyr)
newdf <- gather(df)
p <- ggplot(data=newdf, aes(x=key, y=value, fill = value)) +
geom_bar(stat="identity", color="black", position=position_dodge())+
theme_minimal()
p