Error in plot.window(...) : invalid 'ylim' value

I've searched other threads for this error but can't figure out this issue. Each of the plot statements in the following code results in a "Error in plot.window(...) : invalid 'ylim' value" - Can someone please assist?
Thanks!

library(tidyverse)
names(file1)
library(zoo)
x=data.frame(file1)
dt= seq(as.Date("2017-08-22"),as.Date("2018-08-22"),by="days")
GAS=zoo(x,dt)
GAS
plot(GAS$G1.close, xlab='date(08-22-2017 to 08-22-2018)', ylab = 'G1.close')
plot(GAS$A1.close, xlab='date(08-22-2017 to 08-22-2018)', ylab = 'A1.close')
plot(GAS$g2.return, xlab='date(08-22-2017 to 08-22-2018)', ylab = 'g2.return')
plot(GAS$a2.return, xlab='date(08-22-2017 to 08-22-2018)', ylab = 'a2.return')

What does GAS look like?

Can you provide a reproducible example?

Hello,
a Sample of the data looks like the following:

A screenshot of the data is really not very useful. We really need some usable data.
A very simple and very effective way to supply some data is to use the dput() command.

dput(mydata)

and then simply copy the output and paste it here. If you have a very large data set then a sample should be fine. To supply us with 100 rows of your data set do

dput(head(mydata , 100))

where mydata is the name of your dataframe or tibble.

Hello,

Hope this helps:

dput(head(GAS,100))
structure(c("8/22/2017", "8/23/2017", "8/24/2017", "8/25/2017",
"8/28/2017", "8/29/2017", "8/30/2017", "8/31/2017", "9/1/2017",
"9/5/2017", "9/6/2017", "9/7/2017", "9/8/2017", "9/11/2017",
"9/12/2017", "9/13/2017", "9/14/2017", "9/15/2017", "9/18/2017",
"9/19/2017", "9/20/2017", "9/21/2017", "9/22/2017", "9/25/2017",
"9/26/2017", "9/27/2017", "9/28/2017", "9/29/2017", "10/2/2017",
"10/3/2017", "10/4/2017", "10/5/2017", "10/6/2017", "10/9/2017",
"10/10/2017", "10/11/2017", "10/12/2017", "10/13/2017", "10/16/2017",
"10/17/2017", "10/18/2017", "10/19/2017", "10/20/2017", "10/23/2017",
"10/24/2017", "10/25/2017", "10/26/2017", "10/27/2017", "10/30/2017",
"10/31/2017", "11/1/2017", "11/2/2017", "11/3/2017", "11/6/2017",
"11/7/2017", "11/8/2017", "11/9/2017", "11/10/2017", "11/13/2017",
"11/14/2017", "11/15/2017", "11/16/2017", "11/17/2017", "11/20/2017",
"11/21/2017", "11/22/2017", "11/24/2017", "11/27/2017", "11/28/2017",
"11/29/2017", "11/30/2017", "12/1/2017", "12/4/2017", "12/5/2017",
"12/6/2017", "12/7/2017", "12/8/2017", "12/11/2017", "12/12/2017",
"12/13/2017", "12/14/2017", "12/15/2017", "12/18/2017", "12/19/2017",
"12/20/2017", "12/21/2017", "12/22/2017", "12/26/2017", "12/27/2017",
"12/28/2017", "12/29/2017", "1/2/2018", "1/3/2018", "1/4/2018",
"1/5/2018", "1/8/2018", "1/9/2018", "1/10/2018", "1/11/2018",
"1/12/2018", " 924.69", " 927.00", " 921.28", " 915.89", " 913.81",
" 921.29", " 929.57", " 939.33", " 937.34", " 928.45", " 927.81",
" 935.95", " 926.50", " 929.08", " 932.07", " 935.09", " 925.11",
" 920.29", " 915.00", " 921.81", " 931.58", " 932.45", " 928.53",
" 920.97", " 924.86", " 944.49", " 949.50", " 959.11", " 953.27",
" 957.79", " 951.68", " 969.96", " 978.89", " 977.00", " 972.60",
" 989.25", " 987.83", " 989.68", " 992.00", " 992.18", " 992.81",
" 984.45", " 988.20", " 968.45", " 970.54", " 973.33", " 972.56",
"1019.27", "1017.11", "1016.64", "1025.50", "1025.58", "1032.48",
"1025.90", "1033.33", "1039.85", "1031.26", "1028.07", "1025.75",
"1026.00", "1020.91", "1032.50", "1019.09", "1018.38", "1034.49",
"1035.96", "1040.61", "1054.21", "1047.41", "1021.66", "1021.41",
"1010.17", " 998.68", "1005.15", "1018.38", "1030.93", "1037.05",
"1041.10", "1040.48", "1040.61", "1049.15", "1064.19", "1077.14",
"1070.68", "1064.95", "1063.63", "1060.12", "1056.74", "1049.37",
"1048.14", "1046.40", "1065.00", "1082.48", "1086.40", "1102.23",
"1106.94", "1106.26", "1102.61", "1105.52", "1122.26", " 966.90",
" 958.00", " 952.45", " 945.26", " 946.02", " 954.06", " 967.59",
" 980.60", " 978.25", " 965.27", " 967.80", " 979.47", " 965.90",
" 977.96", " 982.58", " 999.60", " 992.21", " 986.79", " 974.19",
" 969.86", " 973.21", " 964.65", " 955.10", " 939.79", " 938.60",
" 950.87", " 956.40", " 961.35", " 959.19", " 957.10", " 965.45",
" 980.85", " 989.58", " 990.99", " 987.20", " 995.00", "1000.93",
"1002.94", "1006.34", "1009.13", " 997.00", " 986.61", " 982.91",
" 966.30", " 975.90", " 972.91", " 972.43", "1100.95", "1110.85",
"1105.28", "1103.68", "1094.22", "1111.60", "1120.66", "1123.17",
"1132.88", "1129.13", "1125.35", "1129.17", "1136.84", "1126.69",
"1137.29", "1129.88", "1126.31", "1139.49", "1156.16", "1186.00",
"1195.83", "1193.60", "1161.27", "1176.75", "1162.35", "1133.95",
"1141.57", "1152.35", "1159.79", "1162.00", "1168.92", "1165.08",
"1164.13", "1174.26", "1179.14", "1190.58", "1187.38", "1177.62",
"1174.76", "1168.36", "1176.76", "1182.26", "1186.10", "1169.47",
"1189.01", "1204.20", "1209.59", "1229.14", "1246.87", "1252.70",
"1254.33", "1276.68", "1305.20", NA, " 0.0024981320", "-0.0061704110",
"-0.0058505710", "-0.0022710340", " 0.0081854870", " 0.0089874300",
" 0.0104994890", "-0.0021185210", "-0.0094843010", "-0.0006893360",
" 0.0087733630", "-0.0100967060", " 0.0027846920", " 0.0032182270",
" 0.0032401210", "-0.0106728140", "-0.0052101990", "-0.0057481640",
" 0.0074426210", " 0.0105987340", " 0.0009338920", "-0.0042039600",
"-0.0081419640", " 0.0042238230", " 0.0212248400", " 0.0053044610",
" 0.0101211010", "-0.0060889420", " 0.0047415300", "-0.0063792530",
" 0.0192081680", " 0.0092065580", "-0.0019307740", "-0.0045036070",
" 0.0171190870", "-0.0014354140", " 0.0018727680", " 0.0023441990",
" 0.0001814450", " 0.0006349700", "-0.0084205300", " 0.0038092340",
"-0.0199858330", " 0.0021580530", " 0.0028747290", "-0.0007911180",
" 0.0480279080", "-0.0021191980", "-0.0004620640", " 0.0087149680",
" 0.0000779678", " 0.0067279240", "-0.0063729620", " 0.0072423550",
" 0.0063097170", "-0.0082607740", "-0.0030933650", "-0.0022566030",
" 0.0002437240", "-0.0049610400", " 0.0113526440", "-0.0129878670",
"-0.0006967220", " 0.0158192280", " 0.0014209620", " 0.0044886140",
" 0.0130692350", "-0.0064502590", "-0.0245845090", "-0.0002447000",
"-0.0110043860", "-0.0113743130", " 0.0064785830", " 0.0131621950",
" 0.0123235420", " 0.0059363820", " 0.0039052380", "-0.0005955200",
" 0.0001249470", " 0.0082067620", " 0.0143353350", " 0.0121689500",
"-0.0059973270", "-0.0053518350", "-0.0012394440", "-0.0033000290",
"-0.0031883230", "-0.0069742750", "-0.0011721130", "-0.0016600750",
" 0.0177752060", " 0.0164131270", " 0.0036213550", " 0.0145710200",
" 0.0042731200", "-0.0006142440", "-0.0032994280", " 0.0026392240",
" 0.0151421860", NA, "-0.0092046990", "-0.0057933070", "-0.0075489550",
" 0.0008040220", " 0.0084987400", " 0.0141815280", " 0.0134457250",
"-0.0023964680", "-0.0132685710", " 0.0026209950", " 0.0120582590",
"-0.0138543780", " 0.0124857620", " 0.0047241140", " 0.0173217030",
"-0.0073929110", "-0.0054625980", "-0.0127686500", "-0.0044447360",
" 0.0034541450", "-0.0087956330", "-0.0099000130", "-0.0160297330",
"-0.0012662420", " 0.0130726820", " 0.0058157570", " 0.0051756080",
"-0.0022468130", "-0.0021789490", " 0.0087243090", " 0.0159510730",
" 0.0089004860", " 0.0014248200", "-0.0038244360", " 0.0079011220",
" 0.0059597920", " 0.0020081410", " 0.0033900580", " 0.0027724010",
"-0.0120202600", "-0.0104212790", "-0.0037502280", "-0.0168987860",
" 0.0099348400", "-0.0030638910", "-0.0004933450", " 0.1321637120",
" 0.0089922570", "-0.0050141310", "-0.0014475740", "-0.0085714000",
" 0.0158834650", " 0.0081504660", " 0.0022397600", " 0.0086451390",
"-0.0033101480", "-0.0033477360", " 0.0033945600", " 0.0067925310",
"-0.0089282800", " 0.0094081770", "-0.0065155180", "-0.0031595800",
" 0.0117018670", " 0.0146293900", " 0.0258095460", " 0.0082883270",
"-0.0018647970", "-0.0270860900", " 0.0133302160", "-0.0122371140",
"-0.0244332820", " 0.0067198690", " 0.0094431620", " 0.0064564270",
" 0.0019054840", " 0.0059552870", "-0.0032851590", "-0.0008153530",
" 0.0087017820", " 0.0041558130", " 0.0097019360", "-0.0026877250",
"-0.0082197860", "-0.0024286150", "-0.0054479430", " 0.0071895860",
" 0.0046738500", " 0.0032479880", "-0.0140207450", " 0.0167084570",
" 0.0127752840", " 0.0044760130", " 0.0161625420", " 0.0144247030",
" 0.0046756730", " 0.0013011930", " 0.0178183560", " 0.0223391110"
), .Dim = c(100L, 5L), .Dimnames = list(NULL, c("Date", "G1.close",
"A1.close", "g2.return", "a2.return")), index = structure(c(17400,
17401, 17402, 17403, 17404, 17405, 17406, 17407, 17408, 17409,
17410, 17411, 17412, 17413, 17414, 17415, 17416, 17417, 17418,
17419, 17420, 17421, 17422, 17423, 17424, 17425, 17426, 17427,
17428, 17429, 17430, 17431, 17432, 17433, 17434, 17435, 17436,
17437, 17438, 17439, 17440, 17441, 17442, 17443, 17444, 17445,
17446, 17447, 17448, 17449, 17450, 17451, 17452, 17453, 17454,
17455, 17456, 17457, 17458, 17459, 17460, 17461, 17462, 17463,
17464, 17465, 17466, 17467, 17468, 17469, 17470, 17471, 17472,
17473, 17474, 17475, 17476, 17477, 17478, 17479, 17480, 17481,
17482, 17483, 17484, 17485, 17486, 17487, 17488, 17489, 17490,
17491, 17492, 17493, 17494, 17495, 17496, 17497, 17498, 17499
), class = "Date"), class = "zoo")

