Hello,
I am working on my first data analysis project. Currently I am trying to create a plot that would show values of daily activity compared with daily standard which is 30 hours per day. I started with creating a new data frame that would break data to below 30 and fill it with orange color, equal to 30 and fill it with yellow and above 30 which would be filled with green.
I tried to run the code and received a message below. ag is a name of a new data frame I am creating. Please advise.
Error in ggplot(data = ag, aes(x = id, y = avgactivity, fill = goal)) :
object 'ag' not found
project link here
my code:
activityvsgoal <- daily %>%
group_by(id) %>%
summarise(avgactivity = mean(active_minutes)) %>%
drop_na() %>%
select(-c(3:8))
ag <- activityvsgoal %>%
mutate(avgactivity = as.factor(avgactivity),
goal = cut (breaks = c(-Inf, 30, Inf),
labels = c('Below', 'Goal', 'Above')))
#COlour Palette
pal <- c("orange", "yellow", "green")
ggplot (data=ag, aes (x = id, y = avgactivity, fill = goal)) +
geom_col() +
coord_flip() +
scale_x_discrete(limits = rev(levels(ag$id))) +
scale_fill_manual(values = pal)+
theme(axis.text.x = element_text(angle = 45)) +
labs(title = "Daily Activity Goal", y="Active Minutes", x="ID")