3

我正在尝试(通过grid.arrangein gridExtra)安排 -package 的三元图和并排ggtern的常规图。ggplot2但是,删除了三元图的美学和标签位置。

知道这似乎是一个错误。任何绕过这个问题并产生我正在寻找的输出的指针都非常感谢。

一个可重现的例子:

library(ggplot2)
library(ggtern)
library(reshape2)
library(gridExtra)

# Some faux data
dat <- replicate(3, runif(5))
dat <- as.data.frame(dat/rowSums(dat))
colnames(dat) <- LETTERS[seq_len(ncol(dat)) + 23]
dat$var <- factor(LETTERS[seq_len(nrow(dat))])

# Make a ternary plot
tern.plot <- 
  ggplot(data = dat, aes(y=Y, x=X, z=Z, color = var, fill = var)) +
  coord_tern() +
  geom_point(size = 3)

# Make a stacked barplot
dat.melt <- melt(dat, id.vars = "var", variable.name = "dim")  
stacked.plot <-
  ggplot(data = dat.melt, aes(x = var, y = value, fill = dim)) +
  geom_bar(stat = "identity")

# Arrange the two plots:
grid.arrange(tern.plot, stacked.plot, ncol = 2)
#Warning messages:
#1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
#2: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'
# ...
#9: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL'

网格排列

三元图应如下所示:

print(tern.plot)

tern.plot

4

1 回答 1

3

我得到了ggtern.multi我显然完全错过的想要的结果。

ggtern.multi(tern.plot, stacked.plot, cols = 2)

想要的结果

正如 David Arenburg 在评论中所建议的那样,该multiplot功能也可以完美运行。

library(devtools)
source_gist("https://gist.github.com/AEBilgrau/2a78a9ebda2226b6b988")
multiplot(tern.plot, stacked.plot, cols = 2)
于 2014-07-24T21:45:52.513 回答