当我查看我的旧项目时,我注意到我的报告中没有包含图表的代码。 你能帮我如何得到下面的图表吗?
数据表,
分数 | 变量 | 实际 | 泊伊斯 |
---|---|---|---|
0 | 离开 | 0.316 | 0.314 |
0 | 家 | 0.228 | 0.213 |
1 | 离开 | 0.366 | 0.363 |
1 | 家 | 0.313 | 0.329 |
2 | 离开 | 0.205 | 0.210 |
2 | 家 | 0.248 | 0.254 |
3 | 离开 | 0.081 | 0.081 |
3 | 家 | 0.137 | 0.131 |
4 | 离开 | 0.016 | 0.023 |
4 | 家 | 0.055 | 0.050 |
5 | 离开 | 0.009 | 0.005 |
5 | 家 | 0.003 | 0.015 |
6 | 离开 | 0.003 | 0.001 |
6 | 家 | 0.006 | 0.004 |
我想要得到的图表,
谢谢你, 维利
这让你相当接近
library(ggplot2)
ggplot(within(df, variable <- factor(variable, c("home", "away"))),
aes(Score, Actual, fill = variable, color = variable)) +
geom_col(position = position_dodge(width = 0.9), color = NA) +
geom_line(aes(y = Pois), position = position_dodge(width = 0.9),
linewidth = 1.5) +
geom_point(aes(y = Pois), position = position_dodge(width = 0.9),
fill = NA, size = 4) +
scale_fill_manual("Actual", values = c("#ffbca1", "#62c9c3")) +
scale_color_manual("Poisson", values = c("#cd5c5c", "#006400")) +
scale_x_continuous(breaks = 0:6) +
labs(x = "Goals per match", y = "Proportion of matches",
title = "Number of Goals per Match (TSL 2015-2016 Season)") +
theme_classic(base_size = 20) +
theme(text = element_text(face = "bold"),
legend.position = c(0.75, 0.85),
legend.box.background = element_rect(color = "black", fill = "white"),
legend.background = element_blank(),
legend.box = "horizontal",
panel.border = element_rect(fill = NA, color = "black"))