I'm new to RStudio and have issue with knitting a R markdown file to pdf. every time I try, I get an error of couldn't function. however when I run the code It works normally. The issue only appears when I try knitting.
Hi @Mohamed_Fergany ,
For best help you, it's necesary put more information about his problem. In this form the community could help you.
Maybe the error msm, or take a clear picture.
# Load the dataset
data("penguins")
# A draft to check the plots results
summary = penguins %>%
group_by(island) %>%
count(species)
summary
Note that every plot in the gglpot package must start with the ggplot() function
where you specify the dataset.
Bar plots can be used to show the count of each categorical value in one
variable only. If we want to used the bar plot for two variables, we use the
column chart. However it's better to use scatter plots and heat maps. Let's try
this simple column & scatter plots to see the difference.
Please assume .Rmd file is a text file. Every R code which have to be executed, has to be wrapped in so called chunks which are marked as
```{r}
```
See below. Just remove > signs, which are added by citation function.
> ---
> title: "Untitled"
> output: pdf_document
> ---
>
> ```{r setup, include=FALSE}
> knitr::opts_chunk$set(echo = TRUE)
> library(palmerpenguins)
> library(tidyverse)
> library(ggplot2)
> ```
>
> ## R Markdown
>
> This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.
>
> ```{r penguins}
> data("penguins")
>
> # A draft to check the plots results
> summary = penguins %>%
> group_by(island) %>%
> count(species)
> summary
> ```
>
> ## Including Plots
>
> You can also embed plots, for example:
>
> ```{r pressure, echo=FALSE}
> ggplot(penguins) + geom_col(mapping = aes(flipper_length_mm, body_mass_g))
> ```
Please note, that in .Rmd you can write any sentence outside chunk without # comment tag. In markdown # is used to create paragraphs and subparagraphs.
You might have loaded tidyverse interactively in your current working environment and that is why the code runs normally there but you must have in mind that when you knit an Rmd document the code gets executed in a clean environment other than the one you are currently working on so if you have not included the required library calls in your Rmd file itself, the libraries are not going to be loaded on that environment and the knitting is going to fail.