我使用ggpairs()为一组变量创建散点图和相关性。我的相关图上的文本不适合绘图区域,因为它们被水平调整为在绘图中途结束。我在another post上看到了如何调整背线相关性文本,但它不适用于组相关性。
下面是一个例子:
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))
)发布于 2018-03-11 06:55:56
从@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))
)https://stackoverflow.com/questions/49213418
复制相似问题