I wanted to plot a animated plot using gganimate , here is the code:
library(ggplot2)
library(dplyr)
library(reshape2)
library(gganimate)
rain<-read.csv("csvrainfall.csv")
temp<- read.csv("temp.csv")
mean_temp<-temp$Temp
> #computing mean annual rain
rain$mean_ann_rain<- apply(rain[,-1], 1, function(x) mean(x, na.rm=TRUE))
> #combining the two datasets
combined_rain_temp<- cbind(rain, mean_temp)
> #transforming the data from wide to long form
long_combined<- melt(combined_rain_temp, id.vars = c("Time", "mean_ann_rain", "mean_temp"), variable.name = "Region", value.name = "Rainfall")
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)
The code is not generating any error, it also generated the .png files needed to do the job, but just plot is not getting displayed. Sample dataset:
temp <- tibble::tribble(
~Time, ~Temp,
1951L, 24.22,
1952L, 24.34,
1953L, 24.57,
1954L, 24.13,
1955L, 23.97,
1956L, 23.96,
1957L, 23.97,
1958L, 24.62,
1959L, 24.3,
1960L, 24.29
)
rain <- tibble::tribble(
~Time, ~Andaman.and.Nicobar.Islands, ~Assam.and.Meghalaya, ~Naga.Mani.Mizo.Tripura,
1951L, 3275.1, 2613.8, 2609.3,
1952L, 3079.9, 2851.3, 2810.9,
1953L, 2721.9, 2559.9, 2661.6,
1954L, 3449, 2859.1, 2905.1,
1955L, 3349.6, 2761.2, 2865,
1956L, 3080, 2802.9, 3022.7,
1957L, 2507.2, 2257.2, 2303.9,
1958L, 2807.4, 2626.4, 1968.6,
1959L, 3343.3, 2535.8, 2327.6,
1960L, 3025, 2342.2, 1799.9
)