1

I'm looking to make a graph in R, something like this

enter image description here

Where plot 1, 2, and 3 are are at specified markings along the x-axis.

Noting an answer to a similar question, I think this can be done using the grconvertX function with fig, but I can't seem to get the code I wrote to plot more than one of the subplots. Here is the toy data and code.

  #example
  #main plot variables
   x = seq(0,1, by=.1)
   y = (x/(.2+x))
   plot(x,y, type='b')

  #subplot variables
   xlocations = c(.2,.6,.8)
   nXticks = length(xlocations)

  for(i in 1:nXtick){
    xloc = xlocations[i]
    xRad = .05
    par(fig = c(grconvertX(c(xloc-xRad, xloc+xRad), from="user", to="ndc"),
                grconvertY(c(0, 0.1), from="user", to="ndc")),
        mar = c(0,0,0,0),
        new = TRUE)
    plot(1:10,1:10, axes=F, xlab='', ylab=''); box();
  }
Community
  • 1
  • 1
WetlabStudent
  • 2,556
  • 3
  • 25
  • 39
  • 1
    Is this not the same post? http://stackoverflow.com/questions/14288194/plot-inside-a-plot or http://stackoverflow.com/questions/20896439 – zx8754 Oct 19 '16 at 07:43
  • 1
    `ggvis` "embedded plots" may be what you are looking for. Here are examples : [visualize complex data with subplots](https://www.r-bloggers.com/visualize-complex-data-with-subplots/). – Paul Rougieux Oct 19 '16 at 07:48
  • 1
    The `grid` package is also suited for this job, see e.g. http://ww2.amstat.org/publications/jse/v18n3/zhou.pdf for an introduction – tobiasegli_te Oct 19 '16 at 07:58
  • @zx8754 it is very similar but not a duplicate, since that question does not specify the location of the internal plot, and that aspect of the question is the central point of this one. In addition the answers do not explain this part of the question above. While grconvertX, answer seems like this is possible, it throws errors when the arguments are modified. – WetlabStudent Oct 19 '16 at 08:08
  • I see, so if you have 1,2,3,4 on Xaxis, then you would need 4 subplots on top of each number on X? – zx8754 Oct 19 '16 at 08:36
  • @zx8754 yes, exactly – WetlabStudent Oct 19 '16 at 08:38
  • 2
    @PaulRougieux subplots no longer works for later versions of R, for what I can tell "package ‘ggsubplot’ is not available (for R version 3.3.1)" – WetlabStudent Oct 19 '16 at 09:53
  • 1
    @MHH, yes embedded plots might provide the functionality that you want and [it is supposed to replace faceting in ggvis](http://ggvis.rstudio.com/0.1/ggplot2.html). But it seem to be still under development according to [this github issue](https://github.com/rstudio/ggvis/issues/442) and to [ggvis layers](http://ggvis.rstudio.com/layers.html): "a future major release [...] will add support for facetting/subplots." Sorry I had this at the back of my mind and didn't know it wasn't available yet. – Paul Rougieux Oct 19 '16 at 10:11

0 Answers0