Reputation: 109
I am new to R and I am trying to convert plot to ggplot.
plot(res$s, type="n", main=title)
print(lines(res$s))
res$s
output
2014-02-14 51.8460
2014-02-14 44.5080
Upvotes: 5
Views: 10069
Reputation: 3033
Using package ggplotify: https://cran.r-project.org/web/packages/ggplotify/vignettes/ggplotify.html
library(ggplotify)
res<-read.table(text="
s
\"2014-02-14 51.8460\"
\"2014-02-14 44.5080\" ", header=T)
p <- as.ggplot(function() plot(res$s, type="n", main="title") )
p
Upvotes: 10
Reputation: 2126
You cannot "convert" a graphic from base R to ggplot2. You have to replot the data. ggplot2 provides the function qplot()
that has a syntax similar to plot()
.
If you have a two column dataframe: df$x and df$y,
qplot(df$s,df$y, geom='line')
should do what you want.
Upvotes: -1