[R-SIG-Finance] Save a plot
Brian G. Peterson
br|@n @end|ng |rom br@verock@com
Tue Jul 28 22:54:05 CEST 2020
The problem is that you need to open the png device, call your plots,
and then close the device. You would do the same e.g. with a pdf.
Try something like this:
##########
library(PerformanceAnalytics)
library(quantmod)
library(png)
png("plot-1.png", width=1000, height=600)
chart.CumReturns(ret,wealth.index = TRUE,legend.loc = "bottomleft",
yaxis.pct=100)
title("SP500 reval", adj = 0, line = 3, cex.main=1.25)
title("Eco", adj = 0.75, line = -22)
dev.off()
##########
On Tue, 2020-07-28 at 22:46 +0200, Pedro páramo wrote:
> Hi all I want to save a code on a png but it saves me a png with
> 0k(nothing on the plot) but I see it on R-Studio. No error is
> happening, whatshould be happening?
> Many thanks for your help
> library(PerformanceAnalytics)library(dplyr)library(tibble)library(lub
> ridate)library(PerformanceAnalytics)library(quantmod)library(ggplot2)
> library(png)library(grid)library(RCurl)
> Eurostoxx50<-getSymbols(src='yahoo',"^STOXX50E", env
> =parent.frame(),from="2019-12-31")Ibex35<-getSymbols("^IBEX", env =
> parent.frame(),from="2019-12-31")SP500<-getSymbols("^GSPC", env =
> parent.frame(),from="2019-12-31")Nasdaq<-getSymbols("^IXIC", env =
> parent.frame(),from="2019-12-30")
> ret <-
> na.omit(CalculateReturns(cbind(Cl(IBEX),Cl(STOXX50E),Cl(GSPC),Cl(IXIC
> ))) )# same as Cl(AAPL)/lag(Cl(AAPL)) -
> 1))chart.CumReturns(ret,wealth.index = TRUE,legend.loc =
> "bottomleft",yaxis.pct=100)title("SP500 reval", adj = 0, line = 3,
> cex.main=1.25)title("Eco", adj = 0.75, line = -22)png("plot-1.png",
> width=1000, height=600)
> [[alternative HTML version deleted]]
> _______________________________________________R-SIG-Finance using r-
> project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.--
> Also note that this is not the r-help list where general R questions
> should go.
I also wonder about the multiple calls to title(). chart.CumReturns has a title argument.
--
Brian G. Peterson
ph: +1.773.459.4973
im: bgpbraverock
[[alternative HTML version deleted]]
More information about the R-SIG-Finance
mailing list