[R] Plots in ioslides and R markdown

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Fri Aug 24 16:53:10 CEST 2018


a) Keep the mailing list in the conversation... someone else may have useful input, and others may benefit from reading the discussion.

b) If the issue can be reproduced on your end with something like a basic plot(mpg~disk, data=mtcars) call, then you should use that instead of your complicated example. If the problem only appears when you use certain plotting functions hidden inside your plot1 through plot6 functions, we can't tell that from here. Sorting that out is part of making your example minimal as the Posting Guide requests.

c) If you can only reproduce with certain data, then you can use dput to give us the necessary data.[1][2] It is up to you to determine what the minimal data needed to demo the problem is, but we don't want to sift through some large data blob only to find out that it was not relevant so you need to do that. 

d) Interactions with data files are hard to make reproducible on someone else's computer... saving data with different filenames will not help fix that problem.

e) Note that this is the R-help mailing list, not the RStudio-help mailing list nor the rmarkdown-package-help mailing list. We can and often do provide help on using contributed packages anyway, but you should be aware that not everyone here uses RStudio so doing your best to provide a reproducible example is in your interest if you want readers to consider your question on topic.

There are many discussions online of how to communicate R examples, such as [1][2][3]. In particular I think [3] is useful because it forces you to confirm that the example will run in a fresh R environment which is the first step to insuring it will run on our computers and we can dig into the problem. in this case you could use it to help confirm that your R code should work for us without the rmarkdown.

[1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example

[2] http://adv-r.had.co.nz/Reproducibility.html

[3] https://cran.r-project.org/web/packages/reprex/index.html (read the vignette) 


On August 24, 2018 3:13:17 AM PDT, Patrick Connolly <p_connolly using slingshot.co.nz> wrote:
>On Thu, 23-Aug-2018 at 07:23AM -0700, Jeff Newmiller wrote:
>
>|> This is not reproducible because you have not provided the plot
>|> code or sample data. Output of sessionInfo would probably be
>|> appropriate as well.
>
>I took it as read that the plotting functions themselves aren't an
>issue since they operate as intended outside of the Rmarkdown
>space. Any function that uses the function plot() successfully will
>do.  I was trying to ascertain how I should be setting up the scaling.
>
>|> As to whether needing to load objects is typical... yes, rmarkdown
>|> runs from a fresh environment to emphasize reproducibility, but
>|> your load command is bypassing that for us.
>
>The objects loaded from .RData took hours of simulating and it's out
>of the question to run them again inside Rmarkdown.  Though the script
>used in the creation of .RData is reproducable, perhaps it would be
>clearer for me to have saved the objects to a file by a different
>name.
>
>Is there a better way to do that??
>
>
>
>|> On August 23, 2018 2:15:19 AM PDT, Patrick Connolly
><p_connolly using slingshot.co.nz> wrote:
>|> >I'm having difficulty getting plots into ioslides.  It seems to me
>|> >that the scale is completely out, but I can't figure out what to do
>|> >about it.  Whatever I try, I get the title slide, then a second
>with a
>|> >horizontal line and a vertical line in the bottom right corner.  It
>|> >looks like a badly scaled plot about 25 times the size of the
>plotting
>|> >area, so only a fragment is visible.
>|> >
>|> >This is the code I've tried:
>|> >
>|> >---
>|> >title: "Barking up the wrong tree"
>|> >author: "Patrick Connolly"
>|> >date: "`r format(Sys.time(), '%a %d/%m/%Y %H:%M')`"
>|> >output: ioslides_presentation
>|> >---
>|> >
>|> >```{r global_options, echo=FALSE}
>|> >knitr::opts_chunk$set(tidy=TRUE,
>|> >                      warning=FALSE, 
>|> >                      message=FALSE,
>|> >                      cache=FALSE,
>|> >                      dpi=600)
>|> >```
>|> >
>|> >```{r use these functions, echo= FALSE}
>|> >  load(".RData") ## code for 6 plotting functions
>|> >
>|> >``
>|> >## 6 different Trees
>|> >
>|> >```{r 6 different Trees, echo = FALSE, messages=FALSE, fig.width =
>7,
>|> >fig.height = 5}
>|> >
>|> >###  par(mfrow = c(2, 3))
>|> >plot1()
>|> >plot2()
>|> >plot3()
>|> >plot4()
>|> >plot5()
>|> >plot6()
>|> >}
>|> >```
>|> >
>|> >If I run the plot functions in the Console, it all works and
>displays
>|> >correctly in Rstudiio's plot panel, even the mfrow bit.  But I
>haven't
>|> >worked out how to include the code into Rmarkdown.  I thought it
>might
>|> >be less taxing to not try putting the 6 plots on the same slide,
>but
>|> >it makes no difference when I commented out the mfrow bit.
>|> >
>|> >I'm not very familiar with the workings of Markdown or Rstudio, but
>it
>|> >does seem strange to me that I need to specifically load the global
>|> >environment otherwise it's not visible.  Is that to be expected?
>|> >
>|> >Ideas welcome, particularly about scaling.
>|> 
>|> -- 
>|> Sent from my phone. Please excuse my brevity.

-- 
Sent from my phone. Please excuse my brevity.




More information about the R-help mailing list