Hi R-users,

I'm new to R and I'm trying to make a barplot combined with two lines
(refering to secondary y-axis). Bars should represent the number of
transfused patients by age class and sex and lines should represent
the amount of blood units given in age classes. I have now successfully made
a barplot and used par(new=TRUE) to plot another empty graph at the top of
the barplot.

#tab-table:
#        ikar_new
#sp       0-9 10-19 20-29 30-39 40-49 50-59 60-69 70-79 >80
#  mies   227    93    79    92   195   451   560   577 132
#  nainen 183    80   102   175    99   161   230   357 164

barplot(tab,
        beside=TRUE,
        col = c("black", "lightgrey"),
        legend = rownames(tab),
        ylim= c(0,800),
        font.main = 4,
        cex.names = 1.1,
        main = "Transfused patients and trombocytes given by age and sex",
        ylab="Number of transfused patients",
        xlab="Age groups (years)")

axis(1, c(0,3.5+3*0:9), labels=FALSE, tick=TRUE)

par(new=TRUE)

#temp-table
#  ikar_new mies nainen
#1      0-9 2296   2224
#2    10-19 1648   3508
#3    20-29 2276   1464
#4    30-39 1920   2600
#5    40-49 3912   2020
#6    50-59 6856   2872
#7    60-69 8748   3592
#8    70-79 7052   4916
#9      >80 1436   1780


plot(temp$mies, type="n", yaxt='n', xaxt='n', ann=FALSE)
lines(temp$mies, col="blue", lwd=2)
lines(temp$nainen, col="red", lwd=2)
axis(4, at=NULL)

I have used lines() to draw the lines into the picture. How can I get the
lines into the same x-axis and get the actual data points of the lines to
be exactly in between the two barplot's bars (categories in x-axis)? Now the
points which the lines connect are not in the middle of the groups in x-axis
as I would want them to be. The bars in the barplot are not stacked. I'm
sorry that I'm not able to give you the scripts to make those tables.

Thanks in advance
Lauri Nikkinen
Lahti, Finland

        [[alternative HTML version deleted]]

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to