我有3个表希望左对齐。我发誓昨天我能做到这一点,但是突然之间它现在返回一个错误(将其放在代码之后)
以下是数据和代码:
> dput(features)
structure(list(`2018` = c(4, 4, 4), `vs '17` = c(0, 1, 3), `vs Pilot` = c(0.47,
0.58, 0.26), `vs ALL` = c(0.37, 0.48, 0.22), `vs General` = c(0.42,
0.54, 0.21)), row.names = c(NA, -3L), class = "data.frame")
> dput(features_matrix)
structure(c("black", "black", "black", "black", "green", "green",
"green", "green", "green", "green", "green", "green", "green",
"green", "green"), .Dim = c(3L, 5L), .Dimnames = list(NULL, c("2018",
"vs '17", "vs Pilot", "vs ALL", "vs General"
)))
> dput(youth)
structure(list(`2018` = c(4, 3, 3, NaN, NaN, NaN), `vs '17` = c(0,
1, 1, NaN, NaN, NaN), `vs Pilot` = c(0.32, 0.63, 0.95,
NaN, NaN, NaN), `vs ALL` = c(0.26, 0.59, 0.93, NaN, NaN,
NaN), `vs General` = c(0.29, 0.46, 0.83, NaN, NaN, NaN)), row.names = c(NA,
-6L), class = "data.frame")
> dput(youth_matrix)
structure(c("black", "black", "black", "black", "black", "black",
"black", "green", "green", NA, NA, NA, "green", "red", "green",
NA, NA, NA, "green", "red", "green", NA, NA, NA, "green", "red",
"green", NA, NA, NA), .Dim = 6:5, .Dimnames = list(NULL, c("2018",
"vs '17", "vs BoSTEM Pilot", "vs BoSTEM ALL", "vs General SY"
)))
> dput(engage_diff)
structure(list(`2018` = c(4, 3, 4, NaN, NaN, NaN), `vs '17` = c(3,
1, 1, NaN, NaN, NaN), `vs Pilot` = c(1.32, -0.05, 1.21,
NaN, NaN, NaN), `vs ALL` = c(1.22, -0.19, 1.07, NaN, NaN,
NaN), `vs General` = c(1.21, -0.08, 1.17, NaN, NaN, NaN)), row.names = c(NA,
-6L), class = "data.frame")
> dput(engage_matrix)
structure(c("black", "black", "black", "black", "black", "black",
"green", "green", "green", NA, NA, NA, "green", "red", "green",
NA, NA, NA, "green", "red", "green", NA, NA, NA, "green", "red",
"green", NA, NA, NA), .Dim = 6:5, .Dimnames = list(NULL, c("2018",
"vs '17", "vs BoSTEM Pilot", "vs BoSTEM ALL", "vs General SY"
)))
comp_table_cols <- c("2018", "vs '17", "vs Pilot", "vs ALL", "vs SY")
tt <- ttheme_minimal(core=list(fg_params = list(col = features_matrix)),
colhead=list(fg_params=list(col="black", fontface=1L, cex = 0.8)),
rowhead=list(fg_params=list(col=NA))
)
features_diff_plot <- tableGrob(features_diff, theme = tt)
colnames(youth_diff) <- comp_table_cols
youth_matrix <- ifelse(engage_diff < 0, "red", ifelse(youth_diff > 0, "green", "black"))
youth_matrix[,1] <- "black"
tt <- ttheme_minimal(core=list(fg_params = list(col = youth_matrix)),
colhead=list(fg_params=list(col=NA)),
rowhead=list(fg_params=list(col=NA))
)
youth_diff_plot <- tableGrob(youth_diff, theme = tt)
colnames(engage_diff) <- comp_table_cols
engage_matrix <- ifelse(engage_diff < 0, "red", ifelse(engage_diff > 0, "green", "black"))
engage_matrix[,1] <- "black"
tt <- ttheme_minimal(core=list(fg_params = list(col = engage_matrix)),
colhead=list(fg_params=list(col=NA)),
rowhead=list(fg_params=list(col=NA))
)
engage_diff_plot <- tableGrob(engage_diff, theme = tt)
colnames(stem_diff) <- comp_table_cols
stem_matrix <- ifelse(stem_diff < 0, "red", ifelse(stem_diff > 0, "green", "black"))
stem_matrix[,1] <- "black"
tt <- ttheme_minimal(core=list(fg_params = list(col = stem_matrix)),
colhead=list(fg_params=list(col=NA)),
rowhead=list(fg_params=list(col=NA))
)
stem_diff_plot <- tableGrob(stem_diff, theme = tt)
plot_grid(features, youth, engage,
, ncol = 1
, rel_heights = c(3, 6, 8)
#, axis = "l"
, align = "h"
)
错误:
Warning message:
In align_plots(plotlist = plots, align = align, axis = axis) :
Graphs cannot be horizontally aligned, unless axis parameter set. Placing graphs unaligned.
希望我可以上载输出内容的图片,但是应该这样,以便所有列都彼此对齐。
我尝试弄乱plot_grid函数的axis
和align
参数,但无法用左对齐来绘制这些表。取消注释axis
参数时,我没有收到错误消息,但是它不能解决对齐问题。任何帮助将不胜感激