ggplot2:使用grid.arrange()作为do.call()的参数定义绘图布局

时间:2015-05-18 09:29:00

标签: r ggplot2 gridextra

我想获得一个不平衡的情节网格,例如

EntityWrapper

enter image description here

但使用函数

require(ggplot2)
require(gridExtra)

df <- data.frame(value1 = rnorm(200),
                 value2 = rnorm(200),
                 value3 = rnorm(200),
                 value4 = rnorm(200))

p1 <- ggplot(df) + geom_density(aes(x=value1))
p2 <- ggplot(df) + geom_density(aes(x=value2))
p3 <- ggplot(df) + geom_density(aes(x=value3))
p4 <- ggplot(df) + geom_density(aes(x=value4))

grid.arrange(p1, arrangeGrob(p2,p3,p4, ncol=3), heights=c(2.5/4, 1.5/4), ncol=1)

myplot <- function(i){ p <- ggplot(df) + geom_density(aes_string(x=i)) return(p) } 来电

lapply

在这种情况下,p <- lapply(c("value1","value2","value3","value4"), myplot) do.call(grid.arrange, c(p)) 将图分布在2×2矩阵中。但我希望获得与

一样的不平衡布局
grid.arrange

1 个答案:

答案 0 :(得分:22)

你现在可以做,

 SELECT   distinct a.personidno as 'PersonId', a.[LastHireDate], a.[TerminationDate],  --COUNT(distinct a.PersonIdNo) 
    CASE    WHEN a.EmploymentStatus = 'Regular Full Time' THEN 'RFT'
            WHEN a.EmploymentStatus = 'PRN' THEN 'PRN'
            WHEN a.EmploymentStatus = 'Regular Part Time' THEN 'RPT'
            ELSE a.EmploymentStatus
    END as 'EmpStatus'
  --into #tmp_ytd_hc_avg
  FROM [EmployeeTable] a
  where 
  a.OrgCodeIdNo = '69' and
  (a.[TerminationDate] >= '2015-01-01 00:00:00' and a.[TerminationDate] <= '2015-06-30 23:59:59')
  OR (a.[TerminationDate] is null and a.employeestatus = 'Active')