Search code examples
rquantmod

Creating scatter plot after getSymbols


I get one time-series data using getSymbols as:

getSymbols("GM") 
hh=GM[1:10]

I try to create a scatter plot for the first two columns:

plot(hh[,1],hh[,2])

However instead of a scatter plot, I get a time-series chart for the first column.

While trying to use

plot.zoo(hh[,1],hh[,2])

I got the error Error in xy[, 2] : incorrect number of dimensions

Finally I have the very stupid way to transfer hh in to vector:

h1=drop(coredata(hh[,1]))
h2=drop(coredata(hh[,2]))
plot(h1,h2)

It works and I have the scatter chart, but I believe there should be a method to create scatter just using hh.


Solution

  • You can use ggplot2 to create a scatterplot (and a many other very easily customizable plots)

    library(ggplot2)
    
    ggplot(hh, aes(x=GM.Open, y=GM.High)) +
      geom_point()