无法在Rpres中创建绘图(RStudio的HTML演示文稿格式)

时间:2014-12-31 23:12:50

标签: r plot ggplot2 rstudio rpres

我正在尝试使用ggplot2图创建HTML5演示文稿。我正在使用Rstudio的Rpres格式。但是我在输出演示文稿中看不到任何情节。对于下面的示例,我得到一个文本框,其中包含以下消息:

<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;" />

对于其他块,我看不到任何情节。我看到在子目录中生成的数字,但它们不包含在演示文稿中。 这可能是因为我使用setwd来更改其中一个块内的当前目录。

如何确保将图表添加到演示文稿中?

```{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)
```    

1 个答案:

答案 0 :(得分:0)

好的,我能够通过重命名我的Rpres文件来解决我的问题,因此它没有任何空格。因此,我选择"PT terms for each age Strata.Rnw.Rpres"作为文件名而不是"PT_terms_plots.Rpres"。 如果您认为这可能是一个错误,请发表评论告诉我,以便我可以联系Rstudio开发人员。