df数据框添加黑色实线边框,包括表头
时间: 2023-06-05 11:09:07 浏览: 109
表单边框样式
您好,对于您的问题,我可以提供以下代码来实现df数据框添加黑色实线边框,包括表头的需求:
```
library(gridExtra)
library(grid)
library(ggplot2)
# Create Data Frame
df <- data.frame(x = 1:10, y = 11:20)
# Add black stroke border around the data frame
grid.newpage()
pushViewport(viewport(name = "vp1", x = 0.5, y = 0.5, width = 0.7, height = 0.7))
grid.rect(gp = gpar(lwd = 1, fill = NA, col = "black"))
grid.table(df, vp = "vp1", gpar.params = list(fill = "white", col = "black", lwd = 1), rows = NULL, theme = ttheme_minimal( core = list(bg_params = list(fill = "white"))))
# Add black stroke border around the header and text labels
grid.text("Label 1", x = 0.18, y = 0.95, gp = gpar(fontsize = 14, col = "black", fontface = "bold"))
grid.text("Label 2", x = 0.65, y = 0.95, gp = gpar(fontsize = 14, col = "black", fontface = "bold"))
grid.rect(x = c(0.05, 0.45), y = 0.9, width = 0.4, height = 0.1, gp = gpar(lwd = 1, fill = "white", col = "black"))
grid.rect(x = c(0.5, 0.9), y = 0.9, width = 0.4, height = 0.1, gp = gpar(lwd = 1, fill = "white", col = "black"))
# Save the plot
ggsave("dataframe_with_border.png")
```
希望这能够帮助您。如果您有任何其他问题,请随时提出。
阅读全文