Different GGplot on RMarkdown and HTML File

Hello,

I am asking for help in terms of fixing a problem on my ggplots; I had never faced this issue before, so I was wondering what it might be.

My ggplot on the RMarkdown (this after clearing data output, restarting R, etc. to make sure everything is coherent and works) and the published html version comes out differently.

The following is what I get on my RMD:

This is what I get on my html:

I'm wondering if it has to do something with the actual line itself, but I'm not sure. I am putting the relevant ggplot code down:

``` r

test <- ggplot(PR_twoparty, aes(x=year, y=ideavoteshare, 
                                color= factor(cons_or_not))) +
  
  geom_line() +
  
  # scale_colour_manual(values = c("blue", "red")) + 
  # 
  # scale the years
  scale_x_continuous(breaks = seq(1988, 2016, by = 4),
                       labels = c("1988", "'92", "'96", "2000",
                                "'04", "'08", "'12", "'16")) +

  # scale the percentage
  scale_y_continuous(breaks = seq(10, 100, by = 10),
                       limits = c(0, 100)) +

  # add title to graph
  labs(title = "Conservative vs. Liberal Vote Share for PR Seats Nationwide",
         subtitle = "Current system started in 1996",
         caption  = "Data from Kuniaki Nemoto, Musashi University") +

  theme_classic()
#> Error in ggplot(PR_twoparty, aes(x = year, y = ideavoteshare, color = factor(cons_or_not))): could not find function "ggplot"



test
#> Error in eval(expr, envir, enclos): object 'test' not found

Created on 2020-03-06 by the reprex package (v0.3.0)


Thank you for the help!

Hi,

This is indeed a strange problem, and my first guess would be that you have variables that RMD can access but are not correctly set during knitting, but since you already cleared the output and restarted R that should have made the markdown break too...

In order for us to help you with your question, please provide us a minimal reproducible example where you provide a minimal (dummy) dataset and code that can recreate the issue. Once we have that, we can go from there. For help on creating a Reprex, see this guide:

Good luck!
PJ

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