@Ricardo Saporta 在这里提出了一种将基本图形和 ggplot 图形组合在多个绘图图中的简单方法。
我使用这种方式在左侧绘制一个基本图形,在右侧绘制一个 ggplot 图形,它实际上包含两个图形(这是一个人工示例,不是真实示例,但它与我的真实示例具有相同的结构):
library(ggplot2)
library(gridExtra)
library(plotrix)
Mvalues <- matrix(rpois(9,1), ncol=3)
Mcolors <- matrix(rpois(9,5), ncol=3)
par(mfrow=c(1,2))
color2D.matplot(x=Mvalues, show.values=2, cellcolors=Mcolors,
xlab="x", ylab="y", axes=FALSE, vcex=0.4)
gg2 <- ggplot(diamonds, aes(clarity, fill=cut)) + geom_bar(position="dodge")
ta <- do.call(arrangeGrob, list(gg2,gg2))
vp.Left <- viewport(height=unit(1, "npc"), width=unit(0.5, "npc"),
just="left", y=0.5, x=0.5)
print(ta, vp=vp.Left)
非常好。但现在我希望基础图形的宽度比 ggplot 图形更大。怎么做 ?我没有成功尝试使用该layout()
功能。