Die*_*nne 5 graphics r ggplot2 lattice
这次讨论的后续stackexchange我试图执行下列情节
从
Cumming,G.,&Finch,S.(2005).[眼睛推理:置信区间和如何读取数据图片] [5].美国心理学家,60(2),170-180.DOI:10.1037/0003-066X.60.2.170
我有些人不喜欢双轴,但我认为这是一个合理的用途.
在我的部分尝试之下,第二个轴仍然缺失.我正在寻找更优雅的替代品,欢迎智能变化.
library(lattice)
library(latticeExtra)
d = data.frame(what=c("A","B","Difference"),
mean=c(75,105,30),
lower=c(50,80,-3),
upper = c(100,130,63))
# Convert Differences to left scale
d1 = d
d1[d1$what=="Difference",-1] = d1[d1$what=="Difference",-1]+d1[d1=="A","mean"]
segplot(what~lower+upper,centers=mean,data=d1,horizontal=FALSE,draw.bands=FALSE,
lwd=3,cex=3,ylim=c(0,NA),pch=c(16,16,17),
panel = function (x,y,z,...){
centers = list(...)$centers
panel.segplot(x,y,z,...)
panel.abline(h=centers[1:2],lty=3)
} )
## How to add the right scale, close to the last bar?
Run Code Online (Sandbox Code Playgroud)

par(mar=c(3,5,3,5))
plot(NA, xlim=c(.5,3.5), ylim=c(0, max(d$upper[1:2])), bty="l", xaxt="n", xlab="",ylab="Mean")
points(d$mean[1:2], pch=19)
segments(1,d$mean[1],5,d$mean[1],lty=2)
segments(2,d$mean[2],5,d$mean[2],lty=2)
axis(1, 1:3, d$what)
segments(1:2,d$lower[1:2],1:2,d$upper[1:2])
axis(4, seq((d$mean[1]-30),(d$mean[1]+50),by=10), seq(-30,50,by=10), las=1)
points(3,d$mean[1]+d$mean[3],pch=17, cex=1.5)
segments(3,d$lower[3]+d$lower[2],3,d$lower[3]+d$upper[2], lwd=2)
mtext("Difference", side=4, at=d$mean[1], line=3)
Run Code Online (Sandbox Code Playgroud)

| 归档时间: |
|
| 查看次数: |
897 次 |
| 最近记录: |