Forest fire Project

I’m doing the Fire Analysis guided project. I wrote the code for my script, but I don’t know why it gives me an error, I’ve reviewed it a thousand times and I don’t know.

This the code:
#Libraries
library(readr)
library(dplyr)
library(ggplot2)

#Load Data
forest_fire_data <- read.csv(‘forestfires.csv’)

#Group by day
forest_fires_day <- forest_fire_data %>%
group_by(day) %>% summarise(total_fires = n())

#reordered
forest_fires_day<- forest_fires_day %>% mutate(day = factor(day, levels = c(“sun”, “mon”, “tue”, “wed”, “thu”, “fri”, “sat”)))

#Graph
ggplot2::ggplot(data = forest_fires_day) +
aes(x = day, y = total_fires) +
geom_bar(stat = ‘identity’) +
labs(title = “Fires by Day”, x = “Day”, y = “Total fires”) +
theme(panel.background = element_rect(fill = ‘white’))

Apparently the error was in ggplot, try to fix it by putting ggplot2::ggplot, however…

These are the errors:

#Group by day
forest_fires_day <- forest_fire_data %>%
group_by(day) %>%summarise(total_fires = n())
Error in forest_fire_data %>% group_by(day) %>% summarise(total_fires = n()) :
could not find function " %>%"

#reordered
forest_fire_data<- forest_fire_data %>% mutate(day = factor(day, levels = c(“sun”, “mon”, “tue”, “wed”, “thu”, “fri”, “sat”)))
Error in forest_fire_data %>% mutate(day = factor(day, levels = c(“sun”, :
could not find function " %>%"

#Graph
ggplot2::ggplot(data = forest_fire_data) +
ggplot2::aes(x = day, y = total_fires) +
ggplot2::geom_bar(stat = ‘identity’) +
ggplot2::labs(title = “Fires by Day”, x = “Day”, y = “Total fires”) +
ggplot2::theme(panel.background = ggplot2::element_rect(fill = ‘white’))
Error in FUN(X[[i]], …) : object ‘total_fires’ not found

I do not know what it could b.

Hi fabricioism,
What error were you getting before adding ggplot2 to your plot code? I copied your code and run in RStudio and it works. I only had to change the quotation marks as the string data were not rendered as string/text.

1 Like

Hello friend, I was making a very simple mistake. I was not selecting the code that was going to run. Variables are not being assigned, and the other errors that I had. I realized that last night, thanks in advance for responding and wanting to help me.

1 Like

I have the same probelm and can’t fix that part. How did you fixed it?

Hi @jin1118babymetal, welcome to the community! Could you share your code or post a link to it? That will make it easy for people to help.

1 Like