2016-09-26 330 views
3

我在做一个ggpairs图,但回归线太粗,'Corr:'文本字体太大。在ggpairs图中减小线条粗细和'Corr:'字体大小

data(mtcars) 
head(mtcars) 

mtcars$am <- as.factor(mtcars$am) 

g <- ggpairs( 
    data = mtcars, 
    lower = list(
    continuous = wrap("smooth", alpha = 0.3, color = "blue") 
    ) 
) 
g <- g + theme(
    axis.text = element_text(size = 6), 
    axis.title = element_text(size = 6), 
    legend.background = element_rect(fill = "white"), 
    panel.grid.major = element_line(colour = NA), 
    panel.grid.minor = element_blank(), 
    panel.background = element_rect(fill = "grey95") 
) 
print(g, bottomHeightProportion = 0.5, leftWidthProportion = .5) 

这是输出:

enter image description here

我不能GGally文档,在那里我可以设置这找到。

任何指针?

回答

2

试试这个增加字体大小:

data(mtcars) 
head(mtcars) 

mtcars$am <- as.factor(mtcars$am) 

library(ggplot2) 
library(GGally) 

lowerFn <- function(data, mapping, ...) { 
    p <- ggplot(data = data, mapping = mapping) + 
    geom_point(color = 'blue', alpha=0.3, size=4) + 
    geom_smooth(color = 'black', method='lm', size=1,...) 
    p 
} 

g <- ggpairs( 
    data = mtcars, 
    lower = list(
    continuous = wrap(lowerFn) #wrap("smooth", alpha = 0.3, color = "blue", lwd=1) 
), 
    upper = list(continuous = wrap("cor", size = 5)) 
) 
g <- g + theme(
    axis.text = element_text(size = 6), 
    axis.title = element_text(size = 6), 
    legend.background = element_rect(fill = "white"), 
    panel.grid.major = element_line(colour = NA), 
    panel.grid.minor = element_blank(), 
    panel.background = element_rect(fill = "grey95") 
) 
print(g, bottomHeightProportion = 0.5, leftWidthProportion = .5) 

enter image description here

2

这个怎么样?

lowerFn <- function(data, mapping, ...) { 
    p <- ggplot(data = data, mapping = mapping) + 
    geom_point(color = 'blue', alpha=0.3, size=4) + 
    geom_smooth(color = 'black', method='lm', size=1,...) 
    p 
} 

g <- ggpairs( 
    data = mtcars, 
    lower = list(
    continuous = wrap(lowerFn) 
) 
) 
g <- g + theme(
    axis.text = element_text(size = 6), 
    axis.title = element_text(size = 6), 
    legend.background = element_rect(fill = "white"), 
    panel.grid.major = element_line(colour = NA), 
    panel.grid.minor = element_blank(), 
    panel.background = element_rect(fill = "grey95") 
) 
print(g, bottomHeightProportion = 0.5, leftWidthProportion = .5) 

enter image description here

+0

感谢这个!我已经更新了问题,但询问如何编辑'Corr:'标签的字体大小。有任何想法吗? –

0

@克里斯雪:使用ggpairs功能的upper参数wrapggally_cor功能。 size = 2将解决您的问题,但是我也添加了color = "black"以防您想更改颜色。 礼貌:Change colors in ggpairs now that params is deprecated

修改后的MWE是:

data(mtcars) 
head(mtcars) 

mtcars$am <- as.factor(mtcars$am) 

g <- ggpairs( 
    data = mtcars, 
    lower = list(
    continuous = wrap("smooth", alpha = 0.3, color = "blue") 
    ), 
    upper = list(continuous = wrap(ggally_cor, size = 2, color = "black"))) 
g <- g + theme(
    axis.text = element_text(size = 6), 
    axis.title = element_text(size = 6), 
    legend.background = element_rect(fill = "white"), 
    panel.grid.major = element_line(colour = NA), 
    panel.grid.minor = element_blank(), 
    panel.background = element_rect(fill = "grey95") 
) 
print(g, bottomHeightProportion = 0.5, leftWidthProportion = .5)