Skip to content

Commit

Permalink
Merge pull request #10 from LDSamson/improve_labels
Browse files Browse the repository at this point in the history
Improve labels
  • Loading branch information
caijun authored May 6, 2022
2 parents e86ee00 + 927e525 commit 8441cf2
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions R/ggcorrplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ ggcorrplot <- function(corr, method = c("circle", "square", "ellipse", "number")
if (type == "full") {
p <- p +
scale_x_continuous(breaks = 1:nvars, labels = vars, expand = c(0, 0)) +
scale_y_reverse(breaks = 1:nvars, labels = vars, expand = c(0, 0))
scale_y_reverse(breaks = 1:nvars, labels = vars, expand = c(0, 0)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))
} else if (type == "lower") {
if (show.diag) {
y.vars <- data.frame(x = 0, y = 1:nvars)
Expand All @@ -280,10 +281,11 @@ ggcorrplot <- function(corr, method = c("circle", "square", "ellipse", "number")
diag.label <- utils::head(vars, -1)
}
p <- p +
geom_text(data = diag.vars, mapping = aes(.data$x, .data$y), label = diag.label,
colour = "grey30", size = geom.text.fontsize) +
geom_text(data = diag.vars, mapping = aes(.data$x, .data$y+0.4), label = diag.label,
colour = "grey30", size = geom.text.fontsize, angle = 90, hjust = 0) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_reverse(breaks = y.vars$y, labels = y.label, expand = c(0, 0),
scale_y_reverse(breaks = y.vars$y, labels = y.label,
expand = expansion(mult = c(0, 0.02*nchar(diag.label[1]))),
limits = c(nvars + 0.5, min(diag.vars$y) - 0.5)) +
theme(axis.text.x = element_blank(),
axis.text.y = element_text(size = axis.text.fontsize))
Expand All @@ -299,12 +301,13 @@ ggcorrplot <- function(corr, method = c("circle", "square", "ellipse", "number")
diag.label <- utils::head(vars, -1)
}
p <- p +
geom_text(data = diag.vars, mapping = aes(.data$x, .data$y), label = diag.label,
colour = "grey30", size = geom.text.fontsize) +
scale_x_continuous(breaks = x.vars$x, labels = x.label, expand = c(0, 0),
geom_text(data = diag.vars, mapping = aes(.data$x+0.4, .data$y), label = diag.label,
colour = "grey30", size = geom.text.fontsize, hjust = 1) +
scale_x_continuous(breaks = x.vars$x, labels = x.label,
expand = expansion(mult = c(0.02*nchar(diag.label[1]), 0)),
position = "top", limits = c(min(diag.vars$x) - 0.5, nvars + 0.5)) +
scale_y_reverse(expand = c(0, 0)) +
theme(axis.text.x = element_text(size = axis.text.fontsize),
theme(axis.text.x = element_text(size = axis.text.fontsize, angle = 90, hjust = 0),
axis.text.y = element_blank())
}

Expand Down

0 comments on commit 8441cf2

Please sign in to comment.