Excellent.

Try

str(GAS)

What this show us is that you are dealing with a zoo object which is not the same thing as a data.frame or tibble. Your plot commands seem to assume you are dealing with a data.frame or tibble.

After that, I am out of my depth since I have never dealt with time-series data. I expect someone will soon be along to help.

I am sorry to be of so little help.

I haven't used zoo much, but your date format is really strange (two dates that don't match in some cases) and your numbers are being read in as characters.

> head(GAS)
           Date      G1.close A1.close g2.return     a2.return    
2017-08-22 8/22/2017  924.69   966.90  <NA>          <NA>         
2017-08-23 8/23/2017  927.00   958.00   0.0024981320 -0.0092046990
2017-08-24 8/24/2017  921.28   952.45  -0.0061704110 -0.0057933070
2017-08-25 8/25/2017  915.89   945.26  -0.0058505710 -0.0075489550
2017-08-26 8/28/2017  913.81   946.02  -0.0022710340  0.0008040220
2017-08-27 8/29/2017  921.29   954.06   0.0081854870  0.0084987400
> str(GAS)
‘zoo’ series from 2017-08-22 to 2017-11-29
  Data: chr [1:100, 1:5] "8/22/2017" "8/23/2017" "8/24/2017" "8/25/2017" "8/28/2017" "8/29/2017" "8/30/2017" "8/31/2017" "9/1/2017" ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:5] "Date" "G1.close" "A1.close" "g2.return" ...
  Index:  Date[1:100], format: "2017-08-22" "2017-08-23" "2017-08-24" "2017-08-25" "2017-08-26" "2017-08-27" "2017-08-28" "2017-08-29" "2017-08-30" ...

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.