create a boxplot in R that labels a box with the sample size (N)

后端 未结 5 985
囚心锁ツ
囚心锁ツ 2021-02-01 22:05

Is there a way to create a boxplot in R that will display with the box (somewhere) an \"N=(sample size)\"? The varwidth logical adjusts the width of the box on the basis of sam

5条回答
  •  说谎
    说谎 (楼主)
    2021-02-01 22:49

    To get the n on top of the bar, you could use text with the stat details provided by boxplot as follows

    b <- boxplot(xvar ~ f1, data=frame, plot=0)
    text(1:length(b$n), b$stats[5,]+1, paste("n=", b$n))
    

    The stats field of b is a matrix, each column contains the extreme of the lower whisker, the lower hinge, the median, the upper hinge and the extreme of the upper whisker for one group/plot.

提交回复
热议问题