使用 R 在图表上添加信息

发布于 2025-01-08 02:04:22 字数 1485 浏览 2 评论 0 原文

我想在我的图表上添加一些从该数据集绘制的信息:

编辑:

#data set:
day <- c(0:28)
ndied <- c(342,335,240,122,74,64,49,60,51,44,35,48,41,34,38,27,29,23,20,15,20,16,17,17,14,10,4,1,2)
pdied <- c(19.1,18.7,13.4,6.8,4.1,3.6,2.7,3.3,2.8,2.5,2.0,2.7,2.3,1.9,2.1,1.5,1.6,1.3,1.1,0.8,1.1,0.9,0.9,0.9,0.8,0.6,0.2,0.1,0.1)
pmort <- data.frame(day,ndied,pdied)
> pmort
   day ndied pdied
1    0   342  19.1
2    1   335  18.7
3    2   240  13.4
4    3   122   6.8
5    4    74   4.1
6    5    64   3.6
7    6    49   2.7
8    7    60   3.3
9    8    51   2.8
10   9    44   2.5
11  10    35   2.0
12  11    48   2.7
13  12    41   2.3
14  13    34   1.9
15  14    38   2.1
16  15    27   1.5
17  16    29   1.6
18  17    23   1.3
19  18    20   1.1
20  19    15   0.8
21  20    20   1.1
22  21    16   0.9
23  22    17   0.9
24  23    17   0.9
25  24    14   0.8
26  25    10   0.6
27  26     4   0.2
28  27     1   0.1
29  28     2   0.1

我已经整理了这个脚本,并且仍在尝试改进它,以便可以添加其余信息:

> barplot(pmort$pdied,xlab="Age(days)",ylab="Percent",xlim=c(0,28),ylim=c(0,20),legend="Mortality")

mygraph

我试图在 x 轴上插入数字 0 到 28(以天为单位的年龄),但不能,我知道这可能是简单的脚本。其次,我想沿着 x 轴在每天(0 到 28)下面添加死亡或死亡的数字(342 到 2)。

Example:

   0         1     2     3      4        5  and so on...
(N=342) (N=335) (N=240) (N=122) (N=74) (N=64)

图:

任何帮助将不胜感激。

巴兹

I would like to add some information on my graph which was plotted from this data set:

EDITTED:

#data set:
day <- c(0:28)
ndied <- c(342,335,240,122,74,64,49,60,51,44,35,48,41,34,38,27,29,23,20,15,20,16,17,17,14,10,4,1,2)
pdied <- c(19.1,18.7,13.4,6.8,4.1,3.6,2.7,3.3,2.8,2.5,2.0,2.7,2.3,1.9,2.1,1.5,1.6,1.3,1.1,0.8,1.1,0.9,0.9,0.9,0.8,0.6,0.2,0.1,0.1)
pmort <- data.frame(day,ndied,pdied)
> pmort
   day ndied pdied
1    0   342  19.1
2    1   335  18.7
3    2   240  13.4
4    3   122   6.8
5    4    74   4.1
6    5    64   3.6
7    6    49   2.7
8    7    60   3.3
9    8    51   2.8
10   9    44   2.5
11  10    35   2.0
12  11    48   2.7
13  12    41   2.3
14  13    34   1.9
15  14    38   2.1
16  15    27   1.5
17  16    29   1.6
18  17    23   1.3
19  18    20   1.1
20  19    15   0.8
21  20    20   1.1
22  21    16   0.9
23  22    17   0.9
24  23    17   0.9
25  24    14   0.8
26  25    10   0.6
27  26     4   0.2
28  27     1   0.1
29  28     2   0.1

I have put together this script and still trying to improve on it so that the rest of the information can be added:

> barplot(pmort$pdied,xlab="Age(days)",ylab="Percent",xlim=c(0,28),ylim=c(0,20),legend="Mortality")

mygraph

I am trying to insert the numbers 0 to 28 (age in days) on the x-axis but could not and I know that it could be a simple script. Secondly, I would like to add the number died or ndied (342 to 2) below each day(0 to 28) along the x-axis.

Example:

   0         1     2     3      4        5  and so on...
(N=342) (N=335) (N=240) (N=122) (N=74) (N=64)

Graph:

Any help would be appreciated.

Baz

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

思念绕指尖 2025-01-15 02:04:22

我为您提供了两种绘制信息的方法:一种在条形上方,一种在条形下方。您可以对其进行调整以满足您的需求。

barX <- barplot(pmort$pdied,xlab="Age(days)",
   ylab="Percent", names=pmort$day,
   xlim=c(0,28),ylim=c(0,20),legend="Mortality")

text(cex=.5, x=barX, y=pmort$pdied+par("cxy")[2]/2, pmort$ndied, xpd=TRUE) 

barX <- barplot(pmort$pdied,xlab="Age(days)",
   ylab="Percent", names=pmort$day,
   xlim=c(0,28),ylim=c(0,20),legend="Mortality")

text(cex=.5, x=barX, y=-.5, pmort$ndied, xpd=TRUE)

I gave you two ways to plot the info: one above the bars and one below. You can tweak it to meet your needs.

barX <- barplot(pmort$pdied,xlab="Age(days)",
   ylab="Percent", names=pmort$day,
   xlim=c(0,28),ylim=c(0,20),legend="Mortality")

text(cex=.5, x=barX, y=pmort$pdied+par("cxy")[2]/2, pmort$ndied, xpd=TRUE) 

barX <- barplot(pmort$pdied,xlab="Age(days)",
   ylab="Percent", names=pmort$day,
   xlim=c(0,28),ylim=c(0,20),legend="Mortality")

text(cex=.5, x=barX, y=-.5, pmort$ndied, xpd=TRUE)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文