Reputation: 400
i've got the following problem; I wrote a simple code to create some plots for a lecture, but somehow it does not add text to my plot. Thought there is neither a warning nor an error, and after searching in the internet i did not find any solution so far. Thank you in advance for your help, the code is following. A short note: Anything else of the plot works as i wish, it's just the text-line which is missing.
edit: here is the full code
libraries = c("dygraphs", "quantmod", "stringr", "ggplot2")
lapply(libraries, function(x) if (!(x %in% installed.packages())) { install.packages(x) })
lapply(libraries, library, quietly = TRUE, character.only = TRUE)
tickers = c("AMZN","GOOG", "MSFT")
end = Sys.Date()
getSymbols(tickers, from = "2017-10-01", to = end)
a = seq(1, 51, by =1)
time = index(AMZN.1)
time = time[a]
time = format(time, format = "%d.%m.")
for (i in 1:3){
assign(paste0(tickers[i], ".1"), Cl(get(tickers[i])))
}
AMZN.2 = as.numeric(AMZN.1)
GOOG.2 = as.numeric(GOOG.1)
MSFT.2 = as.numeric(MSFT.1)
abc = as.numeric(match("27.10.", time))
plot(AMZN.2, type = "l", xlab = "time", ylab = "price (USD, NASDAQ)", xaxs = "i", xaxt = "n", main = "Share price Amazon Inc. (Oct 17 - Dec 17)", sub = "qrtly results announced at oct 26th")
axis(1,a, labels = time) #a is a numeric vector, time a character vector
abline(v = abc, col = "red", lty = "dotted") #abc is a number (=20)
abline(h = 972.43, col = "red", lty = "dotted")
abline(h = 1100.95, col = "red", lty = "dotted")
text(abc, "my text here", col = "red", srt = 90) #abc see above
Upvotes: 2
Views: 4824
Reputation: 364
Running your code, it appears to me that the problem is that abc provides an x-coordinate, but a y-coordinate is not provided. Simply providing the x and y argument as
text(x=abc, y=1000, "my text here", col = "red", srt = 90)
is an example that seems to agree with my theory.
Upvotes: 3