我正在使用一种策略在热图中使用 绘制汇总(总计)行geom_tile,这涉及data_frame在行和列总计中创建额外的行:
library(dplyr)
library(ggplot2)
entitites = LETTERS[1:10]
# create some sample data
df_foo = bind_cols(
data_frame(Group1 = rep(c("A", "B"), each = 100)),
bind_rows(
expand.grid(
Left = entitites, Right = entitites,
stringsAsFactors = FALSE
),
expand.grid(
Left = entitites, Right = entitites,
stringsAsFactors = FALSE
)
),
data_frame(Value = rpois(200, 15))
)
# create the summary row & column
df_foo_aug = bind_rows(
df_foo,
df_foo %>%
group_by(Left, Group1) %>%
summarize(
Value = sum(Value),
Right = "Total"
),
df_foo …Run Code Online (Sandbox Code Playgroud)