2

这是我编写的代码:

sp9 <- ggplot(PWPdf3_12_1250, aes(log10(Avsize), log10(Prob))) +
  geom_point(color= "blue")

plotx <- ggplot(mpg, aes(displ, hwy)) + 
  geom_point() +
  geom_point(color= "blue")

#plot example from internet
plotx + 
  annotation_custom(
    ggplotGrob(sp9), 
    xmin = 5, xmax = 7, ymin = 30, ymax = 44
  )

#plotting my own data
sp9+ 
  annotation_custom(
    ggplotGrob(sp9), 
    xmin = 5, xmax = 7, ymin = 30, ymax = 44
  )

输出是:

在此处输入图像描述

在此处输入图像描述

我不知道为什么 annotation_custom 在案例 1 中成功插入了 grob,但在案例 2 中没有这样做。我已经包含了库 egg 和 tidyverse

4

0 回答 0