我正在使用Rstudio版本1.1.447。在使用Windows 10的Dell Latitude E5470上。我正在尝试使用R markdown和knittr以及ioslides为作业创建演示文稿。结果演示文稿具有完整的黑页而不是图表。但是,如果我在R markdown之外运行代码,那么图表会显示在Rstudio中。
这是我的代码:
```{r, echo = TRUE, include=FALSE}
library("plotly")
library("ggplot2")
library("datasets")
data("state")
x <- state.area
y <- state.x77[,1]*1000
z <- state.x77[,5]
fac <- state.division
newdf <- as.data.frame(cbind(state.area, state.x77[,1]*1000, state.x77[,5], state.division))
colnames(newdf) <- c("Area", "Population", "Murder", "Division")
p <-plot_ly(newdf,
x="Area",
y="Population",
z="Murder",
type="scatter3d",
mode="markers",
color="Division")
p
```
答案 0 :(得分:0)
尝试相同但删除{r, echo = TRUE, include=FALSE}
并将其替换为{r}
。
这是一个完整的工作答案。
---
title: "Plotly in Markdown Example"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library("plotly")
library("ggplot2")
library("datasets")
data("state")
x <- state.area
y <- state.x77[,1]*1000
z <- state.x77[,5]
fac <- state.division
```
## Plot title goes here
Awesome comments about plot output goes here:
```{r}
newdf <- as.data.frame(cbind(state.area, state.x77[,1]*1000, state.x77[,5], state.division))
colnames(newdf) <- c("Area", "Population", "Murder", "Division")
p <-plot_ly(newdf,
x="Area",
y="Population",
z="Murder",
type="scatter3d",
mode="markers",
color="Division")
p
```