Ggplot error - cannot knit into html

#my code is below

pkgs <- c("moments", "ggplot2", "dplyr", "tidyr", "tidyverse")
install.packages(pkgs, repos = "http://cran.us.r-project.org")

library(ggplot2)
ggplot(data= dailyActivity )+
geom_point(mapping = aes(x= TotalSteps, y=Calories ))

ggplot(data= dailyActivity )+
geom_point(mapping = aes(x= VeryActiveMinutes, y=Calories ))

ggplot(data= dailyActivity )+
geom_point(mapping = aes(x= TotalDistance, y=Calories ))

install.packages("rmarkdown")
library(markdown)

#i am getting following error while Knit into HTML. pls help

Quitting from lines 3-20 (knit.spin.Rmd)
Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> ggplot

This is because you need this dataset included in your R Markdown document.

1 Like

The first problem I see is that you shouldn't include install commands in your Rmd file, you only need to install packages once in your system, but if you include this command, you are going to be installing them every time you knit the document.

Now, about your issue, when you knit a document the code gets executed in a clean environment other than the one you are currently working on, so if you do not include the code you have used to load dailyActivity into memory, the dataset is not going to exist in the clean environment.

1 Like

hi this is the error

Quitting from lines 3-40 (knit.spin.Rmd)
Error in contrib.url(repos, "source") :
trying to use CRAN without setting a mirror
Calls: ... withVisible -> eval -> eval -> install.packages -> contri

please help now i am getting this error

  1. +-rmarkdown::render(...)
  2. | -knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  3. | -knitr:::process_file(text, output)
  4. | +-base::withCallingHandlers(...)
  5. | +-knitr:::process_group(group)
  6. | -knitr:::process_group.block(group)
  7. | -knitr:::call_block(x)
  8. | -knitr:::block_exec(params)
  9. | -knitr:::eng_r(options)
  10. | +-knitr:::in_dir(...)
  11. | -knitr:::evaluate(...)
  12. | -evaluate::evaluate(...)
  13. | -evaluate:::evaluate_call(...)
  14. | +-evaluate:::timing_fn(...)
  15. | +-base:::handle(...)
  16. | +-base::withCallingHandlers(...)
  17. | +-base::withVisible(eval(expr, envir, enclos))
  18. | -base::eval(expr, envir, enclos)
  19. | -base::eval(expr, envir, enclos)
  20. +-ggplot2::ggplot(data = dailyActivity)
  21. -ggplot2:::ggplot.function(data = dailyActivity)

Execution halted

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

1 Like
head(dailyActivity)
# A tibble: 6 x 15
        Id ActivityDate TotalSteps TotalDistance TrackerDistance LoggedActivitiesDi~
     <dbl> <chr>             <dbl>         <dbl>           <dbl>               <dbl>
1   1.50e9 04-12-2016        13162          8.5             8.5                    0
2   1.50e9 4/13/2016         10735          6.97            6.97                   0
3   1.50e9 4/14/2016         10460          6.74            6.74                   0
4   1.50e9 4/15/2016          9762          6.28            6.28                   0
5   1.50e9 4/16/2016         12669          8.16            8.16                   0
6   1.50e9 4/17/2016          9705          6.48            6.48                   0
# ... with 9 more variables: VeryActiveDistance <dbl>,
#   ModeratelyActiveDistance <dbl>, LightActiveDistance <dbl>,
#   SedentaryActiveDistance <dbl>, VeryActiveMinutes <dbl>,
#   FairlyActiveMinutes <dbl>, LightlyActiveMinutes <dbl>, SedentaryMinutes <dbl>,
#   Calories <dbl>

library(rmarkdown)
library(tidyverse)

library(ggplot2)

dailyActivity <- read.csv
joined_hourly_data<- read.csv
view(dailyActivity)
view(joined_hourly_data)
ggplot(data= dailyActivity  )+
  geom_point(mapping = aes(x= TotalSteps, y=Calories ))

ggplot(data= dailyActivity  )+
  geom_point(mapping = aes(x= VeryActiveMinutes, y=Calories ))

ggplot(data= dailyActivity  )+
  geom_point(mapping = aes(x= TotalDistance, y=Calories ))


Quitting from lines 3-22 (new-markdown.spin.Rmd) 
Error:   You're passing a function as global data.
  Have you misspelled the `data` argument in `ggplot()`
Backtrace:
     x
  1. +-rmarkdown::render(...)
  2. | \-knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  3. |   \-knitr:::process_file(text, output)
  4. |     +-base::withCallingHandlers(...)
  5. |     +-knitr:::process_group(group)
  6. |     \-knitr:::process_group.block(group)
  7. |       \-knitr:::call_block(x)
  8. |         \-knitr:::block_exec(params)
  9. |           \-knitr:::eng_r(options)
 10. |             +-knitr:::in_dir(...)
 11. |             \-knitr:::evaluate(...)
 12. |               \-evaluate::evaluate(...)
 13. |                 \-evaluate:::evaluate_call(...)
 14. |                   +-evaluate:::timing_fn(...)
 15. |                   +-base:::handle(...)
 16. |                   +-base::withCallingHandlers(...)
 17. |                   +-base::withVisible(eval(expr, envir, enclos))
 18. |                   \-base::eval(expr, envir, enclos)
 19. |                     \-base::eval(expr, envir, enclos)
 20. +-ggplot2::ggplot(data = dailyActivity)
 21. \-ggplot2:::ggplot.function(data = dailyActivity)

Execution halted

done please check if this is understandable

This is not valid R code, so you basically have the same problem as before. You need to include valid code to read your data frame into memory.

1 Like

thank you very much. Was able to knit.
I am just a beginner in this field so learning step by step.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.