Sasa88
Sasa88

Reputation: 327

error in barplot R

i use this code to reprsent my data in barplot.

m<-matrix(c(0.3266765,0.02333991,0.02654504,0.0243261,0.5162414,
            0.09647816,0.4568512,0.452532,0.3976825,0.006431235,
            0.007935491,0.004401323),ncol=4,byrow=TRUE)
colnames(m)<-c("HPI","JAC","SAL","HDI")
rownames(m)<-c("Zackary Karaté Club","American College Football","Political Blogs")
m<-as.table(m)
colors<-rainbow(4)
barplot(t(m), beside= TRUE, legend.text=colnames(m), 
        col=colors, ylab="Modularity", ylim=c(0,1))

But, my problem is in the result, i will have three barplot, i have the name in the first and third, which is the rownames of the table ,but in the second i dont' have it. can anyone helps me?? thanks

you can see the problem once you execute the code. i can't upload the image.

Upvotes: 1

Views: 485

Answers (2)

Sasa88
Sasa88

Reputation: 327

another option to the previous answers. it's to add the cex.names to the barplot command to define the size of the text. the problem was the size of the text which was big.

barplot(t(m), beside= TRUE, legend.text=colnames(m), col=colors, ylab="Modularity", ylim=c(0,1), cex.names=0.75)

Upvotes: 0

fishtank
fishtank

Reputation: 3728

If you resize the plot window large enough, the labels should appear.

  • Use dev.size() to get the size of your plot window.
  • x11(width=10,height=10) will start a window of the specified size (for X window server).

Otherwise, you may want to consider using custom labels. See xaxt option in plot and the axis commands.

Upvotes: 1

Related Questions