friendly / VCDR

Visualizing categorical data with R
0 stars 0 forks source link

Fig 4.8 plot(lor_CM) now gives a barplot #31

Closed friendly closed 9 years ago

friendly commented 9 years ago

In example 4.12, the plot of log odds ratios now shows a bar plot, with connected lines. It should give a line graph. As well, the fitted quadratic model doesn't appear in the plot.

data("CoalMiners", package = "vcd")
CM <- CoalMiners[, , 2 : 9]

lor_CM <- loddsratio(CM)
plot(lor_CM)

lor_CM_df <- as.data.frame(lor_CM)
age <- seq(25, 60, by = 5) + 2
lmod <- lm(LOR ~ poly(age, 2), weights=1/ASE^2, data = lor_CM_df)
grid.lines(age, fitted(lmod), gp = gpar(col = "red"))

lor-cm

friendly commented 9 years ago

This is more or less how the plot should appear:

plot(LOR ~ age, data=lor_CM_df, lwd=2, type="b", pch=16, cex=1.25, ylim=c(2,5))
with(lor_CM_df, arrows(age, LOR-2*ASE, age, LOR+2*ASE, angle=90, code=3, length=.1))

Ah, when in doubt, RTFM! Now need bars=FALSE

plot(lor_CM, bars=FALSE, baseline=FALSE)

There is still the problem with the fitted quadratic not showing.

davidjohannesmeyer commented 9 years ago

issue with quadratic solved with vcd rev 802, and modified code. (The real x-axis scale differs from what the labels show).