Question

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

Was it helpful?

Solution

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)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top