I am trying to create a HTML5 presentation with ggplot2 plots in it. I am using Rstudio's Rpres format. However I see no plot in the output presentation. For the example below, I get a textbox with a message like this:
<img src="PT terms for each age
Strata.Rnw-figure/unnamed-chunk-1-1.png" title="plot of chunk
unnamed-chunk-1" alt="plot of chunk unnamed-chunk-1" style="display:
block; margin: auto;" />
For other chunks I see no plot at all. I see the figures generated in a subdirectory, but they are not included in the presentation.
This could be due to the fact that I use setwd
to change the current directory inside one of the chunks.
How do I make sure the plots are added to the presentation?
```{r, echo=FALSE,fig.width=8, fig.height=4, warning=FALSE, eval=TRUE, message=FALSE, tidy=TRUE, fig.align='center',fig=TRUE}
PT.term.table.combo.df <- structure(list(term = structure(c(3L, 6L, 10L, 9L, 5L, 8L, 2L,
7L, 1L, 4L, 11L, 16L, 20L, 13L, 18L, 19L, 15L, 14L, 17L, 12L), .Label = c("Erythema",
"Injection site erythema", "Injection site pain", "Injection site swelling",
"Pain", "Pain in extremity", "Paraesthesia", "Pruritus", "Rash",
"Urticaria", "Dizziness", "Fatigue", "Headache", "Unknown",
"Loss of consciousness", "Nausea", "Pallor", "Pyrexia", "Syncope",
"Vomiting", "Blood pressure decreased", "Condition aggravated",
"Convulsion", "Fall", "Grand mal convulsion", "Head injury",
"Immediate post-injection reaction", "Condition8",
"Condition2", "Condition3", "Condition4",
"Condition1", "Menstruation delayed", "Menstruation irregular",
"Condition5", "Condition12", "Unevaluable event"
), class = "factor"), normalized.count = structure(c(0.758666519304954,
0.509556068608868, 0.498746392459638, 0.426484861272957, 0.41955098519173,
0.333070361160926, 0.306233446655841, 0.303395720748491, 0.281332387076534,
0.275858307359097, 2.05157281092953, 1.55514068644281, 0.761792303294041,
0.730331039886107, 0.553772087835693, 0.545722098808532, 0.426814370578148,
0.422207780194755, 0.401335815218956, 0.325021057176447), .Names = c("Injection site pain",
"Pain in extremity", "Urticaria", "Rash", "Pain", "Pruritus",
"Injection site erythema", "Paraesthesia", "Erythema", "Injection site swelling",
"Dizziness", "Nausea", "Vomiting", "Headache", "Pyrexia", "Syncope",
"Loss of consciousness", "Hyperhidrosis", "Pallor", "Fatigue"
)), source = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("1",
"2", "3", "4"), class = "factor")), .Names = c("term", "normalized.count",
"source"), row.names = c("Injection site pain", "Pain in extremity",
"Urticaria", "Rash", "Pain", "Pruritus", "Injection site erythema",
"Paraesthesia", "Erythema", "Injection site swelling", "Dizziness",
"Nausea", "Vomiting", "Headache", "Pyrexia", "Syncope", "Loss of consciousness",
"Hyperhidrosis", "Pallor", "Fatigue"), class = "data.frame")
library(ggplot2)
library(gdata)
#PT.term.table.combo.df <- combine(lapply( PT.term.tables$communities , FUN = function(x) { data.frame (term = names(x), normalized.count = x)}),names = 1:4)
PT.term.table.combo.df <- do.call(what=combine,args=lapply( PT.term.tables$communities , FUN = function(x) { data.frame (term = names(x), normalized.count = x)}))
levels(PT.term.table.combo.df$source)<- 1:4
#PT.term.table <- PT.term.tables$communities[[1]]
#term.df <- data.frame (term=names(PT.term.table), normalized.count = PT.term.table)
PT.plot<-ggplot(data=PT.term.table.combo.df, aes(x=term, y=normalized.count )) +
geom_bar(stat='identity') + coord_flip()+facet_wrap(~source)
print(PT.plot)
```
Ok, I was able to fix my problem by renaming my Rpres file, so that it does not have any spaces. So instead of "PT terms for each age Strata.Rnw.Rpres"
I chose"PT_terms_plots.Rpres"
as the filename.
If you believe this might be a bug, comment to let me know so that I can contact Rstudio devs.