【问题标题】:Labelling axis in a plot在图中标记轴
【发布时间】:2015-11-02 19:08:00
【问题描述】:

如何在 x 轴下方标记每个条形,例如,如果每个条形代表一个月,我如何在每个条形下方标出第一个月、第二个月、第三个月等。

conditiongood <- c(50,65,60,65,59) 
conditionpoor <- c(61,46,51,46,52)   
condition <- rbind(conditiongood,conditionpoor)   

layout(matrix(1:1,1,1)) 

barplot(as.matrix(condition), 
        col=c("darkblue","red"),
        xlab="month",
        ylab="subject count",
        main="Monthly condition",
        ylim=c(0, 140)) 

legend(5.25,140.1,
       c("good","poor"), 
       fill=c("darkblue","red"),
       title="condition")

【问题讨论】:

    标签: r plot


    【解决方案1】:

    你的意思是这样的? 这是基于this post。 可能有更复杂的方法可以做到这一点。

    # Barplot
    bp<-barplot(as.matrix(condition), 
            col=c("darkblue","red"),
            xlab="month",
            ylab="subject count",
            main="Monthly condition",
            ylim=c(0, 140)) 
    
    # x-axis labels
    axis(1, at = bp,
         labels=c("month 1", "month 2", "month 3", "month 4", "month 5"),
         cex.axis=1.2)
    
    # Add legend
    legend(5.25,140.1,
           c("good","poor"), 
           fill=c("darkblue","red"),
           title="condition")
    

    这会给:

    您可能想在图例的位置上做点什么,如果您要单独标记每个条,我认为没有必要指定 xlab。 我不会评论颜色的选择:)

    【讨论】:

    • 非常感谢,就是这样! :)
    猜你喜欢
    • 1970-01-01
    • 2023-03-27
    • 1970-01-01
    • 1970-01-01
    • 2014-01-25
    • 2021-12-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多