- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试制作一个功能,该功能将为我提供一个可用于 indesign、插画或inkscape 的绘图。在尝试这样做时,我有两个无法解决的问题。
1)设置我的情节(或只是grobTable)的宽度和高度:
我得到的输出非常小,当在 illustrator 中放大它时,字体会跟随并变大。因此我想用手动定义的宽度和高度来绘制图。
2) 有时标题、注释和行名会“错位”(有关详细信息,请参阅图 1 和图 2 之间的区别)。当行名很短时会发生这种情况。
library(gridExtra)
library(ggplot2)
data(diamonds)
## plot function
kryds.row <- function(x,y, p=100, decor="%", digits=3,
titel="", note="", red=219, green=55, blue= 153){
c <- table(x, y)
s <- as.character(sum(c))
s <- paste("Antal svarpersoner=", s, sep=" ")
j <- prop.table(c,1)
r <- c(rownames(j),"Total")
k <- c(colnames(j), "Total")
j <- addmargins(j, margin =2, FUN = sum)
j <- round(j, digits)
j[]<-paste(j*p, decor, sep=" ")
farve <- rgb(red,green,blue, maxColorValue =255)
table <- tableGrob(j,
cols = k,
gpar.coretext = gpar(fontsize = 12),
gpar.coltext = gpar(fontsize = 12,col="white"),
gpar.rowtext = gpar(fontsize = 12, fontface="bold"),
gpar.corefill = gpar(fill = rgb(255,255,255, maxColorValue =255), alpha = 1, col = NA),
gpar.rowfill = gpar(fill = rgb(255,255,255, maxColorValue =255), alpha = 1, col = NA),
gpar.colfill = gpar(fill = 0, alpha = 1 ,col= "white"),
equal.width = TRUE,
show.rownames = TRUE,
show.rsep = TRUE,
show.hlines = TRUE,
show.csep = FALSE,
show.vlines = FALSE,
show.box = FALSE,
padding.h = unit(15, "mm"),
padding.v = unit(8, "mm"),
core.just = "center",
row.just = "left",
separator = farve)
hh <- grobHeight(table)
ww <- grobWidth(table)
border <- roundrectGrob(x=0.5, y=0.5, width=ww, height=hh,
default.units="npc",
r=unit(0.1, "snpc"),
just="centre",
name=NULL, gp=gpar(col="white", fill=farve, vp=NULL))
border2 <- roundrectGrob(x=0.5, y=0.5, width=ww, height=hh,
default.units="npc",
r=unit(0.1, "snpc"),
just="centre",
name=NULL, gp=gpar(fill=NA, col=farve, vp=NULL))
title <- textGrob(titel,
x=unit(0.5,"npc") -0.5*ww + unit(5, "mm"),
y=unit(0.5,"npc") +0.5*hh + unit(2, "mm"),
vjust=0,hjust=0, gp=gpar(fontsize=12, fontface="bold"))
footnote <- textGrob(note,
x=unit(0.5,"npc") - 0.5*ww + unit(5,"mm"),
y=unit(0.5,"npc") - 0.5*hh,
vjust=1, hjust=0,gp=gpar( fontsize=10))
svarpersoner <- textGrob(s,
x=unit(0.5,"npc") + 0.5*ww -unit(5, "mm"),
y=unit(0.5,"npc") + 0.5*hh + unit(2, "mm"),
vjust=0, hjust=1,gp=gpar( fontsize=10))
grid.newpage()
gt <- gTree(children=gList(border,table,border2, title, footnote, svarpersoner))
grid.draw(gt)
}
# Plot it
kryds.row(diamonds$color, diamonds$cut, titel="title", note="note") # plot 1
kryds.row(diamonds$cut, diamonds$color, titel="title", note="note") # plot 2
# Problems
#1: The title, note and the j in the row.text is very badly placed in plot 1 but not plot 2
#2 I cannot set the width and height of my table
最佳答案
gridExtra::tableGrob 的当前版本不允许您设置宽度/高度。但是,您可以尝试不同的 (experimental)使用 gtable 从头构建的 tableGrob 版本。
#library(devtools)
#install_github("tablegrob", "baptiste")
require(tablegrob)
d <- iris[sample(seq.int(nrow(iris)), 6),]
grid.newpage()
pushViewport(viewport(height=0.8,width=0.9))
g2 <- tableGrob(d, rows=NULL,
widths=unit(1,"null"), heights=unit(1/(nrow(d)),"npc"))
grid.draw(g2)
grid.roundrect(y=unit(0,"line"), height=unit(1,"npc") +unit(1,"lines"),
just="bottom", r=unit(0.05, "snpc"))
关于r - tableGrob : set the height and width of a grid. 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16471808/
我有一些相对简单的代码来创建用于打印为 PDF 的表格: library(gridExtra) df <- head(iris) tableGrob(df, gp = gpar(fontsize =
当我创建一个带有左对齐字符串的 tableGrob 时,最终结果显示字符串最后被剪掉了。 是错误还是我错过了什么? library(gridExtra) slices <- c(10, 12, 4,
在 R 中使用 ggplot2 和 gridExtra,我有一个要绘制和保存的 tableGrob。 假设它是一个像这样的小表(你可以自己用内置数据集 iris 试试): ggsave(plot=ta
如何在表格中添加上标?例如,df 的列 b 会将重复索引指示为上标。 我可以考虑将 b 列的值作为表达式引入,但可能有更好的方法。 数据: df <- data.frame( a = 1:6, b =
有没有办法增加tableGrob中列名的单元格?元素? library(grid) d <- head(iris, 3) g <- tableGrob(d) grid.newpage() grid.d
我想用 ggplot 绘制一个表格,但是似乎无法丢失 row.names。 我试过了: row.names(cov_table_a)<-NULL # outside the plot row.name
这个问题在这里已经有了答案: Align grob at fixed top/center position, regardless of size (1 个回答) 关闭 3 年前。 我想将 tab
我有以下数据框 df section_name #> 1 WWW #> 2 WWW:XXX:YYY #> 3 WWW:ZZZ #> 4 WWW:ZZZ:
使用默认表输出时,默认情况下是使用参数名称(在本例中为 k1 和 k2)绘制“轴”标签。这对于比较集群成员资格特别有用,最重要的是要表示哪个集群是行,哪个是列。 table( k1=matrix(
我希望自定义 tableGrob 中的特定列,对于这个可重现的示例,我选择查看自定义理由。 假设您有以下数据框: df <- data.frame(Order = c(1:3), Name = c("
我有一系列调查问题,正在报告学校、学校家庭和整个董事会的答复。有些问题很长——我想做的是让文本在专栏结束时自动换行。现在我必须手动添加换行符。这可能吗?我使用的是 R 版本 3.2.1 和 gridE
我在这里阅读了 Baptiste 对 gridextra 的 tableGrob 函数的精彩解释:https://github.com/baptiste/gridextra/wiki/tableGro
我很难找到对齐 ggplot grob 和 table grob 的解决方案。我试图按照说明here但仍然没有给出我想要的结果。 library(grid) library(gridExtra) li
在对齐网格图形对象时遇到了一些麻烦——我已经阅读了我能找到的所有文档,包括 Murrell 的书,但没有成功。我认为我正在尝试做的事情非常简单,所以希望我缺少简单的东西。 这是一个可重现的示例,它将按
我正在尝试制作一个功能,该功能将为我提供一个可用于 indesign、插画或inkscape 的绘图。在尝试这样做时,我有两个无法解决的问题。 1)设置我的情节(或只是grobTable)的宽度和高度
有没有一种优雅的方法可以将 tableGrob 行与轴中断对齐? 我想在 R 中并列一个 tableGrob 和 ggplot 图表(我需要重现以前版本的公共(public)报告中使用的一些 SAS
我想要实现的目标 我正在尝试在 ggparagraph() 中实现边距,但找不到任何有帮助的设置。我尝试在 ggarrange() 中将两个宽度设置为相同,但这没有用,这是一种解决方法。当我从 gga
我正在尝试将多个 tableGrob 对象与一个 ggplot 对象合并到一个 .png 文件中;我无法理解如何以允许我调整表格对象的填充和尺寸的方式编辑 tableGrob 主题参数。理想情况下,我
我想知道如何在 gridExtra 2.0.0 中做我在以前版本中可以做的来改变表格宽度/高度填充,例如: grid.arrange(tableGrob(mtcars,padding.h=unit(1
我已经搜索了一段时间,但我仍然无法解决这个小问题,我想更改 tablegrob() 创建的表格中数字的小数位。这样做会使整个 View 看起来更好,如下所示: 这是代码: a<-as.vector(m
我是一名优秀的程序员,十分优秀!