0

the code runs fine in the rmarkdown but the line is missing when i knit.

the code :

cyclistic_v2$day_of_week <- ordered(cyclistic_v2$day_of_week, levels = c("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))

cyclistic_v2 %>%
  group_by(member_casual, day_of_week) %>%
  summarize(number_of_rides = n()) %>%
  ggplot(aes(x = day_of_week, y = number_of_rides, group = member_casual, color = member_casual)) +
  geom_line() +
  labs(title = " Number of rides per day of week for each customer type")

enter image description here

stefan
  • 90,330
  • 6
  • 25
  • 51
  • 2
    Welcome to SO! To help us to help you would you mind sharing [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. Also could you clarify what you mean by "the line is missing when I knit"? Do you get any errors or warnings? – stefan Mar 12 '22 at 21:10
  • Hi stefan ,no i don't get an error i just get a line chart without line when i knit – Anas Bensadoun Mar 13 '22 at 08:15

1 Answers1

0

Your code works fine, I reproduced your plot using the Case Study - Cyclistic Bike share (2018-2019) dataset.

Sample code:

library(dplyr)
library(ggplot2)   


cyclistic_v2 $day_of_week= factor(cyclistic_v2 $day_of_week, levels= c("Sunday","Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"))

 cyclistic_v2 %>%
      group_by(member_casual, day_of_week) %>%
      summarize(number_of_rides = n(), .groups = 'drop') %>% # 'drop' removes the group attribute and by default, it removes the last group
      ggplot(aes(x = day_of_week, y = number_of_rides, group = member_casual, color = member_casual)) +
      geom_line() +
        labs(title = " Number of rides per day of week for each customer type", x="Number of rides", y="Day of the week", color = "Rider status")+
      theme_minimal()

Plot:

enter image description here

Sample data:

202004-divvy-tripdata.zip

Rfanatic
  • 2,224
  • 1
  • 5
  • 21