Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to plot a empty barplot?

Tags:

plot

r

I like to use it for prepare the plot, add horizontal lines and finally plot the bars. When I do it like below, R plots every thing twice and this looks not so nice. For a normal plot the equivalent I search is: plot(NULL, xlim=c(1,2), ylim=c(3,5), axes=F)

data = c(1,4,2) 
barplot(data)
abline(h=seq(0,5,1), col="red")
barplot(data, add=T)

I prefer to have a base solution.

like image 739
and-bri Avatar asked Aug 28 '17 20:08

and-bri


1 Answers

Plotting with col and border set to NA and axes = FALSE will effectively create an empty plot. Then you can add abline and actual barplot

data = c(1,4,2) 
barplot(data, col = NA, border = NA, axes = FALSE)
abline(h=0:5, col="red")
barplot(data, add = TRUE)
like image 66
d.b Avatar answered Sep 20 '22 18:09

d.b