r - how to set the x-axis of barplot -
this has been questioned many times 1 x axis in barplot in r
however none helped me solve problem
dt<- structure(c(79l, 54l, 37l, 41l, 42l, 121l, 134l, 169l, 23l, 19l, 22l, 19l, 25l), .names = c("experi_1", "experi_2", "experi_3", "experi_4", "experi_5", "experi_6", "experi_7", "experi_8", "experi_9", "experi_10", "experi_11", "experi_12", "experi_13"))
i plot data
mydt<- barplot(dt)
if , overlay twice x-axis
axis(side=1,at=mydt[1+c(1,13)],labels=c("experi1","experi13"))
it set few of x-axis labels automatically. want manually, example mention beginning of x-axis label , end . in case experi1 , experi 13. tried understand ?axis , specially label not set costume axis label want.
parameter names.arg
of barplot
function allows custom labels way want. have give parameter vector of name same length number of bars:
for example, putting first , last:
barplot(dt, names.arg=c("experi_1", rep("", 11), "experi_13"))
another example, putting 5 labels:
barplot(dt, names.arg=c(names(dt)[1:5], rep("", 2), names(dt)[8:13]))
edit
if want put label sequence (every 5 example), can do:
lab <- rep("", length(dt)) lab[seq(1, length(dt), by=5)] <-names(dt)[seq(1, length(dt), by=5)] barplot(dt, names.arg=lab)
Comments
Post a Comment