Skip to content

Instantly share code, notes, and snippets.

@kazutan
Created March 10, 2017 08:17
Show Gist options
  • Save kazutan/03489ba218b09d34ccf213abe2211384 to your computer and use it in GitHub Desktop.
Save kazutan/03489ba218b09d34ccf213abe2211384 to your computer and use it in GitHub Desktop.
corrr::rplotの相関係数のサイズ変更
library("corrr")
library("ggplot2")
# 差し替え用の関数
# サイズ指定用の引数をセット
rplot_kari <- function (rdf, legend = TRUE, shape = 16, colours = c("indianred2", "white", "skyblue1"), print_cor = FALSE, colors, size = 3)
{
if (!missing(colors))
colours <- colors
row_order <- rdf$rowname
dots <- stats::setNames(list(
lazyeval::interp(~factor(x, levels = row_order), x = quote(x)),
lazyeval::interp(~factor(y, levels = rev(row_order)), y = quote(y)),
lazyeval::interp(~abs(r), r = quote(r)),
lazyeval::interp(~as.character(fashion(r)), r = quote(r))
),
list("x", "y", "size", "label")
)
pd <- rdf %>%
stretch(na.rm = TRUE) %>%
mutate_(.dots = dots)
plot_ <- list(geom_point(shape = shape),
if (print_cor) geom_text(color = "black", size = size, show.legend = FALSE),
scale_colour_gradientn(limits = c(-1, 1), colors = colours),
theme_classic(),
labs(x = "", y = ""),
guides(size = "none", alpha = "none"),
if (legend) labs(colour = NULL),
if (!legend) theme(legend.position = "none"))
ggplot(pd, aes_string(x = "x", y = "y", color = "r", size = "size", alpha = "size", label = "label")) +
plot_
}
d2 <- mtcars %>%
correlate() %>%
focus(-cyl, -vs, -hp, mirror = TRUE)
g <- shave(d2) %>%
rplot_kari(print_cor = TRUE, shape=15, size = 20) # 好きなサイズを指定して試してみてください
g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment