在r r中使用GGPLOT打印样本大小在Boxplot边界外
我想在我的盒装上显示每个物种的样本大小,但是情节杂乱无章。有没有办法在标题(我突出显示的红色区域中使用样本尺寸)时显示图块“外部”的样本大小?
df <- data.frame(year = rep(c(2019, 2020), each = 10),
month = rep(c("March", "October"), each = 1),
site = rep(c("1", "2", "3", "4", "5"), each = 2),
type = rep(c("baitfish", "shark"), each = 1),
salinity = sample(x = 20:35, size = 20, replace = TRUE),
num = sample(x = 0:10, size = 20, replace = TRUE))
count_by_row <- data.frame(df[rep(row.names(df), df$num), 1:5])
ggplot(data=subset(count_by_row, !is.na(salinity)), aes(x = reorder(type, -salinity, FUN = median), y = salinity)) +
geom_boxplot(outlier.shape = 1, outlier.size = 2) +
coord_flip() +
xlab("") +
ylab("salinity (PSU)")
I'd like to display the sample size of each species on my boxplot, but the plot is fairly cluttered. Is there a way to display the sample size on the "outside" of the plot with "N" as the header (sample size should go in the red area I highlighted)?
df <- data.frame(year = rep(c(2019, 2020), each = 10),
month = rep(c("March", "October"), each = 1),
site = rep(c("1", "2", "3", "4", "5"), each = 2),
type = rep(c("baitfish", "shark"), each = 1),
salinity = sample(x = 20:35, size = 20, replace = TRUE),
num = sample(x = 0:10, size = 20, replace = TRUE))
count_by_row <- data.frame(df[rep(row.names(df), df$num), 1:5])
ggplot(data=subset(count_by_row, !is.na(salinity)), aes(x = reorder(type, -salinity, FUN = median), y = salinity)) +
geom_boxplot(outlier.shape = 1, outlier.size = 2) +
coord_flip() +
xlab("") +
ylab("salinity (PSU)")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在增加正确的保证金后添加自定义注释:
You could add a custom annotation after increasing the right margin: