X axis does not match barcode

I used the barplot () function to create a complex chart from a matrix.

The matrix looks like this:
1 0.989013 0.010987
2 0.999990 0.000010
3 0.999990 0.000010
4 0.999990 0.000010

to create a complex diagram is as follows:

barplot(t(as.matrix(x)), col=c("cyan", "black"))

The problem is that I want to create a custom x axis with ticks and labels at specific points. I used the following to create the x axis:

axis(1, at=keyindexes, labels=unique(t$V4), tck=-0.01)

where keyindexes is the vector of bar numbers where I need to have ticks and unique (t $ V4) is a vector containing a unique name for each tick.

Now the problem is that the x axis does not coincide with the area of ​​the diagram and is much shorter. Can anyone advise on how to increase the x axis?

+5
source share
2 answers

, . , barplot(). axis() x 1 10.

set.seed(1)
x<-data.frame(v1=rnorm(10),v2=rnorm(10))
barplot(t(as.matrix(x)), col=c("cyan", "black"))
axis(1,at=1:10)

enter image description here

.

, barplot() , at= .

m<-barplot(t(as.matrix(x)), col=c("cyan", "black"))
m
 [1]  0.7  1.9  3.1  4.3  5.5  6.7  7.9  9.1 10.3 11.5
axis(1, at=m,labels=1:10)

enter image description here

EDIT -

, m , , , labels=. 1., 5. 10.

m<-barplot(t(as.matrix(x)), col=c("cyan", "black"))
lab<-c("A","B","C")
axis(1, at=m[c(1,5,10)],labels=lab)

enter image description here

+15

updateusr TeachingDemos. "" . x .

0

All Articles