I want to plot the wind speed at three different sites with x = date and y = wind speed.
The plot I want should basically look like this:
Except I want the full date instead of just the day on the x-axis. The graph above is just a workaround, as the code I wanted to use produces a glitch described below.
The data:
> u10
date u10.TXL u10.MF u10.THF
1 2013-05-01 2.9 2.0 3.5
2 2013-05-02 3.1 2.1 4.1
3 2013-05-03 2.8 2.0 3.4
The code I wanted to use:
plot(u10$date[month==5&year==2013],u10$u10.MF[month==5&year==2013],
type="b", col="green",
main="wind speed at three sites", ylab="wind speed [m/s]", xlab="date",
xlim=c(1,30), ylim=c(0,12),
las=0)
lines(u10$date[month==5&year==2013],u10$u10.THF[month==5&year==2013], col="red")
lines(u10$date[month==5&year==2013],u10$u10.TXL[month==5&year==2013], col="blue")
points(u10$date[month==5&year==2013],u10$u10.THF[month==5&year==2013], col="red")
points(u10$date[month==5&year==2013],u10$u10.TXL[month==5&year==2013], col="blue")
Results in the following graph:
As you can see, the first, "original" data is not plotted with standard points and a line, despite me using
type="b"
I even tried to use the "pch" command, which will just add the symbol over the "minus" sign I automatically get.
Question: Why do I have this kind of plot and why can't I change it? Is it because the date is defined as date and R just assumes the wind value for every time of the day? But why does it work for the second and third line?
The workaround seems to work, but I just wonder what I did wrong. Also, I didn't find out how to add the full date with the workaround solution.
Thanks in advance for any help
PS:Here is the code I used for the workaround:
plot(u10$date[month==5&year==2013],NULL,
type="p", pch="",
main="wind speed at three sites", ylab="wind speed [m/s]", xlab="date",
xlim=c(1,30), ylim=c(0,12),
las=0)
lines(u10$date[month==5&year==2013],u10$u10.MF[month==5&year==2013], col="green")
lines(u10$date[month==5&year==2013],u10$u10.THF[month==5&year==2013], col="red")
lines(u10$date[month==5&year==2013],u10$u10.TXL[month==5&year==2013], col="blue")
points(u10$date[month==5&year==2013],u10$u10.MF[month==5&year==2013], col="green")
points(u10$date[month==5&year==2013],u10$u10.THF[month==5&year==2013], col="red")
points(u10$date[month==5&year==2013],u10$u10.TXL[month==5&year==2013], col="blue")