I need to recreate a chart which was produced with R and edited with Inkscape afterwards. I'd like to do as much as possible in R. This is the chart:
Some of the text labels within the chart I will add later with Inkscape. My problem lies with the ticks. I decided to got for barplot() with no axes and add them separate with axis(). As you can see there is a spacing between the bars. I just don't know how to set a spacing for the ticks on the x-axis so that they are adjusted with the bars. Right now the ticks are getting off from the center. Here is my code:
mwe <- data.frame(month=c("Dec 2007", "Jan 2008", "Feb 2008", "Mar 2008","Apr 2008","May 2008","Jun 2008"),
job_difference_in_thousands=c(70, -10, -50, -33, -149, -231, -193),
color=c("darkred","darkred","darkred","darkred","darkred","darkred","darkred"))
barplot(height=mwe$job_difference_in_thousands,
axes=F,
col=mwe$color,
border = NA,
space=0.1,
main="Grafik X_1 NEW JOBS IN THE UNITED STATES",
cex.main=0.75,
ylim=c(-800,600),
)
axis(1,pos=0, lwd.tick=0, labels=F,line=1, outer=TRUE)
axis(1,at=0:6+0.5,labels=FALSE,lwd=0,lwd.tick=1)
axis(1, at=0:6+0.5,
labels=mwe$month,
cex.axis=0.65,
lwd=0)
axis(2, at=seq(-800,600,by=200),las=2,cex.axis=0.65, lwd=0, lwd.tick=1)
Created on 2020-12-28 by the reprex package (v0.3.0)
scale_x_discrete(expand = ...)
which does exactly what you want. Even for the long run, getting yourself familiar with ggplot2 is much better because of how easy it is to use and the community around it. – Aman