Answers:
我想您会发现这会产生类似您的手绘图的效果。
data <- c(0.4, 0.7, 0.75, 0.82, 0.9)
endaxis <- c(0, 1) # endpoints of axis
datamm <- c(min(data), max(data))
boxplot(data, horizontal = TRUE, range = 0, ylim = endaxis,
axes = FALSE, col = "grey", add = FALSE)
arrows(endaxis, 1, datamm, 1, code = 1, angle = 90, length = 0.1)
valuelabels <- c(endaxis[1], round(fivenum(data)[2], digits = 2) ,
round(fivenum(data)[4], digits = 2), endaxis[2] )
text(x = valuelabels, y = c(1.05, 1.25, 1.25, 1.05), labels = valuelabels)
可能有更好的方法。您可能需要对其进行调整以适合您的ROC图,包括进行更改add = FALSE
对于独立版本,请尝试以下操作:
bxp <- boxplot(rnorm(100), horizontal=TRUE, axes=FALSE)
mtext(c("Min","Max"), side=3, at=bxp$stats[c(1,5)], line=-3)
请注意,您在致电时可以获得一些信息boxplot
,尤其是“五个数字”。
add=T
mtext
text
John Maindonald给出了一个更完整的示例(代码应在他的网站上):
完全可定制的ggplot2 boxplot ...
#bootstrap
data <- data.frame(value=rnorm(100,mean = 0.5, sd = 0.2),group=0)
#processing
metaData <- ddply(data,~group,summarise,
mean=mean(data$value),
sd=sd(data$value),
min=min(data$value),
max=max(data$value),
median=median(data$value),
Q1=0,Q3=0
)
bps <- boxplot.stats(data$value,coef=1.5)
metaData$min <- bps$stats[1] #lower wisker
metaData$max <- bps$stats[5] #upper wisker
metaData$Q1 <- bps$stats[2] # 1st Quartile
metaData$Q3 <- bps$stats[4] # 3rd Quartile
#adding outliers
out <- data.frame() #initialising storage for outliers
if(length(bps$out) > 0){
for(n in 1:length(bps$out)){
pt <-data.frame(value=bps$out[n],group=0)
out<-rbind(out,pt)
}
}
#adding labels
labels <-data.frame(value=metaData$max, label="Upper bound")
labels <-rbind(labels,data.frame(value=metaData$min, label="Lower bound"))
labels <-rbind(labels,data.frame(value=metaData$median, label="Median"))
labels <-rbind(labels,data.frame(value=metaData$Q1, label="First quartile"))
labels <-rbind(labels,data.frame(value=metaData$Q3, label="Third quartile"))
#drawing
library(ggplot2)
p <- ggplot(metaData,aes(x=group,y=mean))
p <- p + geom_segment(aes(x=c(0.1,0,0.1),y=c(0,0,1),xend=c(0,0,-0.1),yend=c(0,1,1)))
p <- p + geom_text(aes(y=c(0,1),label=c(0,1),x=0.2))
p <- p + geom_errorbar(aes(ymin=min,ymax=max),linetype = 1,width = 0.5) #main range
p <- p + geom_linerange(aes(ymin=min,ymax=max),linetype = 1,width = 0, color="white")# white line range
p <- p + geom_linerange(aes(ymin=min,ymax=max),linetype = 2) #main range dotted
p <- p + geom_crossbar(aes(y=median,,ymin=Q1,ymax=Q3),linetype = 1,fill='white') #box
if(length(out) >0) p <- p + geom_point(data=out,aes(x=group,y=value),shape=4) # drawning outliers if any
p <- p + scale_x_discrete(breaks=c(0))
p <- p + scale_y_continuous(name= "Value")
p <- p + geom_text(data=labels,aes(x=0.5,y=value,label=round(value,2)),colour="black",angle=0,hjust=0.5, vjust=0.5,size=3)
p <- p + opts(panel.background = theme_rect(fill = "white",colour = NA))
p <- p + opts(panel.grid.minor = theme_blank(), panel.grid.major = theme_blank())
p <- p + opts(axis.title.x=theme_blank())
p <- p + opts(axis.text.x = theme_blank())
p <- p + opts(axis.title.y=theme_blank())
p <- p + opts(axis.text.y = theme_blank())
p + coord_flip()
结果:
...代码可能有点难看,但工作方式正确。
这是我的解决方案实施方案。我决定不映射平均值,剩余空间不多。同样,从0到1的线似乎很奇怪。非常感谢大家。
data <- read.table("roc_average.txt")
bxp <- boxplot(data, horizontal = TRUE, range = 0, axes = FALSE, col = "grey", add = TRUE, at = 0.2, varwidth=FALSE, boxwex=0.3)
valuelabels <- c(round(fivenum(data)[2], digits = 2), round(fivenum(data)[4], digits = 2))
text(x = valuelabels, y = c(0.35, 0.35), labels = valuelabels, font = 2)
mtext(c(min(round(data, digits = 2)),max(round(data, digits = 2))), side=1, at=bxp$stats[c(1,5)], line=-3, font = 2)
pars
参数以减小其长宽比(boxwex
)和晶须的尺寸(staplewex
))。