ggobi / ggally

R package that extends ggplot2
http://ggobi.github.io/ggally/
588 stars 118 forks source link

ggpairs ignores margin argument for axis.title #201

Closed eipi10 closed 8 years ago

eipi10 commented 8 years ago

It looks like ggpairs is ignoring the margin argument when used with axis.title, but not when used with axis.text. Here's an example:

ggpairs(mtcars[,1:3])
ggpairs(mtcars[,1:3]) + theme(axis.title.x=element_text(size=8, margin=margin(t=10)))
ggpairs(mtcars[,1:3]) + theme(axis.text.x=element_text(size=8, margin=margin(t=10)))

In the second example, you can see that size=8 is respected, but margin=margin(t=10) is ignored. But in the third example, the margin argument is respected. In my actual plot, the x-axis titles are too close to the x-axis labels. In fact, they overlap if I use two-line axis titles, which I need to do in some cases. I was hoping I could do this:

ggpairs(mtcars[,1:3]) + theme(axis.text.x=element_text(size=8, margin=margin(b=10))) 

i.e., put a margin below the axis labels, in the hope that this would push the axis titles away from the axis labels. But in fact the axis titles don't move and the axis labels just get pushed down to overlap the axis titles.

So, my questions: Am I missing something? Is there some other way to move the axis titles away from the axis labels? Or is this a bug, and, if so, is there a workaround?

schloerke commented 8 years ago

I am currently traveling, so I can not check the code. I believe this is not currently implemented with the version of GGally on cran.

To work around the lack of functionality (and help test for me!) please install the dev branch from github and try your same code. The dev branch is much more ggplot2 friendly (not perfect, but getting there).

devtools::install_github("ggobi/ggally@dev")

Please let me know if this solves your situation. (And if you like the new layout!)

Best, Barret On Fri, Sep 23, 2016 at 6:23 PM eipi10 notifications@github.com wrote:

It looks like ggpairs is ignoring the margin argument when used with axis.title, but not when used with axis.text. Here's an example:

ggpairs(mtcars[,1:3]) ggpairs(mtcars[,1:3]) + theme(axis.title.x=element_text(size=8, margin=margin(t=10))) ggpairs(mtcars[,1:3]) + theme(axis.text.x=element_text(size=8, margin=margin(t=10)))

In the second example, you can see that size=8 is respected, but margin=margin(t=10) is ignored. But in the third example, the margin argument is respected. In my actual plot, the x-axis titles are too close to the x-axis labels. In fact, they overlap if I use two-line axis titles, which I need to do in some cases. I was hoping I could do this:

ggpairs(mtcars[,1:3]) + theme(axis.text.x=element_text(size=8, margin=margin(b=10)))

i.e., put a margin below the axis labels, in the hope that this would push the the axis title away from the axis labels. But in fact the axis titles don't move and the axis labels just get pushed down to overlap the axis titles.

So, my questions: Am I missing something? Is there some other way to move the axis titles away from the axis labels? Or is this a bug, and, if so, is there a workaround?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ggobi/ggally/issues/201, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFsLzu0ldKqXL2odA7geKy5PXWGMxasks5qtFFXgaJpZM4KFcfl .

eipi10 commented 8 years ago

Hi Barrett,

Thanks for your reply. I installed the dev branch, but it seems to have a bug. When I run ggpairs, instead of returning a plot, it just returns the list object of the plot. For example, ggpairs(mtcars[,1:3]) returns the following list to the console, but no plot. I've only included the beginning and end of the output, as it's a huge list. Do you get the same result?

