R markdown problem with creating PDF file for plots

Have you tried loading dplyr at the beginning of your script? It seems the pipe operator is not being imported.

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.