Seite 1 von 1

Diagramm Y Skala Bereich festlegen Skalierung

Verfasst: Sa Mär 20, 2021 5:18 pm
von popoff_1
Hi, ich habe mir eine schöne Grafik erstellt. Nur passt mir etwas nicht. Die Y Skala passt sich immer den Daten an. Ich möchte Rstudio dazu zwingen dass es mir auf der Y Skala immer die Prozente von 0-100% anzeigt. Wie mache ich dies. Hier ist mein Code und ein Foto von der Grafik:

Code: Alles auswählen

library(PortfolioAnalytics)
library(ROI)
library(ROI.plugin.quadprog)
library(MASS)
library(dplyr)
library(caTools)
library(quantmod)
library(timeSeries)
library(astsa)
library(forecast)
library(ggplot2)

# Get risk-free rate (1 month T-Bond rate) from FRED
rf <- getSymbols('DGS1MO', src = 'FRED', auto.assign = FALSE)

# ticker for SBUX Index
ndx_symbol <- 'MA'



ndx <- getSymbols(ndx_symbol, from = "1980-01-01", auto.assign = FALSE)

str(ndx)

any(is.na(ndx))
dailyReturn

ndx_daily <- to.daily(ndx)

ndx_returns <- Return.calculate(ndx_daily$ndx.Adjusted)
ndx_returns <- ndx_returns[(-1),]
names(ndx_returns) <- 'NDX_daily'

plot.zoo(ndx_returns, main = 'NASDAQ-100 Daily Returns', xlab = 'Date')

chart.Drawdown(ndx_returns, plot.engine = "ggplot2") +
  geom_hline(yintercept = -0.2, size = 1) +
  theme_minimal() +
  theme(legend.position = "none", 
        axis.text.x = element_text(angle = 45, hjust = 1),
        plot.caption = element_text(hjust = 0, lineheight = 0.5)) +
  scale_y_continuous(labels = scales::percent)+
ggtitle("Drawdowns of Starbucks, monthly data",
          subtitle = "Black line indicates bear markets")
 
Bild

Re: Diagramm Y Skala Bereich festlegen Skalierung

Verfasst: So Mär 21, 2021 9:17 am
von EDi
Du hastbdoch schon scale_y_continuous genutzt, also solltest du es kennen. => schau dir die hilfe dazu mal an.

Re: Diagramm Y Skala Bereich festlegen Skalierung

Verfasst: So Mär 21, 2021 9:58 am
von popoff_1
Lösung:

Code: Alles auswählen

scale_y_continuous(labels = scales::percent, limits=c(-1,0))