1

So i prepared notebook in R and then knitted it to html. Everything was perfectly fine, but later on when i updated data, so i changed one line of code, i started to get error:

Error in ggplot(data = mydata, aes(x = fct_infreq(as.factor(worker)))): 
could not find function "ggplot" Calls: <Annonymous> ... handle
 -> withCallingHandlers -> withvisible -> eval ->eval

However, when i coppied the whole script to the notebok and created a preview it works perfeclty well, and also when i run this ggplot function separately it works.

ggplot(data = mydata, aes(x = fct_infreq(as.factor(worker)))) +
  geom_bar(width = 0.5, color = "blue") +
  labs(x ="Worker", y = "Answers") +
  geom_text(stat ='count', aes(label = ..count.., vjust =-0.5)) +
  ggtitle("Total iterations")

The question is: why knitting to HTML doesnt work for me and what i am missing here

thanks!

camille
  • 16,432
  • 18
  • 38
  • 60
M.wol
  • 901
  • 3
  • 10
  • 21

1 Answers1

1

@dario's response should do the trick (don't forget to add library(forcats) as well to get the fct_infreq() function), and is probably a better practice with ggplot2 than explicitly adding the package to every function e.g. ggplot2::ggplot(mydata, ggplot2::aes(x = forcats::fct_infreq(as.factor(worker))).

Jim Kloet
  • 440
  • 3
  • 7