Excel中无法实现分组区分颜色。
右边的图是我手动点击各个柱形修改分组颜色的。
请问如何在R和Excel中分别实现右图?谢谢!
原始数据已经放在Sheet2里,代码放在下面:
library(tidyverse)
a <- openxlsx::read.xlsx("E:/histgram_filled_by_groups.xlsx",
sheet = "Sheet2",
fillMergedCells = TRUE, # 填充所拆散的合并单元格
colNames = TRUE) %>% as_tibble() %>%
mutate(type =
type %>% factor(),
month =
c(1,2,1,3,1,2,3),
month =
month %>% factor(levels = c(1,2,3),
labels = c("Jan","Feb","Mar"))) %>%
arrange(type,month)
a %>% group_by(type,month) %>%
ggplot(mapping = aes(x = type,
y = value,
colour = month)) +
geom_histogram()
错误: stat_bin() can only have an x or y aesthetic.
我知道是x = type出了问题,但是我不知道怎么改。