Closed paulobarros closed 7 months ago
Thanks for the bug report. Please could you provide a reproducible example, i.e. one that I can actually run. (Hint: I don't have a data set called PCA.)
Sorry! My bad! Updated the previous comment with the full code.
And what are from
and to
? Maybe just double check it's reproducible by copy-pasting into a new R session
Sorry again, copy-pasted into a new R session and it runs.
So I get:
As I understand it, you want the inset plot to show only the expanded area, not the white space on either side.
Can I ask why something like the following code doesn't satisfy your needs? It doesn't use the plot
argument and simply expands the area that you are interested in:
from <- c(
xmin = -0.005,
xmax = 0.005,
ymin = -0.065,
ymax = -0.02)
to <- c(0.05, 0.2, -0.04,0.03)
pca |>
ggplot(aes(x = PC1, y = PC2)) +
geom_point(aes(fill = gg), color = alpha("black",.75), shape = 21, size = 6) +
scale_fill_manual(values = ggColors |> unique()) +
labs(x = "PC1 (10.34%)", y = "PC2 (7.73%)",) +
theme_bw(base_family = "Barlow Condensed", base_size = 16) +
geom_magnify(from = from,
to = to,
shadow = TRUE,
axes = "xy")
This gives me:
In any case, I think the reason for your bug is that the geom_magnify
code overrides the limits of the inset plot - that's the way it works. So if you don't want it to do that, then indeed just using an annotation may be more flexible.
You might also want to mess around with the scale.inset
argument. E.g.
from <- c(xmin = -0.01,
xmax = 0.005,
ymin = -0.065,
ymax = -0.02)
to <- c(0.05, 0.2, -0.04,0.03)
pca |>
#filter(!gg %in% c("TT","China")) |>
ggplot(aes(x = PC1, y = PC2,)) +
geom_point(aes(fill = gg),
color = alpha("black",.75),
shape = 21,
size = 6) +
scale_fill_manual(values = ggColors |> unique()) +
labs(x = "PC1 (10.34%)",
y = "PC2 (7.73%)",) +
#scale_color_manual(values = ggLines |> unique()) +
theme_bw(base_family = "Barlow Condensed", base_size = 16) +
geom_magnify(from = from,
to = to,
shadow = TRUE,
axes = "xy",
scale.inset = c(0.45, 1)
)
which gives
First of all, amazing package! Thank you so much!
Describe the bug I cannot make the magnified plot to fill the whole area of the inset. I am using the option with a provided inset plot, but it seems that it is being constrained somehow and not filling the whole inset area declare in the
to
argument. When I tried withannotate_custom
it works fine, but withgeom_magnify
I could not make it work. I've set limits, breaks, and still nothing.To Reproduce
Expected behavior I would like the result to be like this version I was able to make with
annotate_custom
Other information