I want to ask a question about barplot's axes:
first please see my data.
SerNo DOY Rain
1 350 0
2 351 0
3 352 0
4 353 0
5 354 0
6 355 0
7 356 0
8 357 0
9 358 0
10 359 0
11 360 0
12 361 0
13 362 0
14 363 0
15 364 0.7
16 365 2.7
17 1 0
18 2 0
19 3 0
20 4 2
21 5 0
22 6 0
23 7 0
24 8 0
25 9 0
26 10 0
27 11 0
28 12 0
29 13 0
30 14 0
31 15 0
32 16 0
33 17 1.8
34 18 0.8
35 19 10
36 20 0
37 21 0
38 22 0
39 23 0
40 24 0
41 25 0
42 26 0
43 27 0
44 28 0
45 29 0
46 30 6.5
47 31 0
48 32 0
49 33 0
50 34 0
51 35 0
52 36 5.8
53 37 0
54 38 0
55 39 0
56 40 0
57 41 0
58 42 0
59 43 0
60 44 0
61 45 0
62 46 2.9
63 47 0
64 48 0
DOY means the day of year , 1st,January is 1,and 31st December is 365/366, Rain is the total precipitation in that day ,because this time period across the year boundary, and I want to draw a plot which x is the DOY and Y axis is the rain, when using the barplot, I can't match the DOY with the corresponding col of rain here is my code
rainbar<-read.table("I:/example.txt",header=T)
rainbar
barplot(rainbar$Rain,axes=F,ylim=c(0,15))
length(rainbar$SerNo)
seq(1,length(rainbar$SerNo),1)
axis(2,seq(0,15,3),c(0,3,6,9,12,15))
axis(1,seq(1,length(rainbar$SerNo),1),rainbar$DOY)
the result likes this why can't the two data fit together? even I added a column called SerNo, and the SerNo based X axis still can't match the corresponding rain day, what is the reason? how does the barplot function define its own X axis? thank you very much
Try this instead:
mp <- barplot(rainbar$Rain,axes=F,ylim=c(0,15))
axis(1,at=mp,labels=rainbar$DOY)
axis(2,seq(0,15,3),c(0,3,6,9,12,15))
Read ?barplot
to see that the value returned from the function call is a vector of midpoints in the plot coordinate system.
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