Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Width of shading lines without affecting border width in R

Tags:

r

bar-chart

I'd like to draw thick angled lines in R without changing the border width. Here's an example where the border width is also changed:

barplot(c(3,4,5),col="red")
par(lwd=8)
barplot(c(3,4,5),col="blue",density=5,angle=45,add=T)
par(lwd=1)

enter image description here

Here's an attempt at doing the same thing but removing the borders, however the blue then bleeds into the background, which doesn't look good either. I need to have a thin black border.:

barplot(c(3,4,5),col="red")
par(lwd=8)
barplot(c(3,4,5),col="blue",density=5,angle=45,border=NA,add=T)
par(lwd=1)

enter image description here

Any other ideas? (without using ggplot)

like image 973
CodeGuy Avatar asked Jan 24 '26 12:01

CodeGuy


1 Answers

You could use ablineclip of plotrix package

graphics.off()
x = c(3, 4, 5)
w = 2
b = barplot(x, col = "red", width = w)
par(lwd = 8)

library(plotrix)

for(i in seq_along(b)){
    for (p in seq(-(b[i] + w/2), x[i], 0.25)) {
        ablineclip(a = p, b = pi/8, x1 = b[i] - w/2,
                   x2 = b[i] + w/2, col = "blue", y1 = 0, y2 = x[i])
    }
}

enter image description here

like image 136
d.b Avatar answered Jan 27 '26 00:01

d.b



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!