(feature) Specify layer(s) that ggMarginal uses
wpetry opened this issue · 6 comments
This feature would allow the user to specify which layer of the ggplot is used to make the marginal plots. It would be a more controlled middle ground between the original behavior addressed in issue #67 and the current behavior (using all layers).
Could you please post some usecases/examples of how you see this working?
I'm making a phase plot using a ribbon annotation to separate areas with qualitatively different outcomes. I want to plot the marginal density of the scatter points, but the data for the annotation ribbon appear to be driving the behavior of the marginal density plots.
Load packages, make data:
library(tidyverse)
library(ggExtra)
theme_set(theme_bw() + theme(panel.grid = element_blank()))
# make scatterplot data
set.seed(503234)
dat <- tibble(x = rbeta(5000, shape1 = 5, shape2 = 1),
y = exp(rnorm(5000, mean = 0, sd = 2)))
# make data for annotation ribbon (i.e., the phase space boundaries)
rib <- tibble(x = seq(0, 1, 0.001)) %>%
mutate(min = 0.99 * x + 0.01,
max = -99 * x + 100)
# Without annotation layer, WORKS
p <- ggplot(dat, aes(x = x, y = y))+
geom_point(alpha = 0.15)+
scale_y_log10()+
coord_cartesian(xlim = c(0, 1))
ggMarginal(p, type = "density")
# With phase boundary annotation layer, fails
q <- ggplot(dat, aes(x = x, y = y))+
annotate("ribbon", x = rib$x, ymin = rib$min, ymax = rib$max,
fill = "lightblue")+
geom_point(alpha = 0.15)+
scale_y_log10()+
coord_cartesian(xlim = c(0, 1))
ggMarginal(q, type = "density")
Perhaps one could add an argument layers
to the function that accepts a numeric vector of plot layers to use for the marginal plots. This would be difficult for users (they'd have to manually count which layer would be the focus) and fragile (adding another layer could silently return marginal plots on undesired layers).
This code does work for me. I tried both the CRAN and the latest GitHub versions.
library(tidyverse)
library(ggExtra)
theme_set(theme_bw() + theme(panel.grid = element_blank()))
# make scatterplot data
set.seed(503234)
dat <- tibble(x = rbeta(5000, shape1 = 5, shape2 = 1),
y = exp(rnorm(5000, mean = 0, sd = 2)))
# make data for annotation ribbon (i.e., the phase space boundaries)
rib <- tibble(x = seq(0, 1, 0.001)) %>%
mutate(min = 0.99 * x + 0.01,
max = -99 * x + 100)
q <- ggplot(dat, aes(x = x, y = y))+
annotate("ribbon", x = rib$x, ymin = rib$min, ymax = rib$max,
fill = "lightblue")+
geom_point(alpha = 0.15)+
scale_y_log10()+
coord_cartesian(xlim = c(0, 1))
ggMarginal(q, type = "density")
Hello, is it possible to add axis to marginal plots created with ggMarginal () ?
I think you're talking about the same thing as #64
Exactly, @daattali. I am a reviewer on a paper and it's a pity that the proportions of the density plots are not display to get, in a quick glance, all the info needed to interpret the figure.
On the other hand, I'm building up a figure using a bubble plot (latitude and longitude points) over a map (shapefile). I'm using several geom_line(), geom_path(), geom_polygon() layers in a ggplot2 mode. Then the ggMarginal() takes the info of all latitude and longitud points showed in the figure, including the borders of the shapefiles which are build up based on points with a latitude and longitude values...is there any way to make the ggMarginal() function take the latitude and longitud points of the elements georeferenciated in the map but not those belonging to the borders of the countries?
thanks for a great package