help! error in ggplot, object not found

Good day! I've been dealing with this problem for hours already. When running code chunks on R studio, the plot appears but when I want to knit it, it says: "Error in ggplot: object hotelRH.15 not found". Why is this so? When i tried doing other datasets, it knits by just stating the data. but mine does not. My codes are below:

hotelRH.15 <- dplyr::filter(hotels, hotel == "Resort Hotel" , arrival_date_year == "2015")
hotelRH.16 <- dplyr::filter(hotels, hotel == "Resort Hotel" , arrival_date_year == "2016")
hotelRH.17 <- dplyr::filter(hotels, hotel == "Resort Hotel" , arrival_date_year == "2017")
hotelCH.15 <- dplyr::filter(hotels, arrival_date_year == "2015", hotels == "City Hotel")
hotelCH.16 <- dplyr::filter(hotels, arrival_date_year == "2016", hotels == "City Hotel")
hotelCH.17 <- dplyr::filter(hotels, arrival_date_year == "2017", hotels == "City Hotel")
g <- ggplot(hotelRH.15, aes(arrival_date_month))
g + geom_bar()

When you knit an Rmd document the code gets executed on a clean environment other than your current working environment where hotelRH.15 already exists, so you have to include the code to import/create hotelRH.15

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

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.