# 如何在一个图中将两个sjp.likert（来自sjPlot包）生成的图合并？

[英]How to combine two sjp.likert (from the sjPlot package) generated plots in one plot?

``````likert_2 <- data.frame(as.factor(sample(1:2, 500, replace=TRUE, prob=c(0.3,0.7))),
as.factor(sample(1:2, 500, replace=TRUE, prob=c(0.6,0.4))),
as.factor(sample(1:2, 500, replace=TRUE, prob=c(0.25,0.75))),
as.factor(sample(1:2, 500, replace=TRUE, prob=c(0.9,0.1))),
as.factor(sample(1:2, 500, replace=TRUE, prob=c(0.35,0.65))))
levels_2 <- list(c("Disagree", "Agree"))

likert_4 <- data.frame(as.factor(sample(1:4, 500, replace=TRUE, prob=c(0.2,0.3,0.1,0.4))),
as.factor(sample(1:4, 500, replace=TRUE, prob=c(0.5,0.25,0.15,0.1))),
as.factor(sample(1:4, 500, replace=TRUE, prob=c(0.25,0.1,0.4,0.25))),
as.factor(sample(1:4, 500, replace=TRUE, prob=c(0.1,0.4,0.4,0.1))),
as.factor(sample(1:4, 500, replace=TRUE, prob=c(0.35,0.25,0.15,0.25))))
levels_4 <- list(c("Strongly disagree", "Disagree", "Agree", "Strongly Agree"))
items <- list(c("Q1", "Q2", "Q3", "Q4", "Q5"))

par(mfrow=c(2,1))
sjp.likert(likert_2, legendLabels=levels_2, axisLabels.y=items, orderBy="neg")
sjp.likert(likert_4, legendLabels=levels_4, axisLabels.y=items)
``````

`sjp.likert`返回不是基本图形的ggplot2-objects。

``````p1 <- sjp.likert(likert_2, legendLabels=levels_2, axisLabels.y=items, orderBy="neg")
p2 <- sjp.likert(likert_4, legendLabels=levels_4, axisLabels.y=items)
require(gridExtra)
require(grid)
require(ggplot2)
grid.arrange(p1\$plot, p2\$plot, nrow = 2)
``````