function (data, mapping, ...) 
{
    allParams$data <- data
    allParams$mapping <- mapping
    argsList <- list(...)
    allParams[names(argsList)] <- argsList
    do.call(original_fn, allParams)
}
... [I've deleted most of the output to save space]...
$ncol
[1] 3

$byrow
[1] TRUE

attr(,"class")
[1] "gg"       "ggmatrix"
schloerke commented 8 years ago

Yes! So sorry. It wasn't exported.

Either

GGally:::print(obj)

Or

devtools::install_github("ggobi/ggally@new_functions")

Best, Barret On Sat, Sep 24, 2016 at 9:06 PM eipi10 notifications@github.com wrote:

Hi Barrett,

Thanks for your reply. I installed the dev branch, but it seems to have a bug. When I run ggpairs, instead of returning a plot, it just returns the list object of the plot. For example, ggpairs(mtcars[,1:3]) returns the following list to the console, but no plot. I wasn't going to paste the whole thing in, as it's so long, but I thought maybe you'd want to see what it's doing. Do you get the same result?

function (data, mapping, ...) { allParams$data <- data allParams$mapping <- mapping argsList <- list(...) allParams[names(argsList)] <- argsList do.call(original_fn, allParams) } <environment: 0x10b2f79f0> attr(,"class") [1] "ggmatrix_fn_with_params" attr(,"name") [1] "ggally_densityDiag" attr(,"params") list() attr(,"fn") function (data, mapping, ..., rescale = FALSE) { p <- ggplot(data, mapping) + scale_y_continuous() if (identical(rescale, TRUE)) { p <- p + stat_density(aes(y = ..scaled.. * diff(range(x, na.rm = TRUE)) + min(x, na.rm = TRUE)), position = "identity", geom = "line", ...) } else { p <- p + geom_density(...) } p$type <- "diag" p$subType <- "density" p }

$mapping - x -> disp $dataPos [1] 1 $gg NULL attr(,"class") [1] "ggmatrix_plot_obj" $title NULL $xlab NULL $ylab NULL $showStrips NULL $xAxisLabels [1] "mpg" "cyl" "disp" $yAxisLabels [1] "mpg" "cyl" "disp" $showXAxisPlotLabels [1] TRUE $showYAxisPlotLabels [1] TRUE $xProportions NULL $yProportions NULL $legend NULL $gg NULL $nrow [1] 3 $ncol [1] 3 $byrow [1] TRUE attr(,"class") [1] "gg" "ggmatrix" > ggpairs(mtcars[,1:3]) > $data > mpg cyl disp > Mazda RX4 21.0 6 160.0 > Mazda RX4 Wag 21.0 6 160.0 > Datsun 710 22.8 4 108.0 > Hornet 4 Drive 21.4 6 258.0 > Hornet Sportabout 18.7 8 360.0 > Valiant 18.1 6 225.0 > Duster 360 14.3 8 360.0 > Merc 240D 24.4 4 146.7 > Merc 230 22.8 4 140.8 > Merc 280 19.2 6 167.6 > Merc 280C 17.8 6 167.6 > Merc 450SE 16.4 8 275.8 > Merc 450SL 17.3 8 275.8 > Merc 450SLC 15.2 8 275.8 > Cadillac Fleetwood 10.4 8 472.0 > Lincoln Continental 10.4 8 460.0 > Chrysler Imperial 14.7 8 440.0 > Fiat 128 32.4 4 78.7 > Honda Civic 30.4 4 75.7 > Toyota Corolla 33.9 4 71.1 > Toyota Corona 21.5 4 120.1 > Dodge Challenger 15.5 8 318.0 > AMC Javelin 15.2 8 304.0 > Camaro Z28 13.3 8 350.0 > Pontiac Firebird 19.2 8 400.0 > Fiat X1-9 27.3 4 79.0 > Porsche 914-2 26.0 4 120.3 > Lotus Europa 30.4 4 95.1 > Ford Pantera L 15.8 8 351.0 > Ferrari Dino 19.7 6 145.0 > Maserati Bora 15.0 8 301.0 > Volvo 142E 21.4 4 121.0 $plots $plots[[1]] $fn function (data, mapping, ...) { allParams$data <- data allParams$mapping <- mapping argsList <- list(...) allParams[names(argsList)] <- argsList do.call(original_fn, allParams) } attr(,"class") [1] "ggmatrix_fn_with_params" attr(,"name") [1] "ggally_densityDiag" attr(,"params") list() attr(,"fn") function (data, mapping, ..., rescale = FALSE) { p <- ggplot(data, mapping) + scale_y_continuous() if (identical(rescale, TRUE)) { p <- p + stat_density(aes(y = ..scaled.. \* diff(range(x, na.rm = TRUE)) + min(x, na.rm = TRUE)), position = "identity", geom = "line", ...) } else { p <- p + geom_density(...) } p$type <- "diag" p$subType <- "density" p } $mapping - x -> mpg $dataPos [1] 1 $gg NULL attr(,"class") [1] "ggmatrix_plot_obj" $plots[[2]] $fn function (data, mapping, ...) { allParams$data <- data allParams$mapping <- mapping argsList <- list(...) allParams[names(argsList)] <- argsList do.call(original_fn, allParams) } attr(,"class") [1] "ggmatrix_fn_with_params" attr(,"name") [1] "ggally_cor" attr(,"params") list() attr(,"fn") function (data, mapping, alignPercent = 0.6, method = "pearson", use = "complete.obs", corAlignPercent = NULL, corMethod = NULL, corUse = NULL, ...) { if (!is.null(corAlignPercent)) { stop("'corAlignPercent' is deprecated. Please use argument 'alignPercent'") } if (!is.null(corMethod)) { stop("'corMethod' is deprecated. Please use argument 'method'") } if (!is.null(corUse)) { stop("'corUse' is deprecated. Please use argument 'use'") } useOptions <- c("all.obs", "complete.obs", "pairwise.complete.obs", "everything", "na.or.complete") use <- pmatch(use, useOptions) if (is.na(use)) { warning("correlation 'use' not found. Using default value of 'all.obs'") use <- useOptions[1] } else { use <- useOptions[use] } cor_fn <- function(x, y) { cor(x, y, method = method, use = use) } xCol <- deparse(mapping$x) yCol <- deparse(mapping$y) if (is_date(data[[xCol]]) || is_date(data[[yCol]])) { if (!identical(class(data), "data.frame")) { data <- fix_data(data) } for (col in c(xCol, yCol)) { if (is_date(data[[col]])) { data[[col]] <- as.numeric(data[[col]]) } } } if (is.numeric(eval_data_col(data, mapping$colour))) { stop("ggally_cor: mapping color column must be categorical, not numeric") } colorCol <- deparse(mapping$colour) singleColorCol <- ifelse(is.null(colorCol), NULL, paste(colorCol, collapse = "")) if (use %in% c("complete.obs", "pairwise.complete.obs", "na.or.complete")) { if (length(colorCol) > 0) { if (singleColorCol %in% colnames(data)) { rows <- complete.cases(data[c(xCol, yCol, colorCol)]) } else { rows <- complete.cases(data[c(xCol, yCol)]) } } else { rows <- complete.cases(data[c(xCol, yCol)]) } if (any(!rows)) { total <- sum(!rows) if (total > 1) { warning("Removed ", total, " rows containing missing values") } else if (total == 1) { warning("Removing 1 row that contained a missing value") } } data <- data[rows, ] } xVal <- data[[xCol]] yVal <- data[[yCol]] if (length(names(mapping)) > 0) { for (i in length(names(mapping)):1) { tmp_map_val <- deparse(mapping[names(mapping)[i]][[1]]) if (tmp_map_val[length(tmp_map_val)] %in% colnames(data)) mapping[[names(mapping)[i]]] <- NULL if (length(names(mapping)) < 1) { mapping <- NULL break } } } if (length(colorCol) < 1) { colorCol <- "ggally_NO_EXIST" } if ((singleColorCol != "ggally_NO_EXIST") && (singleColorCol %in% colnames(data))) { cord <- ddply(data, c(colorCol), function(x) { cor_fn(x[[xCol]], x[[yCol]]) }) colnames(cord)[2] <- "ggally_cor" cord$ggally_cor <- signif(as.numeric(cord$ggally_cor), 3) lev <- levels(data[[colorCol]]) ord <- rep(-1, nrow(cord)) for (i in 1:nrow(cord)) { for (j in seq_along(lev)) { if (identical(as.character(cord[i, colorCol]), as.character(lev[j]))) { ord[i] <- j } } } cord <- cord[order(ord[ord >= 0]), ] cord$label <- str_c(cord[[colorCol]], ": ", cord$ggally_cor) xmin <- min(xVal, na.rm = TRUE) xmax <- max(xVal, na.rm = TRUE) xrange <- c(xmin - 0.01 \* (xmax - xmin), xmax + 0.01 * (xmax - xmin)) ymin <- min(yVal, na.rm = TRUE) ymax <- max(yVal, na.rm = TRUE) yrange <- c(ymin - 0.01 \* (ymax - ymin), ymax + 0.01 * (ymax - ymin)) p <- ggally_text(label = str_c("Cor : ", signif(cor_fn(xVal, yVal), 3)), mapping = mapping, xP = 0.5, yP = 0.9, xrange = xrange, yrange = yrange, color = "black", ...) + theme(legend.position = "none") xPos <- rep(alignPercent, nrow(cord)) \* diff(xrange) + min(xrange, na.rm = TRUE) yPos <- seq(from = 0.9, to = 0.2, length.out = nrow(cord) + 1) yPos <- yPos \* diff(yrange) + min(yrange, na.rm = TRUE) yPos <- yPos[-1] cordf <- data.frame(xPos = xPos, yPos = yPos, labelp = cord$label) cordf$labelp <- factor(cordf$labelp, levels = cordf$labelp) p <- p + geom_text(data = cordf, aes(x = xPos, y = yPos, label = labelp, color = labelp), hjust = 1, ...) p$type <- "continuous" p$subType <- "cor" p } else { xmin <- min(xVal, na.rm = TRUE) xmax <- max(xVal, na.rm = TRUE) xrange <- c(xmin - 0.01 \* (xmax - xmin), xmax + 0.01 * (xmax - xmin)) ymin <- min(yVal, na.rm = TRUE) ymax <- max(yVal, na.rm = TRUE) yrange <- c(ymin - 0.01 \* (ymax - ymin), ymax + 0.01 * (ymax - ymin)) p <- ggally_text(label = paste("Corr:\n", signif(cor_fn(xVal, yVal), 3), sep = "", collapse = ""), mapping, xP = 0.5, yP = 0.5, xrange = xrange, yrange = yrange, ...) + theme(legend.position = "none") p$type <- "continuous" p$subType <- "cor" p } } $mapping - x -> cyl - y -> mpg $dataPos [1] 1 $gg NULL attr(,"class") [1] "ggmatrix_plot_obj" $plots[[3]] $fn function (data, mapping, ...) { allParams$data <- data allParams$mapping <- mapping argsList <- list(...) allParams[names(argsList)] <- argsList do.call(original_fn, allParams) } attr(,"class") [1] "ggmatrix_fn_with_params" attr(,"name") [1] "ggally_cor" attr(,"params") list() attr(,"fn") function (data, mapping, alignPercent = 0.6, method = "pearson", use = "complete.obs", corAlignPercent = NULL, corMethod = NULL, corUse = NULL, ...) { if (!is.null(corAlignPercent)) { stop("'corAlignPercent' is deprecated. Please use argument 'alignPercent'") } if (!is.null(corMethod)) { stop("'corMethod' is deprecated. Please use argument 'method'") } if (!is.null(corUse)) { stop("'corUse' is deprecated. Please use argument 'use'") } useOptions <- c("all.obs", "complete.obs", "pairwise.complete.obs", "everything", "na.or.complete") use <- pmatch(use, useOptions) if (is.na(use)) { warning("correlation 'use' not found. Using default value of 'all.obs'") use <- useOptions[1] } else { use <- useOptions[use] } cor_fn <- function(x, y) { cor(x, y, method = method, use = use) } xCol <- deparse(mapping$x) yCol <- deparse(mapping$y) if (is_date(data[[xCol]]) || is_date(data[[yCol]])) { if (!identical(class(data), "data.frame")) { data <- fix_data(data) } for (col in c(xCol, yCol)) { if (is_date(data[[col]])) { data[[col]] <- as.numeric(data[[col]]) } } } if (is.numeric(eval_data_col(data, mapping$colour))) { stop("ggally_cor: mapping color column must be categorical, not numeric") } colorCol <- deparse(mapping$colour) singleColorCol <- ifelse(is.null(colorCol), NULL, paste(colorCol, collapse = "")) if (use %in% c("complete.obs", "pairwise.complete.obs", "na.or.complete")) { if (length(colorCol) > 0) { if (singleColorCol %in% colnames(data)) { rows <- complete.cases(data[c(xCol, yCol, colorCol)]) } else { rows <- complete.cases(data[c(xCol, yCol)]) } } else { rows <- complete.cases(data[c(xCol, yCol)]) } if (any(!rows)) { total <- sum(!rows) if (total > 1) { warning("Removed ", total, " rows containing missing values") } else if (total == 1) { warning("Removing 1 row that contained a missing value") } } data <- data[rows, ] } xVal <- data[[xCol]] yVal <- data[[yCol]] if (length(names(mapping)) > 0) { for (i in length(names(mapping)):1) { tmp_map_val <- deparse(mapping[names(mapping)[i]][[1]]) if (tmp_map_val[length(tmp_map_val)] %in% colnames(data)) mapping[[names(mapping)[i]]] <- NULL if (length(names(mapping)) < 1) { mapping <- NULL break } } } if (length(colorCol) < 1) { colorCol <- "ggally_NO_EXIST" } if ((singleColorCol != "ggally_NO_EXIST") && (singleColorCol %in% colnames(data))) { cord <- ddply(data, c(colorCol), function(x) { cor_fn(x[[xCol]], x[[yCol]]) }) colnames(cord)[2] <- "ggally_cor" cord$ggally_cor <- signif(as.numeric(cord$ggally_cor), 3) lev <- levels(data[[colorCol]]) ord <- rep(-1, nrow(cord)) for (i in 1:nrow(cord)) { for (j in seq_along(lev)) { if (identical(as.character(cord[i, colorCol]), as.character(lev[j]))) { ord[i] <- j } } } cord <- cord[order(ord[ord >= 0]), ] cord$label <- str_c(cord[[colorCol]], ": ", cord$ggally_cor) xmin <- min(xVal, na.rm = TRUE) xmax <- max(xVal, na.rm = TRUE) xrange <- c(xmin - 0.01 \* (xmax - xmin), xmax + 0.01 * (xmax - xmin)) ymin <- min(yVal, na.rm = TRUE) ymax <- max(yVal, na.rm = TRUE) yrange <- c(ymin - 0.01 \* (ymax - ymin), ymax + 0.01 * (ymax - ymin)) p <- ggally_text(label = str_c("Cor : ", signif(cor_fn(xVal, yVal), 3)), mapping = mapping, xP = 0.5, yP = 0.9, xrange = xrange, yrange = yrange, color = "black", ...) + theme(legend.position = "none") xPos <- rep(alignPercent, nrow(cord)) \* diff(xrange) + min(xrange, na.rm = TRUE) yPos <- seq(from = 0.9, to = 0.2, length.out = nrow(cord) + 1) yPos <- yPos \* diff(yrange) + min(yrange, na.rm = TRUE) yPos <- yPos[-1] cordf <- data.frame(xPos = xPos, yPos = yPos, labelp = cord$label) cordf$labelp <- factor(cordf$labelp, levels = cordf$labelp) p <- p + geom_text(data = cordf, aes(x = xPos, y = yPos, label = labelp, color = labelp), hjust = 1, ...) p$type <- "continuous" p$subType <- "cor" p } else { xmin <- min(xVal, na.rm = TRUE) xmax <- max(xVal, na.rm = TRUE) xrange <- c(xmin - 0.01 \* (xmax - xmin), xmax + 0.01 * (xmax - xmin)) ymin <- min(yVal, na.rm = TRUE) ymax <- max(yVal, na.rm = TRUE) yrange <- c(ymin - 0.01 \* (ymax - ymin), ymax + 0.01 * (ymax - ymin)) p <- ggally_text(label = paste("Corr:\n", signif(cor_fn(xVal, yVal), 3), sep = "", collapse = ""), mapping, xP = 0.5, yP = 0.5, xrange = xrange, yrange = yrange, ...) + theme(legend.position = "none") p$type <- "continuous" p$subType <- "cor" p } } $mapping - x -> disp - y -> mpg $dataPos [1] 1 $gg NULL attr(,"class") [1] "ggmatrix_plot_obj" $plots[[4]] $fn function (data, mapping, ...) { allParams$data <- data allParams$mapping <- mapping argsList <- list(...) allParams[names(argsList)] <- argsList do.call(original_fn, allParams) } attr(,"class") [1] "ggmatrix_fn_with_params" attr(,"name") [1] "ggally_points" attr(,"params") list() attr(,"fn") function (data, mapping, ...) { p <- ggplot(data = data, mapping = mapping) + geom_point(...) p$type <- "continuous" p$subType <- "points" p } $mapping - x -> mpg - y -> cyl $dataPos [1] 1 $gg NULL attr(,"class") [1] "ggmatrix_plot_obj" $plots[[5]] $fn function (data, mapping, ...) { allParams$data <- data allParams$mapping <- mapping argsList <- list(...) allParams[names(argsList)] <- argsList do.call(original_fn, allParams) } attr(,"class") [1] "ggmatrix_fn_with_params" attr(,"name") [1] "ggally_densityDiag" attr(,"params") list() attr(,"fn") function (data, mapping, ..., rescale = FALSE) { p <- ggplot(data, mapping) + scale_y_continuous() if (identical(rescale, TRUE)) { p <- p + stat_density(aes(y = ..scaled.. \* diff(range(x, na.rm = TRUE)) + min(x, na.rm = TRUE)), position = "identity", geom = "line", ...) } else { p <- p + geom_density(...) } p$type <- "diag" p$subType <- "density" p } $mapping - x -> cyl $dataPos [1] 1 $gg NULL attr(,"class") [1] "ggmatrix_plot_obj" $plots[[6]] $fn function (data, mapping, ...) { allParams$data <- data allParams$mapping <- mapping argsList <- list(...) allParams[names(argsList)] <- argsList do.call(original_fn, allParams) } attr(,"class") [1] "ggmatrix_fn_with_params" attr(,"name") [1] "ggally_cor" attr(,"params") list() attr(,"fn") function (data, mapping, alignPercent = 0.6, method = "pearson", use = "complete.obs", corAlignPercent = NULL, corMethod = NULL, corUse = NULL, ...) { if (!is.null(corAlignPercent)) { stop("'corAlignPercent' is deprecated. Please use argument 'alignPercent'") } if (!is.null(corMethod)) { stop("'corMethod' is deprecated. Please use argument 'method'") } if (!is.null(corUse)) { stop("'corUse' is deprecated. Please use argument 'use'") } useOptions <- c("all.obs", "complete.obs", "pairwise.complete.obs", "everything", "na.or.complete") use <- pmatch(use, useOptions) if (is.na(use)) { warning("correlation 'use' not found. Using default value of 'all.obs'") use <- useOptions[1] } else { use <- useOptions[use] } cor_fn <- function(x, y) { cor(x, y, method = method, use = use) } xCol <- deparse(mapping$x) yCol <- deparse(mapping$y) if (is_date(data[[xCol]]) || is_date(data[[yCol]])) { if (!identical(class(data), "data.frame")) { data <- fix_data(data) } for (col in c(xCol, yCol)) { if (is_date(data[[col]])) { data[[col]] <- as.numeric(data[[col]]) } } } if (is.numeric(eval_data_col(data, mapping$colour))) { stop("ggally_cor: mapping color column must be categorical, not numeric") } colorCol <- deparse(mapping$colour) singleColorCol <- ifelse(is.null(colorCol), NULL, paste(colorCol, collapse = "")) if (use %in% c("complete.obs", "pairwise.complete.obs", "na.or.complete")) { if (length(colorCol) > 0) { if (singleColorCol %in% colnames(data)) { rows <- complete.cases(data[c(xCol, yCol, colorCol)]) } else { rows <- complete.cases(data[c(xCol, yCol)]) } } else { rows <- complete.cases(data[c(xCol, yCol)]) } if (any(!rows)) { total <- sum(!rows) if (total > 1) { warning("Removed ", total, " rows containing missing values") } else if (total == 1) { warning("Removing 1 row that contained a missing value") } } data <- data[rows, ] } xVal <- data[[xCol]] yVal <- data[[yCol]] if (length(names(mapping)) > 0) { for (i in length(names(mapping)):1) { tmp_map_val <- deparse(mapping[names(mapping)[i]][[1]]) if (tmp_map_val[length(tmp_map_val)] %in% colnames(data)) mapping[[names(mapping)[i]]] <- NULL if (length(names(mapping)) < 1) { mapping <- NULL break } } } if (length(colorCol) < 1) { colorCol <- "ggally_NO_EXIST" } if ((singleColorCol != "ggally_NO_EXIST") && (singleColorCol %in% colnames(data))) { cord <- ddply(data, c(colorCol), function(x) { cor_fn(x[[xCol]], x[[yCol]]) }) colnames(cord)[2] <- "ggally_cor" cord$ggally_cor <- signif(as.numeric(cord$ggally_cor), 3) lev <- levels(data[[colorCol]]) ord <- rep(-1, nrow(cord)) for (i in 1:nrow(cord)) { for (j in seq_along(lev)) { if (identical(as.character(cord[i, colorCol]), as.character(lev[j]))) { ord[i] <- j } } } cord <- cord[order(ord[ord >= 0]), ] cord$label <- str_c(cord[[colorCol]], ": ", cord$ggally_cor) xmin <- min(xVal, na.rm = TRUE) xmax <- max(xVal, na.rm = TRUE) xrange <- c(xmin - 0.01 \* (xmax - xmin), xmax + 0.01 * (xmax - xmin)) ymin <- min(yVal, na.rm = TRUE) ymax <- max(yVal, na.rm = TRUE) yrange <- c(ymin - 0.01 \* (ymax - ymin), ymax + 0.01 * (ymax - ymin)) p <- ggally_text(label = str_c("Cor : ", signif(cor_fn(xVal, yVal), 3)), mapping = mapping, xP = 0.5, yP = 0.9, xrange = xrange, yrange = yrange, color = "black", ...) + theme(legend.position = "none") xPos <- rep(alignPercent, nrow(cord)) \* diff(xrange) + min(xrange, na.rm = TRUE) yPos <- seq(from = 0.9, to = 0.2, length.out = nrow(cord) + 1) yPos <- yPos \* diff(yrange) + min(yrange, na.rm = TRUE) yPos <- yPos[-1] cordf <- data.frame(xPos = xPos, yPos = yPos, labelp = cord$label) cordf$labelp <- factor(cordf$labelp, levels = cordf$labelp) p <- p + geom_text(data = cordf, aes(x = xPos, y = yPos, label = labelp, color = labelp), hjust = 1, ...) p$type <- "continuous" p$subType <- "cor" p } else { xmin <- min(xVal, na.rm = TRUE) xmax <- max(xVal, na.rm = TRUE) xrange <- c(xmin - 0.01 \* (xmax - xmin), xmax + 0.01 * (xmax - xmin)) ymin <- min(yVal, na.rm = TRUE) ymax <- max(yVal, na.rm = TRUE) yrange <- c(ymin - 0.01 \* (ymax - ymin), ymax + 0.01 * (ymax - ymin)) p <- ggally_text(label = paste("Corr:\n", signif(cor_fn(xVal, yVal), 3), sep = "", collapse = ""), mapping, xP = 0.5, yP = 0.5, xrange = xrange, yrange = yrange, ...) + theme(legend.position = "none") p$type <- "continuous" p$subType <- "cor" p } } $mapping - x -> disp - y -> cyl $dataPos [1] 1 $gg NULL attr(,"class") [1] "ggmatrix_plot_obj" $plots[[7]] $fn function (data, mapping, ...) { allParams$data <- data allParams$mapping <- mapping argsList <- list(...) allParams[names(argsList)] <- argsList do.call(original_fn, allParams) } attr(,"class") [1] "ggmatrix_fn_with_params" attr(,"name") [1] "ggally_points" attr(,"params") list() attr(,"fn") function (data, mapping, ...) { p <- ggplot(data = data, mapping = mapping) + geom_point(...) p$type <- "continuous" p$subType <- "points" p } $mapping - x -> mpg - y -> disp $dataPos [1] 1 $gg NULL attr(,"class") [1] "ggmatrix_plot_obj" $plots[[8]] $fn function (data, mapping, ...) { allParams$data <- data allParams$mapping <- mapping argsList <- list(...) allParams[names(argsList)] <- argsList do.call(original_fn, allParams) } attr(,"class") [1] "ggmatrix_fn_with_params" attr(,"name") [1] "ggally_points" attr(,"params") list() attr(,"fn") function (data, mapping, ...) { p <- ggplot(data = data, mapping = mapping) + geom_point(...) p$type <- "continuous" p$subType <- "points" p } $mapping - x -> cyl - y -> disp $dataPos [1] 1 $gg NULL attr(,"class") [1] "ggmatrix_plot_obj" $plots[[9]] $fn function (data, mapping, ...) { allParams$data <- data allParams$mapping <- mapping argsList <- list(...) allParams[names(argsList)] <- argsList do.call(original_fn, allParams) } attr(,"class") [1] "ggmatrix_fn_with_params" attr(,"name") [1] "ggally_densityDiag" attr(,"params") list() attr(,"fn") function (data, mapping, ..., rescale = FALSE) { p <- ggplot(data, mapping) + scale_y_continuous() if (identical(rescale, TRUE)) { p <- p + stat_density(aes(y = ..scaled.. \* diff(range(x, na.rm = TRUE)) + min(x, na.rm = TRUE)), position = "identity", geom = "line", ...) } else { p <- p + geom_density(...) } p$type <- "diag" p$subType <- "density" p } $mapping - x -> disp $dataPos [1] 1 $gg NULL attr(,"class") [1] "ggmatrix_plot_obj" $title NULL $xlab NULL $ylab NULL $showStrips NULL $xAxisLabels [1] "mpg" "cyl" "disp" $yAxisLabels [1] "mpg" "cyl" "disp" $showXAxisPlotLabels [1] TRUE $showYAxisPlotLabels [1] TRUE $xProportions NULL $yProportions NULL $legend NULL $gg NULL $nrow [1] 3 $ncol [1] 3 $byrow [1] TRUE attr(,"class") [1] "gg" "ggmatrix" — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ggobi/ggally/issues/201#issuecomment-249396444, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFsL08Xo87jNB7m-sUGri0wJ-z5HL9Qks5qtckhgaJpZM4KFcfl .
eipi10 commented 8 years ago

I tried the second option, but now the ggpairs plot has no axis titles.

schloerke commented 8 years ago

The column labels have been moved to the facet strips location.

If you'd like an overall x or y axis title, this can be set as ggpairs argument (xlab and ylab).

It looks like you're using mtcars. Can you give me your ggpairs code to test things out?

On Sat, Sep 24, 2016 at 11:19 PM eipi10 notifications@github.com wrote:

I tried the second option, but now the ggpairs plot has no axis titles.

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/ggobi/ggally/issues/201#issuecomment-249400194, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFsL28kTwAHBT1111nNKf5_uq-DPtfxks5qtehWgaJpZM4KFcfl .

eipi10 commented 8 years ago

Well, I evidently need to be more observant! Yes, that looks good. I also just tried one with the iris data frame so I could try out facetdensity:

ggpairs(iris, lower=list(combo="facetdensity"))

Thanks for your help!

schloerke commented 8 years ago

fixed with #200