Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adjust R axis in plots after plot(...) and lines(...)?

Tags:

plot

r

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))

enter image description here

Now without common y -points, you cannot see them in the same plot. So how to adjust it?

like image 361
hhh Avatar asked Jan 04 '12 12:01

hhh


People also ask

How do I change the axis on an R plot?

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.

How do you change the axis thickness in R?

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.

How do you plot a line in R?

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).

Which function used for setting axis limits in any graph in R?

xlim: Set or query x-axis limits. ylim: Set or query y-axis limits.


1 Answers

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)
like image 198
Pierre Lapointe Avatar answered Oct 23 '22 11:10

Pierre Lapointe