使用ggplot绘制时导入库存数据问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用ggplot绘制时导入库存数据问题相关的知识,希望对你有一定的参考价值。

我一直试图导入这个雅虎财务代码并使用ggplot绘制它,但每当我尝试这样做时,x轴显示多行(如下所示)。另外,如附图所示,我不确定为什么日期会以这种方式出现。谢谢

这是代码

axdata <- read.csv("AXJO.csv")

axdata$Date <- as.Date(axdata$Date)

plt <- ggplot(axdata, aes(x =Date, y = axdata$Close))

这是数据。我保留了所有重要的细节,但删除了大量的价格数据和日期,以保持字符数限制。

> dput(axdata)
structure(list(Date = structure(1:269, .Label = c("2017-10-30", 
"2017-10-31", "2017-11-01", "2017-11-02", "2017-11-05", "2017-11-06", 
"2017-11-07", "2017-11-08", "2017-11-09", "2017-11-12", "2017-11-13", 
, "2018-11-07", "2018-11-08", "2018-11-11", "2018-11-12", "2018-11-13", 
"2018-11-14", "2018-11-15", "2018-11-18", "2018-11-19", "2018-11-20"), 
class = "factor"), 
Open = structure(c(259L, 52L, 63L, 58L, 81L, 78L, 114L, 119L, 
139L, 127L, 121L, 84L, 59L, 71L, 79L, 73L, 83L, 96L, 96L, 
91L, 97L, 93L, 109L, 85L, 98L, 95L, 87L, 73L, 90L, 101L, 
105L, 112L, 121L, 110L, 104L, 133L, 156L, 158L, 147L, 152L, 
153L, 162L, 150L, 148L, 155L, 159L, 178L, 181L, 183L, 167L, 
151L, 154L, 159L, 138L, 117L, 115L, 108L, 100L, 130L, 144L, 
141L, 157L, 122L, 132L, 163L, 177L, 126L, 26L, 41L, 45L, 
28L, 20L, 35L, 30L, 52L, 50L, 68L, 66L, 72L, 76L, 106L, 136L, 
145L, 118L, 88L, 46L, 46L, 82L, 49L, 70L, 86L, 103L, 89L, 
60L, 54L, 74L, 80L, 61L, 75L, 62L, 20L, 15L, 25L, 14L, 10L, 
9L, 11L, 13L, 12L, 17L, 36L, 21L, 18L, 23L, 31L, 32L, 37L, 
42L, 38L, 44L, 55L, 53L, 77L, 92L, 116L, 142L, 169L, 149L, 
160L, 164L, 174L, 176L, 175L, 182L, 168L, 173L, 166L, 161L, 
160L, 135L, 128L, 131L, 129L, 107L, 113L, 94L, 111L, 99L, 
125L, 102L, 124L, 146L, 137L, 143L, 123L, 120L, 165L, 172L, 
171L, 192L, 218L, 215L, 211L, 207L, 206L, 212L, 205L, 196L, 
210L, 199L, 213L, 237L, 245L, 229L, 214L, 234L, 233L, 221L, 
208L, 224L, 230L, 244L, 216L, 231L, 226L, 223L, 247L, 241L, 
242L, 239L, 220L, 219L, 238L, 228L, 235L, 248L, 240L, 227L, 
249L, 254L, 253L, 255L, 256L, 243L, 232L, 222L, 225L, 236L, 
250L, 258L, 257L, 252L, 251L, 246L, 217L, 187L, 185L, 184L, 
197L, 193L, 180L, 189L, 200L, 188L, 203L, 190L, 205L, 202L, 
201L, 204L, 198L, 209L, 191L, 179L, 186L, 194L, 195L, 170L, 
134L, 140L, 43L, 47L, 39L, 39L, 64L, 69L, 65L, 51L, 33L, 
22L, 1L, 2L, 5L, 16L, 24L, 29L, 34L, 19L, 40L, 48L, 57L, 
56L, 67L, 27L, 7L, 8L, 6L, 4L, 3L),
 .Label = c("5664.100098", 
"5665.200195", "5671.799805", "5693.700195", "5728.200195", 
"5730.600098", "5732.799805", "5736.000000", "5751.899902", 
"5759.399902", "5761.399902", "5788.700195", "5788.799805", 
"5789.500000", "5790.500000", "5805.100098", "5808.700195", 
"5815.500000", "5818.100098", "5820.700195", "5828.700195", 
"5829.000000", "5829.100098", "5830.299805", "5832.299805", 
"5833.299805", "5834.200195", "5838.000000", "5840.799805", 
"5841.200195", "5841.299805", "5841.500000", "5843.100098", 
"5849.200195", "5855.899902", "5857.000000", "5861.399902", 
"5868.799805", "5869.899902", "5875.200195", "5876.799805", 
"5881.000000", "5883.799805", "5886.000000", "5890.700195", 
"5895.000000", "5895.700195", "5896.899902", "5902.000000", 
"6094.299805", "6096.700195", "6097.799805", "6098.299805", 
"6100.299805", "6102.100098", "6104.100098", "6107.000000", 
"6108.000000", "6116.200195", "6118.700195", "6121.399902", 
"6122.299805", "6126.200195", "6128.700195", "6130.399902", 
"6135.299805", "6135.799805", "6141.700195", "6143.799805", 
"6146.100098", "6160.399902", "6161.500000", "6165.299805", 
"6169.500000", "6172.299805", "6172.600098", "6175.899902", 
"6176.299805", "6177.399902", "6177.799805", "6179.700195", 
"6181.200195", "6183.399902", "6185.000000", "6185.899902", 
"6186.899902", "6190.000000", "6192.299805", "6194.600098", 
"6195.899902", "6197.600098", "6203.600098", "6207.600098", 
"6210.200195", "6210.399902", "6215.399902", "6215.500000", 
.899902", "6286.000000", "6293.100098", "6297.000000", 
"6297.700195","6299.600098", 
"6304.700195", "6310.899902", "6319.500000", "6328.299805", 
"6329.000000", "6338.399902", "6345.000000", "6351.799805", 
"6352.200195", "null"), class = "factor"), High = structure(c(260L, 
62L, 70L, 74L, 73L, 104L, 108L, 132L, 130L, 116L, 106L, 75L, 
64L, 82L, 66L, 76L, 90L, 86L, 86L, 94L, 93L, 117L, 95L, 97L, 
91L, 85L, 77L, 87L, 99L, 101L, 102L, 114L, 127L, 96L, 124L, 
146L, 150L, 147L, 153L, 157L, 154L, 156L, 143L, 148L, 163L, 
173L, 177L, 181L, 182L, 160L, 152L, 164L, 145L, 129L, 120L, 
115L, 105L, 125L, 141L, 135L, 155L, 144L, 128L, 158L, 172L, 
172L, 113L, 52L, 38L, 37L, 22L, 28L, 32L, 45L, 51L, 61L, 
57L, 65L, 78L, 92L, 126L, 149L, 137L, 103L, 79L, 69L, 83L, 
71L, 60L, 81L, 112L, 89L, 80L, 48L, 63L, 84L, 68L, 72L, 67L, 
50L, 15L, 20L, 18L, 11L, 9L, 8L, 13L, 10L, 14L, 27L, 29L, 
21L, 23L, 31L, 33L, 30L, 42L, 36L, 39L, 46L, 53L, 64L, 88L, 
107L, 133L, 165L, 165L, 166L, 168L, 169L, 178L, 176L, 175L, 
179L, 174L, 171L, 167L, 159L, 151L, 136L, 123L, 122L, 118L, 
110L, 100L, 109L, 98L, 121L, 111L, 112L, 142L, 139L, 140L, 
 34L, 
24L, 26L, 34L, 41L, 49L, 47L, 56L, 56L, 19L, 6L, 7L, 4L, 
2L, 1L), .Label = c("5671.799805", "5693.700195", "5700.200195", 
"5731.299805", "5737.600098", "5753.500000", "5757.899902", 
"5764.299805", "5766.000000", "5799.200195", "5804.299805", 
"5805.100098", "5806.000000", "5816.600098", "5820.700195", 
"5829.000000", "5830.299805", "5832.299805", "5837.299805", 
"5837.500000", "5837.899902", "5840.500000", "5844.700195", 
"5849.200195", "5857.100098", "5857.399902", "5857.799805", 
"5860.200195", "5864.000000", "5864.799805", "5867.600098", 
"5868.100098", "5871.100098", "5877.200195", "5884.700195", 
"5887.000000", "5890.700195", "5893.600098", "5894.700195", 
05", 
"6313.600098", "6314.899902", "6318.899902", "6329.000000", 
"6331.000000", "6333.700195", "6345.399902", "6348.100098", 
"6352.200195", "6355.200195", "6358.000000", "6373.500000", 
"null"), 
class = "factor"), Low = structure(c(263L, 67L, 
79L, 80L, 90L, 96L, 121L, 136L, 139L, 129L, 97L, 82L, 73L, 
86L, 76L, 88L, 100L, 99L, 95L, 107L, 105L, 111L, 92L, 102L, 
109L, 91L, 84L, 87L, 106L, 114L, 123L, 126L, 130L, 113L, 
122L, 149L, 159L, 158L, 160L, 166L, 163L, 156L, 146L, 161L, 
165L, 169L, 186L, 191L, 177L, 157L, 164L, 167L, 152L, 133L, 
135L, 125L, 116L, 116L, 147L, 144L, 154L, 137L, 117L, 148L, 
171L, 134L, 24L, 39L, 41L, 20L, 23L, 29L, 38L, 42L, 64L, 
57L, 70L, 74L, 78L, 94L, 124L, 153L, 132L, 98L, 63L, 58L, 
58L, 59L, 60L, 85L, 103L, 93L, 77L, 66L, 75L, 81L, 72L, 83L, 
68L, 27L, 17L, 22L, 18L, 13L, 9L, 12L, 14L, 15L, 16L, 19L, 
36L, 26L, 30L, 37L, 43L, 44L, 48L, 49L, 50L, 52L, 65L, 69L, 
89L, 108L, 128L, 155L, 162L, 163L, 174L, 173L, 182L, 184L, 
L, 212L, 198L, 
185L, 188L, 194L, 199L, 179L, 145L, 140L, 54L, 47L, 25L, 
40L, 51L, 71L, 53L, 56L, 45L, 33L, 4L, 2L, 5L, 8L, 21L, 34L, 
28L, 31L, 32L, 46L, 62L, 61L, 55L, 35L, 11L, 7L, 10L, 6L, 
3L, 1L), .Label = c("5594.000000", "5624.600098", "5635.500000", 
"5664.100098", "5665.200195", "5682.399902", "5686.799805", 
66.799805", 
"6167.700195", "6169.500000", "6172.600098", "6174.399902", 
"6177.500000", "6177.799805", "6178.399902", "6179.799805", 
"6181.200195", "6182.000000", "6182.500000", "6189.399902", 
"6194.600098", "6199.899902", "6203.600098", "6204.299805", 
"6209.600098", "6209.899902", "6214.500000", "6215.500000", 
"6217.000000", "6224.899902", "6227.600098", "6230.399902", 
"6230.899902", "6231.200195", "6234.799805", "6235.500000", 
"6238.000000", "6239.600098", "6239.700195", "6240.899902", 
"6242.500000", "6243.100098", "6244.399902", "6244.500000", 
"6248.799805", "6251.100098", "6252.200195", "6253.899902", 
"6254.799805", "6257.899902", "6258.399902", "6260.000000", 
"6268.899902", "6269.100098", "6271.899902", "6272.299805", 
"6274.700195", "6275.899902", "6276.299805", "6277.399902", 
"6282.399902", "6303.000000", "6310.899902", "6316.600098", 
"6319.500000", "6338.399902", "6348.200195", "null"), class = "factor"), 
Close = structure(c(263L, 65L, 60L, 85L, 81L, 119L, 124L, 
144L, 132L, 126L, 90L, 61L, 73L, 82L, 75L, 89L, 101L, 86L, 
96L, 102L, 98L, 114L, 91L, 103L, 100L, 92L, 76L, 95L, 106L, 
110L, 117L, 126L, 115L, 109L, 138L, 161L, 163L, 152L, 157L, 
158L, 167L, 155L, 153L, 160L, 164L, 183L, 186L, 188L, 172L, 
156L, 159L, 164L, 143L, 122L, 120L, 113L, 105L, 135L, 149L, 
146L, 162L, 127L, 137L, 168L, 182L, 131L, 27L, 43L, 47L, 
30L, 21L, 37L, 32L, 53L, 51L, 70L, 68L, 74L, 79L, 111L, 141L, 
150L, 123L, 93L, 59L, 84L, 87L, 50L, 72L, 88L, 108L, 94L, 
62L, 55L, 77L, 83L, 63L, 78L, 64L, 21L, 16L, 26L, 15L, 11L, 
10L, 12L, 14L, 13L, 18L, 38L, 22L, 19L, 24L, 33L, 34L, 39L, 
44L, 40L, 46L, 56L, 54L, 80L, 97L, 121L, 147L, 174L, 154L, 
165L, 169L, 179L, 181L, 180L, 187L, 173L, 178L, 171L, 166L, 
165L, 140L, 133L, 136L, 134L, 112L, 118L, 99L, 116L, 104L, 
130L, 107L, 129L, 151L, 142L, 148L, 128L, 125L, 170L, 177L, 
176L, 197L, 223L, 220L, 216L, 212L, 211L, 217L, 210L, 200L, 
215L, 203L, 218L, 242L, 249L, 234L, 219L, 238L, 239L, 226L, 
213L, 229L, 235L, 248L, 221L, 236L, 231L, 228L, 253L, 245L, 
246L, 244L, 225L, 224L, 243L, 233L, 240L, 251L, 245L, 232L, 
252L, 258L, 257L, 259L, 260L, 247L, 237L, 227L, 230L, 241L, 
254L, 262L, 261L, 256L, 255L, 250L, 222L, 192L, 190L, 189L, 
201L, 198L, 185L, 194L, 204L, 193L, 208L, 195L, 210L, 207L, 
206L, 209L, 202L, 214L, 196L, 184L, 191L, 199L, 205L, 175L, 
139L, 145L, 45L, 48L, 29L, 41L, 66L, 71L, 67L, 52L, 35L, 
23L, 2L, 3L, 6L, 17L, 25L, 31L, 36L, 20L, 42L, 49L, 58L, 
57L, 69L, 28L, 8L, 9L, 7L, 5L, 4L, 1L), .Label = c("5642.799805", 
"5664.100098", "5665.200195", "5671.799805", "5693.700195", 
"5728.200195", "5730.600098", "5732.799805", "5736.000000", 
"5751.899902", "5759.399902", "5761.399902", "5788.700195", 
"5788.799805", "5789.500000", "5790.500000", "5805.100098", 
"5808.700195", "5815.500000", "5818.100098", "5820.700195", 
"5828.700195", "5829.000000", "5829.100098", "5830.299805", 
"5832.299805", "5833.299805", "5834.200195", "5837.100098", 
"
"5939.100098", "5939.500000", "5940.899902", "5941.299805", 
"5941.600098", "5942.399902", "5942.899902", "5943.500000", 
"5943.700195", "5945.700195", "5946.100098", "5949.399902", 
"5950.299805", "5950.899902", "5953.600098", "5953.799805", 
"5957.299805", "5959.399902", "5959.500000", "5959.899902", 
"5960.600098", "5962.399902", "5963.200195", "5963.500000", 
"5966.000000", "5969.899902", "5971.700195", "5973.299805", 
"5974.700195", "5977.700195", "5982.600098", "5982.700195", 
"5984.299805", "5984.700195", "5985.600098", "5986.399902", 
"5988.799805", "5989.799805", "5990.399902", "5991.899902", 
"5994.399902", "5994.899902", "5996.100098", "5997.000000", 
"5998.299805", "5999.799805", "6004.000000", "6005.799805", 
"6011.100098", "6011.299805", "6011.899902", "6013.200195", 
"6013.600098", "6014.299805", "6014.600098", "6015.200195", 
"6015.799805", "6016.000000", "6016.299805", "6016.600098", 
"6021.799805", "6022.799805", "6023.500000", "6025.100098", 
"6025.500000", "6026.200195", "6029.399902", "6032.500000", 
"6032.799805", "6037.000000", "6037.100098", "6037.700195", 
"6038.899902", "6041.100098", "6041.899902", "6042.200195", 
"6045.200195", "6048.600098", "6049.399902", "6049.799805", 
"6050.000000", "6050.200195", "6054.399902", "6054.700195", 
"6056.899902", "6057.299805", "6060.399902", "6061.299805", 
"6062.899902", "6065.100098", "6067.600098", "6069.700195", 
"6069.899902", "6070.100098", "6070.399902", "6071.799805", 
"6075.399902", "6075.600098", "6077.100098", "6084.500000", 
"6087.399902", "6088.100098", "6090.100098", "6091.899902", 
"6094.000000", "6094.299805", "6096.700195", "6097.799805", 
"6098.299805", "6100.299805", "6102.100098", "6104.100098", 
"6107.000000", "6108.000000", "6116.200195", "6118.700195", 
"6121.399902", "6122.299805", "6126.200195", "6128.700195", 
"6130.399902", "6135.299805", "6135.799805", "6141.700195", 
"6143.799805", "6146.100098", "6160.399902", "6161.500000", 
"6165.299805", "6169.500000", "6172.299805", "6172.600098", 
"6175.899902", "6176.299805", "6177.799805", "6179.700195", 
"6181.200195", "6183.399902", "6185.000000", "6185.500000", 
"6185.899902", "6186.899902", "6190.000000", "6192.299805", 
"6194.600098", "6195.899902", "6197.600098", "6203.600098", 
"6207.600098", "6210.200195", "6210.399902", "6215.399902", 
"6215.500000", "6215.600098", "6225.200195", "6227.600098", 
"6230.399902", "6232.100098", "6234.799805", "6240.899902", 
"6241.500000", "6244.399902", "6244.500000", "6245.100098", 
"6247.299805", "6247.600098", "6252.200195", "6253.899902", 
"6258.100098", "6262.700195", "6265.799805", "6266.000000", 
"6268.299805", "6268.399902", "6268.500000", "6268.899902", 
"6272.299805", "6273.000000", "6275.700195", "6278.399902", 
"6280.200195", "6284.399902", "6285.899902", "6286.000000", 
"6293.100098", "6297.700195", "6299.600098", "6300.200195", 
"6304.700195", "6310.899902", "6319.500000", "6328.299805", 
"6329.000000", "6339.200195", "6345.000000", "6351.799805", 
"6352.200195", "null"), class = "factor"), Adj.Close = structure(c(263L, 
65L, 60L, 85L, 81L, 119L, 124L, 144L, 132L, 126L, 90L, 61L, 
73L, 82L, 75L, 89L, 101L, 86L, 96L, 102L, 98L, 114L, 91L, 
103L, 100L, 92L, 76L, 95L, 106L, 110L, 117L, 126L, 115L, 
109L, 138L, 161L, 163L, 152L, 157L, 158L, 167L, 155L, 153L, 
160L, 164L, 183L, 186L, 188L, 172L, 156L, 159L, 164L, 143L, 
122L, 120L, 113L, 105L, 135L, 149L, 146L, 162L, 127L, 137L, 
168L, 182L, 131L, 27L, 43L, 47L, 30L, 21L, 37L, 32L, 53L, 
51L, 70L, 68L, 74L, 79L, 111L, 141L, 150L, 123L, 93L, 59L, 
84L, 87L, 50L, 72L, 88L, 108L, 94L, 62L, 55L, 77L, 83L, 63L, 
78L, 64L, 21L, 16L, 26L, 15L, 11L, 10L, 12L, 14L, 13L, 18L, 
38L, 22L, 19L, 24L, 33L, 34L, 39L, 44L, 40L, 46L, 56L, 54L, 
80L, 97L, 121L, 147L, 174L, 154L, 165L, 169L, 179L, 181L, 
180L, 187L, 173L, 178L, 171L, 166L, 165L, 140L, 133L, 136L, 
134L, 112L, 118L, 99L, 116L, 104L, 130L, 107L, 129L, 151L, 
142L, 148L, 128L, 125L, 170L, 177L, 176L, 197L, 223L, 220L, 
216L, 212L, 211L, 217L, 210L, 200L, 215L, 203L, 218L, 242L, 
249L, 234L, 219L, 238L, 239L, 226L, 213L, 229L, 235L, 248L, 
221L, 236L, 231L, 228L, 253L, 245L, 246L, 244L, 225L, 224L, 
243L, 233L, 240L, 251L, 245L, 232L, 252L, 258L, 257L, 259L, 
260L, 247L, 237L, 227L, 230L, 241L, 254L, 262L, 261L, 256L, 
255L, 250L, 222L, 192L, 190L, 189L, 201L, 198L, 185L, 194L, 
204L, 193L, 208L, 195L, 210L, 207L, 206L, 209L, 202L, 214L, 
196L, 184L, 191L, 199L, 205L, 175L, 139L, 145L, 45L, 48L, 
29L, 41L, 66L, 71L, 67L, 52L, 35L, 23L, 2L, 3L, 6L, 17L, 
25L, 31L, 36L, 20L, 42L, 49L, 58L, 57L, 69L, 28L, 8L, 9L, 
7L, 5L, 4L, 1L), .Label = c("5642.799805", "5664.100098", 
"5665.200195", "5671.799805", "5693.700195", "5728.200195", 
"5730.600098", "5732.799805", "5736.000000", "5751.899902", 
"5759.399902", "5761.399902", "5788.700195", "5788.799805", 
"5789.500000", "5790.500000", "5805.100098", "5808.700195", 
"5815.500000", "5818.100098", "5820.700195", "5828.700195", 
"5829.000000", "5829.100098", "5830.299805", "5832.299805", 
"5833.299805", "5834.200195", "5837.100098", "5838.000000", 
"5840.799805", "5841.200195", "5841.299805", "5841.500000", 
"5843.100098", "5849.200195", "5855.899902", "5857.000000", 
"5861.399902", "5868.799805", "5869.899902", "5875.200195", 
"5876.799805", "5881.000000", "5883.799805", "5886.000000", 
"5890.700195", "5895.700195", "5896.899902", "5902.000000", 

"6262.700195", "6265.799805", "6266.000000", "6268.299805", 
"6268.399902", "6268.500000", "6268.899902", "6272.299805", 
"6273.000000", "6275.700195", "6278.399902", "6280.200195", 
"6284.399902", "6285.899902", "6286.000000", "6293.100098", 
"6297.700195", "6299.600098", "6300.200195", "6304.700195", 
"6310.899902", "6319.500000", "6328.299805", "6329.000000", 
"6339.200195", "6345.000000", "6351.799805", "6352.200195", 
"null"), class = "factor"), Volume = structure(c(5L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 4L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c("0", 
"34463900", "78246200", "7891300", "null"), class = "factor")), class = "data.frame", row.names = c(NA, 

我会的

答案

首先,看起来您在阅读数据时遇到问题。您的所有字段都已作为字符而不是数字读入。你需要检查那里发生了什么。

其次,如果要加载yahoo数据,可以使用quantmod包。

library(quantmod)

# get the data
axdata <- getSymbols("^AXJO", from = "2018-09-01", auto.assign = FALSE)

绘制数据:

chartSeries(axdata)

或者你想在tidyquant软件包中处理整洁的数据。但是,这也安装了很多其他软件包,但你会得到一些额外的功能,如geom_candlestick,所以你可以在ggplot2中绘制股票数据。

library(tidyquant)

axdata2 <- tq_get("^AXJO", from = "2018-09-01")

axdata2 %>%
  ggplot(aes(x = date, y = close)) +
  geom_line()

以上是关于使用ggplot绘制时导入库存数据问题的主要内容,如果未能解决你的问题,请参考以下文章

将 ggplot 气泡图导入 Shiny 时出错

如何将 r ggplot 图存储为 html 代码片段

使用 ggplot 绘制绘图时,hjust 和 vjust 做了啥?

迭代地绘制ggplot中的所有列

在传单中绘制 shp 文件,在 ggplot 中工作

用单独的线型在 ggplot2 中绘制缺失值