Using different data in ggplot's geom_rug than I use in the rest of the plot

后端 未结 2 1669
轻奢々
轻奢々 2021-01-13 16:57

I am having trouble getting geom_rug to plot some data into an existing plot. Here\'s an example plot, where I am comparing some visit day to the magnitude of some measureme

相关标签:
2条回答
  • 2021-01-13 17:04

    I would try either this:

    ggplot(test, aes(x = visit, y = mag)) + geom_point() + 
      geom_rug(data=vac, aes(x = visit,y = NULL))
    

    or perhaps a better option this:

    ggplot() + 
      geom_point(data = test,aes(x = visit,y = mag)) + 
      geom_rug(data=vac, aes(x = visit))
    
    0 讨论(0)
  • 2021-01-13 17:06

    You should specify inherit.aes = FALSE in the geom_rug() line, otherwise it inherits y = mag from the main ggplot() call.

    ggplot(test, aes(x = visit, y = mag)) + 
      geom_point() + 
      geom_rug(data=vac, aes(x = visit), inherit.aes = F)
    

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