0

I use R Markdown to build a PDF, and I use ggplot2 to plot. without hiding the code everything is right. (ChickWeight is a default dataset)

```{r}
ggplot(ChickWeight, aes(Time, weight, color = Diet)) + geom_point() + geom_path() + geom_boxplot(aes(group=Time))

``` 

enter image description here

But when I hide the code part with {r echo=FALSE} then the plot picture will be out of the box. enter image description here

I'm looking for help to solve this.

Peyman
  • 3,097
  • 5
  • 33
  • 56

1 Answers1

2

I solved it just by an ENTER! I think it is a bug from R Markdown.

The problem occurs when the code is like this, without new line after the texts:

Lorem Ipsum is simply dummy text of the printing and typesetting industry.
```{r echo=FALSE}
ggplot(ChickWeight, aes(Time, weight, color = Diet)) + geom_point() + geom_path() + geom_boxplot(aes(group=Time))
``` 

It can be solved just by putting a new line after the texts. I mean like this:

Lorem Ipsum is simply dummy text of the printing and typesetting industry.

```{r echo=FALSE}
ggplot(ChickWeight, aes(Time, weight, color = Diet)) + geom_point() + geom_path() + geom_boxplot(aes(group=Time))
``` 

Problem solved!

Peyman
  • 3,097
  • 5
  • 33
  • 56