Please help :gganimate not generating any plot

temp<- read.csv("temp.csv")

rain$mean_ann_rain<- apply(rain[,-1], 1, function(x) mean(x, na.rm=TRUE)) # mean of rain of a year

combined_rain_temp<- cbind(rain, mean_temp) # combining datasets

long_combined<- melt(combined_rain_temp, id.vars = c("Time", "mean_ann_rain", "mean_temp"), = "Region", = "Rainfall") # from wide to long form

ggplot(long_combined, aes(x=mean_ann_rain, y= mean_temp))+ geom_point()+ labs(title = 'Year:{frame_time}',   x="Mean annual rainfall",  y="Mean annual temperature")+
  transition_time(Time)+   ease_aes('linear')+  shadow_wake(.03)

Created on 2023-06-06 with reprex v2.0.2

There is no error, the code generated the .png files, just there is no graph showing. here is small part of two datasets.

Time Temp
1951 24.22
1952 24.34
1953 24.57
1954 24.13
1955 23.97
1956 23.96
Time Andaman and Nicobar Islands Assam and Meghalaya
1951 3275.1 2613.8
1952 3079.9 2851.3
1953 2721.9 2559.9
1954 3449 2859.1
1955 3349.6 2761.2
1956 3080 2802.9

It looks like the files are not being read in.

nope, they are. I have loaded the two datasets that are required and called all the libraries, namely ggplot2, gganimate.

Okay. It's confusing though because you posted

I do not know why in reprex it shows this way, but in actual code it works just fine.

it shows that way because a reprex should be reproducible (on the computers of others ) and yours is not; as csrainfall.csv and temp.csv are not present on others computers ...

Common approaches to overcome this are to use datapasta package, or base R's dput() functionality to create representative objects of the data in R form (i.e. post read in)
so knowing that you would make rain from csvrainfall.csv, you would do that on your computer; and then use dpaste to make a textual representation of the data.frame rain, and share that.
reading csv's is presumably not your problem and can be left out of your reprex, with replacement data that is constructed from a dput output.

This is described here :

Also important :
A reprex should explicitly state the libraries/packages it relies upon , i.e. tidyverse , gganimate etc. as the code would not be expected to run without these, so they can not be omitted.


Yo, you didn't answer my actual question.

That's correct. I personally dont like to work on potentially tricky problems that arent reproducible

1 Like

Thanks for tough guidance.

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.