﻿ r - Round max of the axis / barplot and hist - DeveloperSite- developersite.org

# r - Round max of the axis / barplot and hist

Keywords：r

Question:

I have a large quantity of graphs to produce and I would like to get an automatized script to produce most of them.

I use barplot and hit in R. With the graphic parameters breaks,xaxp/yaxp and xlim/ylim, I would like to have automatic values:

• for breaks: I want breaks to divide the X-axis every 100 (one bar for 0-100, the other one for 100-200, etc.)
• xaxp and ylim: I would like to have the max value rounded at the next hundreds, and the axis labels every 100 with labels and ticks.
• xlim/ylim: I am searching how to get the max value rounded at the next 5 multiples, and I want to have labels and ticks every 5.

Edit: I found the solution:

``````ry<-round(max(g4\$density),digit=-1)
ry
t<-pretty((table\$col1), max(table\$col1)/500)
t
plot(g4,freq=F, axe=F, col=c("gray"), main="", xlab=NA , ylab=NA, ylim=c(0,ry),xlim=c(0,max(t)))
plot(g4,freq=F, axe=F, col=c("gray"), main="", xlab=NA , ylab=NA, ylim=c(0,ry),xlim=c(0,max(t)))
axis(1,xaxp=c(0,max(t),max(t)/500), line=-0.7, xlim=c(0,t))
axis(2,yaxp=c(0,ry,ry/5), line=-0.9, las=2)
``````

``````ry<-round(max(g4\$density),digit=-1) ry