2021年3月31日星期三

How can I make a transition to a linear model?

From a database called "datoschile" that incorporates 6 variables, I have created a panel data called "magrupados3" that uses the variable "Periodo" as an identity variable and I have filtered the information using only "Importaciones" and "Exportaciones" variables

datos <- read.xlsx("C:\\Users\\PEDRO ANDRADE 2019\\Desktop\\Curso Betametrica\\Analisis exploratorio y automatizacion de reportes\\datoschile.xlsx",                     sheet = "Hoja1",                     detectDates = T)`    magrupados3 <- melt(datos, id.vars = "Periodo")%>%    filter(variable == "Exportaciones" | variable == "Importaciones")`  

Then with this data, I have created a graph using geom_line and geom_point and also the tendency line using geom_smooth. This is the code and the result you can see it here:

magrupados4 <- ggplot(data=magrupados3,aes(x=Periodo,y=value))+  geom_line()+geom_point()+facet_wrap(variable~.,scales = "free",ncol = 2)+  geom_smooth(method = "lm",formula= y~x,col="black",se=F)`  

Graph

enter image description here

I want to make a transition of this graph. In other words, I want that geom_line and the regression line (geom_smooth) to appear simultaneously each year(my variable that represents year in my data is called "Periodo"). Can someone help me with this?

https://stackoverflow.com/questions/66897703/how-can-i-make-a-transition-to-a-linear-model April 01, 2021 at 10:29AM

没有评论:

发表评论