plot - r add lines or segments to barchart -


i have stacked horizontal bar chart 1 bar. want label different segments, each label respective segment begins. however, because segments narrow, labels need @ different levels , should connected bar through straight line, in example.

example bar chart

i can create barchart using barplot() , labels using mtext(..., side=3, line=1,...) cannot lines. segments() not seem work because coordinates in y-direction not funtion (or have not yet figured out coordinate system bar charts).

does have hint on how create these lines using base graphics?

## bogus data dat <- c(1,3,1,2) nb <- length(dat) ## basic barplot barplot( cbind( dat ), col=1:nb, horiz=true, ylim=c(0,0.7), wid=0.2)  ## location of vertical segments xdat <- c(0, cumsum(dat[-nb]))  ## create vector of jagged heights label placement/vertical segment ends h1 <- 0.36 h2 <- 0.4 heights <- c(h2,h1,h2,h1) segments(x0=xdat, x1=xdat, y0=rep(0.1,nb), y1=heights) text(x=xdat+0.1, y=heights, paste("segment",1:nb), adj=0) 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -