Aishwarya Deore
Aishwarya Deore

Reputation: 21

Rmarkdown to knit html - graphs not showing

I have the following lines of code:

ggplot(data = subset(gapminder1, year %in% c(seq(1900, 1990, by = 10))), aes(x = year, y = lifeExp)) + geom_boxplot(aes(group = year))
ggplot(subset(gapminder1,country=="United States"),aes(x = year, y = lifeExp)) + geom_line()
ggplot(subset(gapminder1,country %in% c("China","India","United States","Indonesia","Brazil")) , aes(x = year, y = lifeExp)) + geom_line(aes(color=country))

The graphs show up fine in the rmd file when I run the code. However, when I knit the document the graphs do not show up (a blank graph comes up). Can anyone tell me what I could do?

Upvotes: 0

Views: 11403

Answers (1)

Artem
Artem

Reputation: 3414

Please see the code below knitted into HTML file:

---
title: "check"
author: "Artem"
output:
  html_document: default
  pdf_document: default
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)

```

## R Markdown
Check graph

```{r gapminder, echo=FALSE}
gapminder <- read.csv("https://raw.githubusercontent.com/birdsarah/pydata-nc/master/tutorial/assets/gapminder.csv", header = TRUE)
gapminder1 <- setNames(gapminder, c(c("country", "year", "lifeExp", "population", "income", "region"
)))

library(ggplot2)

gpm_sub <- subset(gapminder1, country %in% c("China","India","United States","Indonesia","Brazil"))

g1 <- ggplot(gpm_sub, aes(x = year, y = lifeExp)) +
  geom_line(aes(color=country))


gpm_sub_us <- subset(gapminder1,country=="United States")
g2 <- ggplot(gpm_sub_us,aes(x = year, y = lifeExp)) +
  geom_line()

g3 <- ggplot(gpm_sub, aes(x = year, y = lifeExp)) + 
  geom_line(aes(color=country))

library(gridExtra)
grid.arrange(g1, g2, g3, nrow = 2)

```

Output (No problems experienced).:

enter image description here

Upvotes: 2

Related Questions