ggbio
ggbio copied to clipboard
limits in color scales using tracks
I've encountered what seems like a bug when attempting to set color or fill scales in two different tracks. Basically, I would like both tracks to have the same color limits so they can be directly compared, but when I try to do this and then display them both using tracks() it does not work.
Example using the test data from the vignette (gr): track1 <- autoplot(gr, aes(fill=value))+ scale_fill_continuous(low="blue", high="red", limits=c(0, 200)) track2 <- autoplot(gr, aes(fill=score))+ scale_fill_continuous(low="blue", high="red", limits=c(0, 200))
Both display as expected when I plot them individually, but when I combine them:
tracks(track1, track2)
I get the error:
Error in FUN(X[[2L]], ...) : object 'res' not found
Seems like this should be possible, as it is very useful to be able to compare similar data on the same scale. Is this a bug, or am I missing something?
Thanks, Gretchen
I can confirm this.
The function 'getLimitsFromScales' takes each scale and tests if it has a "limits" entry. If it does it tests if its aesthetics contain either the x* or y* aesthetics and creates a res object based on which it is.
Of course a fill (or color) scale has a limits entry, but no x or y related aesthetics, so no res object is ever created.
Presumably a good fix would be:
function (obj)
{
scal <- obj$scales$scales
lst <- lapply(scal, function(x) {
if (!is.null(x$limits)) {
res <- NULL
limits <- x$limits
if (any(x$aesthetics %in% c("x", "xmin", "xmax",
"xend", "xintercept", "xmin_final", "xmax_final"))) {
res <- data.frame(xmin = limits[1], xmax = limits[2],
ymin = NA, ymax = NA)
}
if (any(x$aesthetics %in% c("y", "ymin", "ymax",
"yend", "yintercept", "ymin_final", "ymax_final"))) {
res <- data.frame(ymin = limits[1], ymax = limits[2],
xmin = NA, xmax = NA)
}
}
else {
res <- NULL
}
res
})
lst <- lst[!is.null(lst)]
res <- do.call("rbind", lst)
res <- data.frame(xmin = min(res$xmin[!is.na(res$xmin)]),
xmax = max(res$xmax[!is.na(res$xmax)]), ymin = min(res$ymin[!is.na(res$ymin)]),
ymax = max(res$ymax[!is.na(res$ymax)]))
res
}
Thanks Ian for your patch, I am working on this bug now!
On Fri, Jan 24, 2014 at 12:19 PM, Ian Sudbery [email protected]:
I can confirm this.
The function 'getLimitsFromScales' takes each scale and tests if it has a "limits" entry. If it does it tests if its aesthetics contain either the x* or y* aesthetics and creates a res object based on which it is.
Of course a fill (or color) scale has a limits entry, but no x or y related aesthetics, so no res object is ever created.
Presumably a good fix would be:
function (obj) { scal <- obj$scales$scales lst <- lapply(scal, function(x) { if (!is.null(x$limits)) { res <- NULL limits <- x$limits if (any(x$aesthetics %in% c("x", "xmin", "xmax", "xend", "xintercept", "xmin_final", "xmax_final"))) { res <- data.frame(xmin = limits[1], xmax = limits[2], ymin = NA, ymax = NA) } if (any(x$aesthetics %in% c("y", "ymin", "ymax", "yend", "yintercept", "ymin_final", "ymax_final"))) { res <- data.frame(ymin = limits[1], ymax = limits[2], xmin = NA, xmax = NA) }
} else { res <- NULL } res }) lst <- lst[!is.null(lst)] res <- do.call("rbind", lst) res <- data.frame(xmin = min(res$xmin[!is.na(res$xmin)]), xmax = max(res$xmax[!is.na(res$xmax)]), ymin = min(res$ymin[!is.na(res$ymin)]), ymax = max(res$ymax[!is.na(res$ymax)])) res
}
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/38#issuecomment-33242309 .
Hi Gretchen,
I cannot confirm the bug with latest ggbio in both released version or devel branch .... Can you try update your ggbio one day later?
Ian, I will keep looking into the issue you mentioned!
cheers
Tengfei
On Tue, Feb 4, 2014 at 3:17 PM, Tengfei Yin [email protected] wrote:
Thanks Ian for your patch, I am working on this bug now!
On Fri, Jan 24, 2014 at 12:19 PM, Ian Sudbery [email protected]:
I can confirm this.
The function 'getLimitsFromScales' takes each scale and tests if it has a "limits" entry. If it does it tests if its aesthetics contain either the x* or y* aesthetics and creates a res object based on which it is.
Of course a fill (or color) scale has a limits entry, but no x or y related aesthetics, so no res object is ever created.
Presumably a good fix would be:
function (obj) { scal <- obj$scales$scales lst <- lapply(scal, function(x) { if (!is.null(x$limits)) { res <- NULL limits <- x$limits if (any(x$aesthetics %in% c("x", "xmin", "xmax", "xend", "xintercept", "xmin_final", "xmax_final"))) { res <- data.frame(xmin = limits[1], xmax = limits[2], ymin = NA, ymax = NA) } if (any(x$aesthetics %in% c("y", "ymin", "ymax", "yend", "yintercept", "ymin_final", "ymax_final"))) { res <- data.frame(ymin = limits[1], ymax = limits[2], xmin = NA, xmax = NA) }
} else { res <- NULL } res }) lst <- lst[!is.null(lst)] res <- do.call("rbind", lst) res <- data.frame(xmin = min(res$xmin[!is.na(res$xmin)]), xmax = max(res$xmax[!is.na(res$xmax)]), ymin = min(res$ymin[!is.na(res$ymin)]), ymax = max(res$ymax[!is.na(res$ymax)])) res
}
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/38#issuecomment-33242309 .
Hi Ian,
I just checked, the patch you provided in this thread is basically the same with current version, I am not sure when I (or somebody else) already fixed this problem for getLimitsFromScales.
Thanks!
Tengfei
On Tue, Feb 4, 2014 at 3:35 PM, Tengfei Yin [email protected] wrote:
Hi Gretchen,
I cannot confirm the bug with latest ggbio in both released version or devel branch .... Can you try update your ggbio one day later?
Ian, I will keep looking into the issue you mentioned!
cheers
Tengfei
On Tue, Feb 4, 2014 at 3:17 PM, Tengfei Yin [email protected] wrote:
Thanks Ian for your patch, I am working on this bug now!
On Fri, Jan 24, 2014 at 12:19 PM, Ian Sudbery [email protected]:
I can confirm this.
The function 'getLimitsFromScales' takes each scale and tests if it has a "limits" entry. If it does it tests if its aesthetics contain either the x* or y* aesthetics and creates a res object based on which it is.
Of course a fill (or color) scale has a limits entry, but no x or y related aesthetics, so no res object is ever created.
Presumably a good fix would be:
function (obj) { scal <- obj$scales$scales lst <- lapply(scal, function(x) { if (!is.null(x$limits)) { res <- NULL limits <- x$limits if (any(x$aesthetics %in% c("x", "xmin", "xmax", "xend", "xintercept", "xmin_final", "xmax_final"))) { res <- data.frame(xmin = limits[1], xmax = limits[2], ymin = NA, ymax = NA) } if (any(x$aesthetics %in% c("y", "ymin", "ymax", "yend", "yintercept", "ymin_final", "ymax_final"))) { res <- data.frame(ymin = limits[1], ymax = limits[2], xmin = NA, xmax = NA) }
} else { res <- NULL } res }) lst <- lst[!is.null(lst)] res <- do.call("rbind", lst) res <- data.frame(xmin = min(res$xmin[!is.na(res$xmin)]), xmax = max(res$xmax[!is.na(res$xmax)]), ymin = min(res$ymin[!is.na(res$ymin)]), ymax = max(res$ymax[!is.na(res$ymax)])) res
}
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/38#issuecomment-33242309 .
Hi Tegnfei,
Just installed the latest version, and it works now (using the example from my post, haven't tried with real data yet). Thanks! Gretchen
On Feb 4, 2014, at 12:45 PM, Tengfei Yin wrote:
Hi Ian,
I just checked, the patch you provided in this thread is basically the same with current version, I am not sure when I (or somebody else) already fixed this problem for getLimitsFromScales.
Thanks!
Tengfei
On Tue, Feb 4, 2014 at 3:35 PM, Tengfei Yin [email protected] wrote:
Hi Gretchen,
I cannot confirm the bug with latest ggbio in both released version or devel branch .... Can you try update your ggbio one day later?
Ian, I will keep looking into the issue you mentioned!
cheers
Tengfei
On Tue, Feb 4, 2014 at 3:17 PM, Tengfei Yin [email protected] wrote:
Thanks Ian for your patch, I am working on this bug now!
On Fri, Jan 24, 2014 at 12:19 PM, Ian Sudbery [email protected]:
I can confirm this.
The function 'getLimitsFromScales' takes each scale and tests if it has a "limits" entry. If it does it tests if its aesthetics contain either the x* or y* aesthetics and creates a res object based on which it is.
Of course a fill (or color) scale has a limits entry, but no x or y related aesthetics, so no res object is ever created.
Presumably a good fix would be:
function (obj) { scal <- obj$scales$scales lst <- lapply(scal, function(x) { if (!is.null(x$limits)) { res <- NULL limits <- x$limits if (any(x$aesthetics %in% c("x", "xmin", "xmax", "xend", "xintercept", "xmin_final", "xmax_final"))) { res <- data.frame(xmin = limits[1], xmax = limits[2], ymin = NA, ymax = NA) } if (any(x$aesthetics %in% c("y", "ymin", "ymax", "yend", "yintercept", "ymin_final", "ymax_final"))) { res <- data.frame(ymin = limits[1], ymax = limits[2], xmin = NA, xmax = NA) }
} else { res <- NULL } res }) lst <- lst[!is.null(lst)] res <- do.call("rbind", lst) res <- data.frame(xmin = min(res$xmin[!is.na(res$xmin)]), xmax = max(res$xmax[!is.na(res$xmax)]), ymin = min(res$ymin[!is.na(res$ymin)]), ymax = max(res$ymax[!is.na(res$ymax)])) res }
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/38#issuecomment-33242309 .
— Reply to this email directly or view it on GitHub.
Cool, just you know, there is a reported bug in track labeling of new version, that when you add labels to tracks, it messed up, I already fixed that in devel, and also in released version today, the released version will be up in bioc for update one or two day later.
cheers
Tengfei
On Tue, Feb 4, 2014 at 4:23 PM, gehrenk [email protected] wrote:
Hi Tegnfei,
Just installed the latest version, and it works now (using the example from my post, haven't tried with real data yet). Thanks! Gretchen
On Feb 4, 2014, at 12:45 PM, Tengfei Yin wrote:
Hi Ian,
I just checked, the patch you provided in this thread is basically the same with current version, I am not sure when I (or somebody else) already fixed this problem for getLimitsFromScales.
Thanks!
Tengfei
On Tue, Feb 4, 2014 at 3:35 PM, Tengfei Yin [email protected] wrote:
Hi Gretchen,
I cannot confirm the bug with latest ggbio in both released version or devel branch .... Can you try update your ggbio one day later?
Ian, I will keep looking into the issue you mentioned!
cheers
Tengfei
On Tue, Feb 4, 2014 at 3:17 PM, Tengfei Yin [email protected] wrote:
Thanks Ian for your patch, I am working on this bug now!
On Fri, Jan 24, 2014 at 12:19 PM, Ian Sudbery < [email protected]>wrote:
I can confirm this.
The function 'getLimitsFromScales' takes each scale and tests if it has a "limits" entry. If it does it tests if its aesthetics contain either the x* or y* aesthetics and creates a res object based on which it is.
Of course a fill (or color) scale has a limits entry, but no x or y related aesthetics, so no res object is ever created.
Presumably a good fix would be:
function (obj) { scal <- obj$scales$scales lst <- lapply(scal, function(x) { if (!is.null(x$limits)) { res <- NULL limits <- x$limits if (any(x$aesthetics %in% c("x", "xmin", "xmax", "xend", "xintercept", "xmin_final", "xmax_final"))) { res <- data.frame(xmin = limits[1], xmax = limits[2], ymin = NA, ymax = NA) } if (any(x$aesthetics %in% c("y", "ymin", "ymax", "yend", "yintercept", "ymin_final", "ymax_final"))) { res <- data.frame(ymin = limits[1], ymax = limits[2], xmin = NA, xmax = NA) }
} else { res <- NULL } res }) lst <- lst[!is.null(lst)] res <- do.call("rbind", lst) res <- data.frame(xmin = min(res$xmin[!is.na(res$xmin)]), xmax = max(res$xmax[!is.na(res$xmax)]), ymin = min(res$ymin[!is.na(res$ymin)]),
ymax = max(res$ymax[!is.na(res$ymax)])) res }
Reply to this email directly or view it on GitHub< https://github.com/tengfei/ggbio/issues/38#issuecomment-33242309> .
Reply to this email directly or view it on GitHub.
Reply to this email directly or view it on GitHubhttps://github.com/tengfei/ggbio/issues/38#issuecomment-34108743 .