【问题标题】:R - 4 plots in 2x2 plot using SweaveR - 使用 Sweave 的 2x2 绘图中的 4 个绘图
【发布时间】:2017-10-19 08:33:26
【问题描述】:

我想在 2x2 图中粘贴四个图以适合单个页面。我正在使用包 Sweave 使用 Latex 生成 PDF。

这是我的代码,但是,它将每个绘图生成到一个页面。

<<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?")
@

【问题讨论】:

  • 使用 par(mfrow = c(2,2)) 并使用 Sweave 仅绘制一个图。
  • 感谢@Mikko,我如何使用 Sweave 创建一个独特的情节?
  • @R_user:你的意思是可交叉引用的情节吗?我会使用上面的建议组合这些图,并为每个子图添加字母。例如,请参见:seananderson.ca/2013/10/21/panel-letters.html

标签: r plot sweave


【解决方案1】:

我将在 Sweave 中创建一个图,使用 par 组合 R 中的图并添加子图字母以供文本引用,而不是尝试将子图编织在一起。例如:

<<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")
@

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-13
    • 2012-04-30
    • 1970-01-01
    • 1970-01-01
    • 2016-08-05
    • 2014-02-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多