3

I created a barplot with the following script in R:

bars <- c(229, 158)
shading.lines <- c(83, 83)
years <- c("1985-89", "2017")
cols1 <- c("indianred4","green4")
cols2 <- c("green4","indianred4")
barplot(bars,names.arg=years,col=cols1)
barplot(shading.lines,names.arg=NA,col=cols2,density=11,add=T)

enter image description here

Is there a way to adjust the width of the shading lines? I`d like to have them thicker in order to get the same appeareance of the shaded part in 1985-89 and 2017.

yenats
  • 531
  • 1
  • 3
  • 16
  • Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610). This will make it much easier for others to help you. – Jaap Sep 25 '17 at 09:01
  • @ Jaap: Sorry, I accidentally closed the tab while creating this question. It was then posted to stackoverflow, apparently. This was not my aim, I will post it again when edited. – yenats Sep 25 '17 at 09:10

1 Answers1

2

You can adjust the width of shading using par(lwd=...):

bars <- c(229, 158)
shading.lines <- c(83, 83)
years <- c("1985-89", "2017")
cols1 <- c("indianred4","green4")
cols2 <- c("green4","indianred4")
barplot(bars,names.arg=years,col=cols1)
# Set width of shading
par(lwd=5)
barplot(shading.lines,names.arg=NA,col=cols2,density=11,add=T)
# Set width of shading to the default value
par(lwd=1)

enter image description here

Marco Sandri
  • 23,289
  • 7
  • 54
  • 58
  • This has set the width of the box too, which is not always desired. Any solution? – Rodrigo Oct 10 '19 at 01:38
  • I've found a solution: plot separately the box and the shading lines, with `add=T` and `border=NA` for the second barplot. Use `par(lwd=5)` in between. – Rodrigo Mar 30 '20 at 01:47