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

后端 未结 5 997
囚心锁ツ
囚心锁ツ 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:54

    You can use the names parameter to write the n next to each factor name.

    If you don't want to calculate the n yourself you could use this little trick:

    # Do the boxplot but do not show it
    b <- boxplot(xvar ~ f1, data=frame, plot=0)
    # Now b$n holds the counts for each factor, we're going to write them in names
    boxplot(xvar ~ f1, data=frame, xlab="input values", names=paste(b$names, "(n=", b$n, ")"))
    

提交回复
热议问题