如何绘制R个可格式化的对象?

时间:2019-01-09 16:39:01

标签: r

我有3个要垂直绘制的文本/数字表。它们的定义与此类似,但按顺序命名(pq2_plot和pq3_plot)

pq1_plot <- formattable(pq1_diffs, list(sla_diff = formatter("span", style = function(x) ifelse(x < 0 , "color:red", "color:green")),
                    bslc_diff = formatter("span", style = function(x) ifelse(x < 0 , "color:red", "color:green")),
                    sum17_diff = formatter("span", style = function(x) ifelse(x < 0 , "color:red", "color:green"))
                    )
            )

如果不清楚,则数据框只有4列。我尝试了以下两种方法,并在顶部pq1_plot

par(mfrow=c(3,1))
plot(pq1_plot)
plot(pq2_plot)
plot(pq3_plot)

也尝试过:

ggpubr::ggarrange(pq1_plot, pq2_plot, pq3_plot, 
                  heights = c(5, 9, 13), 
                  nrow = 3, 
                  align = "v")

我从另一个使用ggpubr的脚本中获得了一些图,所以我想尝试一下。此错误产生以下错误:Argument needs to be of class "ggplot", "gtable", "grob", "recordedplot", or a function that plots to an R graphicsdevice when called, but is a formattabledata.frame

其中一张表的图片:

enter image description here

该表的数据:

structure(list(mean_2018 = c(4, 2.75, 3.87, 3.8, 3), sla_diff = c(0.18, -0.72, 0.14, 0.44, -0.58), bslc_diff = c(0.3, -0.69, 0.23, 0.49, -0.45), sum17_diff = c(0, -0.5, 0.48, 0.8, -0.33)), row.names = c(NA, -5L), class = "data.frame")

因此,我可以通过以下方式绘制基本表:

pq1 <- tableGrob(pq1_plot)
pq2 <- tableGrob(pq2_plot)
pq3 <- tableGrob(pq1_plot)
grid.arrange(pq1, pq2, pq3, nrow=3, ncol=1)

但是它们彼此重叠,并且没有我需要的条件突出显示。如果有办法做到这一点,那将是最佳选择

0 个答案:

没有答案