[R-es] Plot. window error- Usando R base. Gráfico

neo er|cconch@munoz @end|ng |rom gm@||@com
Mie Sep 4 22:04:27 CEST 2019


Hola Antonio, hice algunas suposiciones para completar el código y que 
corriera ... y dibuja bien los gráficos ... te envío adjuntos los 
primeros 10 que hice para probar:

Dos detalles para que funcionara:

1. La variable INDEX SUMMARY no tiene punto en el data.frame, pero sí en 
el código, de modo que Y aparecía vacío por ese motivo.

2. En el data.frame se usa coma para el decimal, y al menos en mi compu 
tengo q usar punto ... con coma no funciona.

Este es el código:

library(data.table)
setwd("/home/neo/Desktop/Rhelp/")
eco_freedom2 <- fread("EconomicFreedom.csv")
countrylist <- eco_freedom2[["Countries"]]
i <- 1
for (i in 1:10){
     currcty <- countrylist[i]
     filename <- paste("index",currcty,".png",sep="")
     png(filename,width=800,height=600)
plot(y=eco_freedom2$SUMMARY.INDEX[eco_freedom2$Countries==currcty],x=eco_freedom2$Year[eco_freedom2$Countries==currcty], 
type="l",ylab="INDEX",xlab="YEAR",main = paste("Countries", currcty))
     dev.off()
   }



Espero te sirva,

Saludos !!

Eric.


