I would like to produce a graphic combining four facets of a graph with insets in each facet showing a detail of the respective plot. This is one of the things I tried:
Modifying off @user63230's excellent answer:
pp <- map(unique(data_frame$max_rep), function(x) {
plot2 +
aes(alpha = ifelse(max_rep == x, 1, 0)) +
coord_cartesian(xlim = c(12, 14),
ylim = c(3, 4)) +
labs(x = NULL, y = NULL) +
scale_alpha_identity() +
facet_null() +
theme(
strip.background = element_blank(),
strip.text.x = element_blank(),
legend.position = "none",
axis.text=element_blank(),
axis.ticks=element_blank()
)
})
Explanation:
alpha
, where lines belonging to the other replicate numbers are assigned 0 for transparency;scale_alpha_identity()
to tell ggplot that the alpha mapping is to be used as-is: i.e. 1 for 100%, 0 for 0%.facet_null()
to override plot2's existing facet_wrap
, which removes the facet for the inset.Everything else is unchanged from the code in the question.