animate plot- error

Hi,

I'm trying to animate my plot but I'm getting an error. MAy some one assist please?

Indiana_cost <- tidy_tuition %>%
  filter(State == "Indiana")
ggplot(Indiana_cost,aes(x=year,y=cost)) +geom_line(color="deeppink1", size=1) +theme(text = element_text(size = 18))            # text size
Indiana_cost+transition_reveal(year)

#> Warning: Incompatible methods ("Ops.data.frame", "+.gg") for "+"
Error in Indiana_cost + transition_reveal(year) : 
  non-numeric argument to binary operator

Created on 2022-04-25 by the reprex package (v2.0.1)

Indiana_cost_df <- tidy_tuition %>%
  filter(State == "Indiana")

Indiana_cost_plot <- ggplot(Indiana_cost_df ,aes(x=year,y=cost)) +
                     geom_line(color="deeppink1", size=1) +
                     theme(text = element_text(size = 18)) 

Indiana_cost_plot+transition_reveal(year)

Thank you so much, it worked.

Is it possible to add plots of DC and VA as well in same plot. How would I do that?

Use facet_wrap or facet_grid

I tried facet_wrap but it gave an error.

Indiana_cost_df <- tidy_tuition %>%
  filter(State == "Indiana" && "DC" && "VA")
Indiana_cost_plot <- ggplot(Indiana_cost_df ,aes(x=year,y=cost)) +
                     geom_line(color="deeppink1", size=1) +
                     theme(text = element_text(size = 18))+labs(
      x = "Years", y = "Tuition Cost ",
      title = "Variation of tuition cost in IN") 
#> Error in ggplot(Indiana_cost_df, aes(x = year, y = cost)): could not find function "ggplot"
Indiana_cost_plot+transition_reveal(year)
#> Error in eval(expr, envir, enclos): object 'Indiana_cost_plot' not found
facet_wrap(~State)
#> Error in facet_wrap(~State): could not find function "facet_wrap"

Created on 2022-04-26 by the reprex package (v2.0.1)

In general errors should be addressed from top(first) to bottom(last). Therefore address could not find function ggplot

This is usually addressed by calling the library containing the functions one wants to use.
In your case library(tidyverse) will do as it contains ggplot2 library.

Aside from that, I would expect this wont work for you :

  filter(State == "Indiana" && "DC" && "VA")

because for it to succeed the value of State must be contradictory, better to use

filter(State %in% c("Indiana","DC","VA")

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.