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 に答える