How to show all the labels in X-axis 45 degree in R 2x2 bar plot

前端 未结 4 1550
独厮守ぢ
独厮守ぢ 2020-12-20 05:20

With the following data:

Method  Metric  E0  E1  E2  E4
Method-XXX  Precision   0.9661017   0.9622642   1   0.9655172
Method-YYY  Precision   0.533   0.535           


        
4条回答
  •  独厮守ぢ
    2020-12-20 06:15

    Here's a way to get all the labels without rotating. You plot the axis labels on two lines instead of one to avoid overlap. I've done it with a single graph to demonstrate the method.

    dat <- read.table("http://dpaste.com/1563769/plain/",header=TRUE)
    
    # Create barplot
    barplot(height=dat$E0, beside=TRUE, col=c("red","blue"))
    
    # Get x-coordinates of bars
    x.coords = barplot(height=dat$E0, beside=TRUE, plot=FALSE)
    # Create new coordinates between each pair of bars
    new.x.coords = seq(sum(x.coords)[1:2]/2, sum(x.coords)[9:10]/2, x.coords[2]-x.coords[1])
    
    # Plot axis labels, but not axis or tickmarks
    axis(side=1, at=new.x.coords[c(1,3,5)], labels=dat$Method[c(1,3,5)], line=0, tick=FALSE)
    axis(side=1, at=new.x.coords[c(2,4)], labels=dat$Method[c(2,4)], line=1, tick=FALSE)
    # Plot just axis and tickmarks, but not labels
    axis(side=1, at=new.x.coords, labels=NA)
    

提交回复
热议问题