R中Barplot中的X轴 [英] X axis in Barplot in R

查看:52
本文介绍了R中Barplot中的X轴的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想问一个关于条形图轴的问题:

I want to ask a question about barplot's axes:

请先查看我的数据.

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 表示一年中的第 1 天,1 月 1 日,12 月 31 日是 365/366,Rain 是当天的总降水量,因为这个时间段跨越了年份边界,我想画一个图x 是 DOY,Y 轴是雨,使用条形图时,我无法将 DOY 与雨的对应列匹配这是我的代码

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)

结果是这样的为什么这两个数据不能放在一起?即使我添加了一个名为SerNo的列,基于SerNo的X轴仍然无法匹配对应的下雨天,这是什么原因?barplot 函数如何定义自己的 X 轴?非常感谢

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

推荐答案

试试这个:

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

阅读 ?barplot 以查看从函数调用返回的值是绘图坐标系中的中点向量.

Read ?barplot to see that the value returned from the function call is a vector of midpoints in the plot coordinate system.

这篇关于R中Barplot中的X轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