2

I am using ggpairs() to create scatterplots and correlations for a set of variables. The text on my correlation plots don't fit onto the plot area, as they are horizontally adjusted to end halfway through the plot. I saw on another post how to adjust the topline correlation text, but it didn't work for the group correlations.

Here's an example:

n = 1000
test_results = tibble(
  test1=sample(1:10, n, replace=TRUE),
  test2=sample(1:10, n, replace=TRUE),
  test3=sample(1:10, n, replace=TRUE),
  test4=sample(1:10, n, replace=TRUE),
  test5=sample(1:10, n, replace=TRUE),
  political=sample(c("Democrat", "Republican", "Green", "Libertarian"), n, replace=TRUE))

test_results %>% 
  select(test1, test2, test3, test4, test5, political) %>%
  ggpairs(columns=c(1:5), mapping = aes(color = political, alpha=.5), 
          upper = list(continuous = wrap("cor", size = 3, hjust=0))
          )

Group correlation text off of image

4

1 回答 1

2

从@jrlewi 链接的代码看来,答案是alignPercent

test_results %>% 
  select(test1, test2, test3, test4, test5, political) %>%
  ggpairs(columns=c(1:5), mapping = aes(color = political, alpha=.5), 
          upper = list(continuous = wrap("cor", size = 3, hjust=0.15, alignPercent=1))
          )

正确对齐的文本

于 2018-03-10T22:55:55.697 回答