1

尽管@MikeWise 对我之前提出的这个问题的回答使用了示例数据,但它看起来不像我的真实代码。

我的代码是:

data(iris)

col.index <- c(1,2,3)

p <- ggpairs(iris, columns = col.index, upper = "blank", legends=T, lower = list(continuous = "points"), diag = "blank",
             axisLabels = "show", 
             colour = "Species",
             columnLabels = c("", "", ""),
             title = "Example") +
  theme_bw() +
  theme(plot.title = element_text(size = 10), axis.title = element_text(size = 10), axis.text = element_text(size = 8), 
        legend.position = "top", legend.title = element_blank())


p1 <- ggally_text("SL") + 
  theme_bw() +
  theme(axis.text = element_blank(), panel.grid = element_blank(), axis.ticks = element_blank())
p2 <- ggally_text("SW") +
  theme_bw() +
  theme(axis.text = element_blank(), panel.grid = element_blank(), axis.ticks = element_blank())
p3 <- ggally_text("PL") +
  theme_bw() +
  theme(axis.text = element_blank(), panel.grid = element_blank(), axis.ticks = element_blank())
p <- putPlot(p,p1,1,1)
p <- putPlot(p,p2,2,2)
p <- putPlot(p,p3,3,3)



GGally:::print_ggpairs_old(p)

colIdx <- c(1,2,3)

for (i in 1:length(colIdx)) {
  # Address only the diagonal elements
  # Get plot out of matrix
  inner <- getPlot(p, i, i);
  # Add any ggplot2 settings you want
  inner <- inner + theme(panel.grid = element_blank()) +
    theme(axis.text.x = element_blank())
  # Put it back into the matrix
  p <- putPlot(p, inner, i, i)

  for (j in 1:length(colIdx)){
    if((i==1 & j==1)){
      inner <- getPlot(p, i, j)
      inner <- inner + theme(legend.position=c(length(colIdx)-0.25,0.50)) 
      p <- putPlot(p, inner, i, j)
    }
    else{
      inner <- getPlot(p, i, j)
      inner <- inner + theme(legend.position="none")
      p <- putPlot(p, inner, i, j)
    }
  }
}

GGally:::print_ggpairs_old(p)

传说还没有。此外,情节看起来不像我想要的。使用函数 print() 布局成为我所期望的。

关于做什么的任何建议?

4

1 回答 1

1

这有什么问题吗?注意我更改了diag参数。如果您确实需要空白图,则可以在调整图例后对其进行编辑。

library(GGally)
data(iris)

col.index <- c(1,2,3)

p <- ggpairs(iris, columns = col.index, 
             upper = "blank", legends=T, 
             lower = list(continuous = "points"), 
             diag = list(continuous = "density"),
             axisLabels = "show", 
             colour = "Species",

             columnLabels = c("", "", ""),
             title = "Example") +
  theme_bw() +
  theme(plot.title = element_text(size = 10), 
        axis.title = element_text(size = 10), 
        axis.text = element_text(size = 8), 
        legend.position = "top", 
        legend.title = element_blank())


# p1 <- ggally_text("SL") + 
#   theme_bw() +
#   theme(axis.text = element_blank(), panel.grid = element_blank(), axis.ticks = element_blank())
# p2 <- ggally_text("SW") +
#   theme_bw() +
#   theme(axis.text = element_blank(), panel.grid = element_blank(), axis.ticks = element_blank())
# p3 <- ggally_text("PL") +
#   theme_bw() +
#   theme(axis.text = element_blank(), panel.grid = element_blank(), axis.ticks = element_blank())
# p <- putPlot(p,p1,1,1)
# p <- putPlot(p,p2,2,2)
# p <- putPlot(p,p3,3,3)


###THE IT TURNS INTO

GGally:::print_ggpairs_old(p)

colIdx <- c(1,2,3)

for (i in 1:length(colIdx)) {
  # Address only the diagonal elements
  # Get plot out of matrix
  inner <- getPlot(p, i, i);
  # Add any ggplot2 settings you want
  inner <- inner + theme(panel.grid = element_blank()) +
    theme(axis.text.x = element_blank())
  # Put it back into the matrix
  p <- putPlot(p, inner, i, i)

  for (j in 1:length(colIdx)){
    if((i==1 & j==1)){
      inner <- getPlot(p, i, j)
      inner <- inner + 
               theme(legend.position=c(length(colIdx)-0.25,0.50)) 
      p <- putPlot(p, inner, i, j)
    }
    else{
      inner <- getPlot(p, i, j)
      inner <- inner + 
               theme(legend.position="none")
      p <- putPlot(p, inner, i, j)
    }
  }
}

GGally:::print_ggpairs_old(p)

在此处输入图像描述

于 2015-10-04T08:48:41.933 回答