2017-10-19 82 views
0

我想在2x2绘图中粘贴四张图以适合单个页面。我正在使用Sweave包来用Latex生成PDF。R-4使用Sweave绘制2x2图

这是我的代码,但是,它会将每个图形生成为单个页面。

<<plot1, fig=TRUE, echo=FALSE>>= 
slices <- c(3, 1,1) 
lbls <- c("Bien", "Regular", "Mal") 
pie(slices, labels = lbls, main="¿Cómo te está sentando la medicación?") 
@ 

<<plot2, fig=TRUE, echo=FALSE>>= 
slices <- c(2, 2,1) 
lbls <- c("Si", "Puedo mejorarla", "No") 
pie(slices, labels = lbls, main="¿Estás llevando una alimentación adecuada?") 
@ 

<<plot3, fig=TRUE, echo=FALSE>>= 
slices <- c(1, 1,3) 
lbls <- c("Si", "Puedo hacer más", "No") 
pie(slices, labels = lbls, main="¿Realizas suficiente ejercicio físico?") 
@ 

<<plot4, fig=TRUE, echo=FALSE>>= 
slices <- c(3, 3, 1,4,1) 
lbls <- c("Contento", "Tranquilo", "Enfadado", "Bien", "Nervioso", "Deprimido") 
pie(slices, labels = lbls, main="¿Cómo te has sentido anímicamente esta semana?") 
@ 
+1

使用'par(mfrow = c(2,2))'并且仅使用Sweave创建一个绘图。 – Mikko

+0

谢谢@Mikko,我如何使用Sweave创建独特的情节? –

+0

@R_user:你的意思是交叉参考吗?我会结合使用上述建议的情节,并为每个子情节添加字母。例如,请参阅:http://seananderson.ca/2013/10/21/panel-letters.html – Mikko

回答

1

,而不是试图在子图sweave在一起,我会创造一个Sweave情节,R中使用par结合地块,并添加子图字母在文本引用。例如:

<<plot1, fig=TRUE, echo=FALSE>>= 
par(mfrow = c(2,2)) 

slices <- c(3, 1,1) 
lbls <- c("Bien", "Regular", "Mal") 
pie(slices, labels = lbls, main="¿Cómo te está sentando la medicación?") 
legend("topleft", letters[1], bty = "n") 

slices <- c(2, 2,1) 
lbls <- c("Si", "Puedo mejorarla", "No") 
pie(slices, labels = lbls, main="¿Estás llevando una alimentación adecuada?") 
legend("topleft", letters[2], bty = "n") 

slices <- c(1, 1,3) 
lbls <- c("Si", "Puedo hacer más", "No") 
pie(slices, labels = lbls, main="¿Realizas suficiente ejercicio físico?") 
legend("topleft", letters[3], bty = "n") 

slices <- c(3, 3, 1,4,1) 
lbls <- c("Contento", "Tranquilo", "Enfadado", "Bien", "Nervioso", "Deprimido") 
pie(slices, labels = lbls, main="¿Cómo te has sentido anímicamente esta semana?") 
legend("topleft", letters[4], bty = "n") 
@