error in making line graph with stock data

Hi! I'm trying to make a line graph about stock price.
I first search stock price using this command

library(tidyquant)
zoom2<- tq_get("ZM", get = "stock.prices", from = "2017-09-01", to = "2021-03-01")
and then, I used this to make the plot.
zoom2 %>%

  • ggplot(aes(x = date, y = price)) +
    
  • geom_line() +
    
  • labs(title = "zoom stock price", y = "stock price", x = "") + 
    
  • theme_tq()
    

However, there is an error.
data must be a data frame, or other object coercible by fortify(), not an S3 object with class uneval
Did you accidentally pass aes() to the data argument?

Could anyone give me a help?:slight_smile: Thank you in advance T T

What is the result of

str(zoom2)

str(zoom2)
tibble [469 x 8] (S3: tbl_df/tbl/data.frame)
symbol : chr [1:469] "ZM" "ZM" "ZM" "ZM" ... date : Date[1:469], format: "2019-04-18" "2019-04-22" ...
open : num [1:469] 65 61 66.9 71.4 64.7 ... high : num [1:469] 66 68.9 74.2 71.5 66.8 ...
low : num [1:469] 60.3 59.9 65.6 63.2 62.6 ... close : num [1:469] 62 65.7 69 63.2 65 ...
volume : num [1:469] 25764700 9949700 6786500 4973500 3863300 ... adjusted: num [1:469] 62 65.7 69 63.2 65 ...

This is the result..!

Could you give us a little data to work with?

E.g.:

library("tidyverse")
my_data <- tribble(
  ~v1, ~v2, ~v3,
  1, 2, 3,
  4, 5, 6
)

Hi! what kind of data do you mean?:slight_smile:
zoom2<- tq_get("ZM", get = "stock.prices", from = "2017-09-01", to = "2021-03-01")
head(zoom2)
zoom2 %>%

  • ggplot(aes(x = date, y = price)) +
    
  • geom_line() +
    
  • labs(title = "zoom stock price", y = "stock price", x = "") + 
    
  • theme_tq()
    

This is what I used. T_T

There is no variable named price in the data frame that tq_get() returns. This should work:

library(tidyquant)
library(ggplot2)

zoom2 = tq_get("ZM", get = "stock.prices", from = "2017-09-01", to = "2021-03-01")

zoom2 %>%
  ggplot(aes(x = date, y = close)) +
  geom_line() +
  labs(title = "zoom stock price", y = "stock price", x = "") + 
  theme_tq()
1 Like

https://cran.r-project.org/web/packages/tidyquant/vignettes/TQ04-charting-with-tidyquant.html
I referred to this page for making the line graph. Hope this provides more information. Thank you!

Wow thank you so much! By the way, may I know how did you checked the variable name? :smiley:

Just to see the variable names, use:

names(zoom2)

To see both the variable names and some of the values, use:

head(zoom2)

This is really the least basics of R. You may want to read an introductory book or watch a tutorial on R basics before actually doing something with R.

ok thanks so much for your help!

This topic was automatically closed 7 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.