Highlighting regions of interest in ggplot2

前端 未结 1 547
没有蜡笔的小新
没有蜡笔的小新 2020-12-30 08:26

In vanilla plotting, it is possible to use a polygon call in the panel.first argument to plot to highlight a background region. Is it

相关标签:
1条回答
  • 2020-12-30 08:51

    Yes, that's possible with ggplot2. To preserve the visibility of grid lines you can use alpha transparency. Note that, in general, the order in which geoms and stats are applied matters.

    tmp <- with(mtcars, data.frame(x=c(0, 0, max(wt)*35), y=c(0, max(wt), max(wt))))
    ggplot(mtcars, aes(hp, wt)) + 
      geom_polygon(data=tmp, aes(x, y), fill="#d8161688") + 
      geom_point()
    

    ggplot2 output

    0 讨论(0)
提交回复
热议问题