t and tt have common days but valuations are not even close so they do not appear in the same plot. Is there some command to adjust the axis to 0:10 in the beginning or after lines command? Some automatic way of doing it so every point appear?
t<-structure(list(as.Date.e1.V1....d..m..Y.. = structure(c(15138,
15139, 15140, 15141, 15142, 15145, 15146, 15147, 15148, 15152,
15152), class = "Date"), e1.V2 = c(2.26, 2.82, 2.89, 2.52,
2.19, 2.02, 2.85, 2.99, 2.21, 2.15, 2.22)), .Names = c("as.Date.e1.V1....d..m..Y..",
"e1.V2"), row.names = 3270:3280, class = "data.frame")
tt<-structure(list(as.Date.e2.V1....d..m..Y.. = structure(c(15135,
15138, 15139, 15140, 15141, 15142, 15145, 15146, 15147, 15148,
15152), class = "Date"), e2.V2 = c(11.29, 11.15, 11.25,
11.4, 11.68, 11.08, 9.9, 9.74, 9.46, 9.45, 9.87
)), .Names = c("as.Date.e2.V1....d..m..Y..", "e2.V2"), row.names = 195:205, class = "data.frame")
plot(t)
# How to adjust here the tt so that t and tt can be seen at the same time?
lines(tt)
I am sure about the mistake because plotting works with common valuation points:
> plot(data.frame(tt[1], log(tt[2])), type='l')
> points(data.frame(t[1], log(t[2])+1.5))
Now without common y -points, you cannot see them in the same plot. So how to adjust it?
To change the axis scales on a plot in base R Language, we can use the xlim() and ylim() functions. The xlim() and ylim() functions are convenience functions that set the limit of the x-axis and y-axis respectively.
To increase the width of axes (both X-axis and Y-axis at the same time) using ggplot2 in R, we can use theme function with axis. line argument where we can set element_line argument to a larger value.
The basic plot command Here, we use type="l" to plot a line rather than symbols, change the color to green, make the line width be 5, specify different labels for the x and y axis, and add a title (with the main argument).
xlim: Set or query x-axis limits. ylim: Set or query y-axis limits.
Building on Geek on Acid's answer, here's a general formulation that addresses the range problem.
plot(t,ylim=range(t[2],tt[2]))
lines(tt)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With