On 04-09-19 14:52, Antonio Rodriguez Andres wrote:
> Aqui estan en formato csv,
>
> Antonio
>
> On Wed, 4 Sep 2019 at 19:19, Carlos Ortega <cof using qualityexcellence.es 
> <mailto:cof using qualityexcellence.es>> wrote:
>
>     ¿Puedes compartir los datos?...
>     No veo otra forma...
>
>     El mié., 4 sept. 2019 a las 18:54, Antonio Rodriguez Andres
>     (<antoniorodriguezandres70 using gmail.com
>     <mailto:antoniorodriguezandres70 using gmail.com>>) escribió:
>
>         No me sale error pero no me imprime la linea, ni ningun
>         gráfico por pais.
>
>         On Wed, 4 Sep 2019 at 18:42, neo <ericconchamunoz using gmail.com
>         <mailto:ericconchamunoz using gmail.com>> wrote:
>
>             podría ser el problema el tipo de dato en X y el tipo de
>             gráfico que
>             intentas hacer ?
>
>             si Year es entero y estas pidiendo que el gráfico sea tipo
>             "I", podría
>             ser que quizá eso te produce el error ?
>
>             si pruebas a cambiar X a numérico (continuo) ?
>
>             Slds,
>
>             Eric.
>
>
>
>
>             On 04-09-19 13:06, Antonio Rodriguez Andres wrote:
>             > Lo que obtengo es dim(currcty)  = NULL
>             >
>             > lo que hice es crear una lista de paises
>             >
>             > countrylist <- unique(length(eco_freedom2$Countries)
>             >
>             > Los datos son de esta forma
>             > head(eco_freedom2, 5)
>             >      Year ISO_Code Countries SUMMARY.INDEX
>             X1..Size.of.Government
>             > 641 2000      AGO    Angola            NA              NA
>             > 601 2001      AGO    Angola            NA              NA
>             > 561 2002      AGO    Angola            NA              NA
>             > 521 2003      AGO    Angola            NA              NA
>             > 481 2004      AGO    Angola            NA              NA
>             >
>             > On Wed, 4 Sep 2019 at 16:53, Carlos Ortega
>             <cof using qualityexcellence.es
>             <mailto:cof using qualityexcellence.es>> wrote:
>             >
>             >> ¿Puedes compartir los datos?..
>             >>
>             >> Otra cosa que puede ayudar es esto lo destaco en rojo.
>             >> Creo que en alguno de los casos te quedas sin datos en
>             tu data.frame.
>             >>
>             >> Con ese mensaje puedes ver justamente el tamaño de cada
>             dataframe en cada
>             >> iteración.
>             >>
>             >>
>             >> for (i in 1:length(countrylist)){
>             >>       currcty <- countrylist[i]
>             >>      * print(dim(currcty))*
>             >>      filename <- paste("index",currcty,".png",sep="")
>             >>      png(filename,width=800,height=600)
>             >>
>             >>
>             plot(y=eco_freedom3$SUMMARY.INDEX[eco_freedom3$Countries==currcty],
>             >> x=eco_freedom3$Year[eco_freedom3$Countries==currcty],
>             ylim = c(2.85, 8.20),
>             >> xlim = c(2000, 2016), type="l",
>             ylab="INDEX",xlab="YEAR", main =
>             >> paste("Countries", currcty))
>             >>      dev.off()
>             >>    }
>             >>
>             >> El mié., 4 sept. 2019 a las 14:52, Antonio Rodriguez
>             Andres (<
>             >> antoniorodriguezandres70 using gmail.com
>             <mailto:antoniorodriguezandres70 using gmail.com>>) escribió:
>             >>
>             >>> Carlos
>             >>> Al especificar los limites, no me sale ningun error,
>             aunque no consigue
>             >>> graficar, nada,
>             >>>
>             >>>
>             >>>    # Look at the time series for each country for the
>             time period, for
>             >>> instance GDPPC
>             >>>    for (i in 1:length(countrylist)){
>             >>>       currcty <- countrylist[i]
>             >>>      filename <- paste("index",currcty,".png",sep="")
>             >>>      png(filename,width=800,height=600)
>             >>>
>             >>>
>             plot(y=eco_freedom3$SUMMARY.INDEX[eco_freedom3$Countries==currcty],
>             >>> x=eco_freedom3$Year[eco_freedom3$Countries==currcty],
>             ylim = c(2.85, 8.20),
>             >>> xlim = c(2000, 2016), type="l", ylab="INDEX",xlab="YEAR",
>             >>>           main = paste("Countries", currcty))
>             >>>      dev.off()
>             >>>    }
>             >>>
>             >>> On Wed, 4 Sep 2019 at 11:57, Carlos Ortega
>             <cof using qualityexcellence.es <mailto:cof using qualityexcellence.es>>
>             >>> wrote:
>             >>>
>             >>>> Hola,
>             >>>>
>             >>>> Pon un "print(i)" en tu bucle para ver en qué
>             número/paso del bucle te
>             >>>> aparece el error.
>             >>>> Y con ese "i" haz la selección del dataframe y mira
>             que pasa.. puede que
>             >>>> para ese caso, al quitar los NAs te quedes sin datos...
>             >>>>
>             >>>> Es una forma de debugear...
>             >>>>
>             >>>> Gracias,
>             >>>> Carlos Ortega
>             >>>> www.qualityexcellence.es
>             <http://www.qualityexcellence.es>
>             >>>>
>             >>>>
>             >>>> El mié., 4 sept. 2019 a las 11:17, Antonio Rodriguez
>             Andres (<
>             >>>> antoniorodriguezandres70 using gmail.com
>             <mailto:antoniorodriguezandres70 using gmail.com>>) escribió:
>             >>>>
>             >>>>> Hola queridos usuarios de R
>             >>>>>
>             >>>>> Estoy intentando hacer un gráfico de una variable en
>             el tiempo para un
>             >>>>> conjunto de países usando R base, con el comando
>             plot. Tengo 40 países y
>             >>>>> son 15 años. Lo quiero salvar como formato png, cada
>             uno de ellos.
>             >>>>>
>             >>>>> Tengo el siguiente código,
>             >>>>>
>             >>>>> for (i in 1:length(countrylist)){
>             >>>>>      currcty <- countrylist[i]
>             >>>>>      filename <- paste("index",currcty,".png",sep="")
>             >>>>> png(filename,width=800,height=600)
>             >>>>>
>             >>>>>
>             plot(y=eco_freedom2$SUMMARY.INDEX[eco_freedom2$Countries==currcty],
>             >>>>>
>             x=eco_freedom2$Year[eco_freedom2$Countries==currcty],
>             type="l",
>             >>>>> ylab="INDEX",xlab="YEAR",
>             >>>>>           main = paste("Countries", currcty))
>             >>>>>      dev.off()
>             >>>>>    }
>             >>>>>
>             >>>>> Pero me aparece el error Error in plot.window(...) :
>             se necesitan
>             >>>>> valores
>             >>>>> finitos de 'xlim'. La variable y = SUMMARY.INDEX
>             tiene valores Nas, y es
>             >>>>> tipo numerico, y la variable x= Year es integer.
>             Entiendo que es por el
>             >>>>> problema de los NAs, por lo que da error.
>             >>>>> Si embargo al usar na.omit(dataset), y quedarnos con
>             los valores que no
>             >>>>> son
>             >>>>> NA, me sigue saliendo el mismo error
>             >>>>>
>             >>>>> Alguna idea,
>             >>>>>
>             >>>>> gracias
>             >>>>>
>             >>>>> --
>             >>>>>
>             >>>>> Member, Editorial Committee, *The Economic and
>             Labour Relations Review*
>             >>>>> (a
>             >>>>> SAGE journal)
>             >>>>>
>             >>>>> http://elr.sagepub.com/
>             >>>>>
>             >>>>> Member, Editorial Committee, African Journal of
>             Economic and Management
>             >>>>> Studies
>             >>>>>
>             >>>>>
>             >>>>>
>             http://emeraldgrouppublishing.com/products/journals/editorial_team.htm?id=ajems
>             >>>>>
>             >>>>> https://www.researchgate.net/profile/Antonio_Andres
>             (Research Gate
>             >>>>> profile)
>             >>>>>
>             >>>>>          [[alternative HTML version deleted]]
>             >>>>>
>             >>>>> _______________________________________________
>             >>>>> R-help-es mailing list
>             >>>>> R-help-es using r-project.org <mailto:R-help-es using r-project.org>
>             >>>>> https://stat.ethz.ch/mailman/listinfo/r-help-es
>             >>>>>
>             >>>>
>             >>>> --
>             >>>> Saludos,
>             >>>> Carlos Ortega
>             >>>> www.qualityexcellence.es
>             <http://www.qualityexcellence.es>
>             >>>>
>             >>>
>             >>> --
>             >>>
>             >>> Member, Editorial Committee, *The Economic and Labour
>             Relations Review* (a
>             >>> SAGE journal)
>             >>>
>             >>> http://elr.sagepub.com/
>             >>>
>             >>> Member, Editorial Committee, African Journal of
>             Economic and Management
>             >>> Studies
>             >>>
>             >>>
>             >>>
>             http://emeraldgrouppublishing.com/products/journals/editorial_team.htm?id=ajems
>             >>>
>             >>> https://www.researchgate.net/profile/Antonio_Andres
>             (Research Gate
>             >>> profile)
>             >>>
>             >>>
>             >>>
>             >> --
>             >> Saludos,
>             >> Carlos Ortega
>             >> www.qualityexcellence.es <http://www.qualityexcellence.es>
>             >>
>             >
>
>
>
>         -- 
>
>         Member, Editorial Committee, /The Economic and Labour
>         Relations Review/ (a SAGE journal)
>
>         http://elr.sagepub.com/
>
>         Member, Editorial Committee, African Journal of Economic and
>         Management Studies
>
>         http://emeraldgrouppublishing.com/products/journals/editorial_team.htm?id=ajems
>
>         https://www.researchgate.net/profile/Antonio_Andres(Research
>         Gate profile)
>
>
>
>
>     -- 
>     Saludos,
>     Carlos Ortega
>     www.qualityexcellence.es <http://www.qualityexcellence.es>
>
>
>
> -- 
>
> Member, Editorial Committee, /The Economic and Labour Relations 
> Review/ (a SAGE journal)
>
> http://elr.sagepub.com/
>
> Member, Editorial Committee, African Journal of Economic and 
> Management Studies
>
> http://emeraldgrouppublishing.com/products/journals/editorial_team.htm?id=ajems
>
> https://www.researchgate.net/profile/Antonio_Andres(Research Gate profile)
>
>

------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0001.html>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: indexAngola.png
Type: image/png
Size: 9854 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0010.png>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: indexBenin.png
Type: image/png
Size: 12520 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0011.png>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: indexBotswana.png
Type: image/png
Size: 11558 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0012.png>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: indexBurkina Faso.png
Type: image/png
Size: 11999 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0013.png>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: indexBurundi.png
Type: image/png
Size: 12089 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0014.png>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: indexCambodia.png
Type: image/png
Size: 9726 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0015.png>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: indexCameroon.png
Type: image/png
Size: 11972 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0016.png>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: indexCape Verde.png
Type: image/png
Size: 9859 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0017.png>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: indexCentral Afr. Rep..png
Type: image/png
Size: 12855 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0018.png>

------------ próxima parte ------------
A non-text attachment was scrubbed...
Name: indexChad.png
Type: image/png
Size: 12888 bytes
Desc: no disponible
URL: <https://stat.ethz.ch/pipermail/r-help-es/attachments/20190904/2faa8c97/attachment-0019.png>


Más información sobre la lista de distribución R-help-es