英文:
Vertical position of stat_summary() in ggplot
问题
我试图做类似这里的第一个解决方案:
give.n <- function(x){
return(c(y = mean(x), label = length(x)))
}
ggplot(diamonds, aes(cut, price)) +
geom_boxplot() +
stat_summary(fun.data = give.n, geom = "text", y = 0)
英文:
I am trying to do something like the first solution here:
give.n <- function(x){
return(c(y = mean(x), label = length(x)))
}
ggplot(diamonds, aes(cut, price)) +
geom_boxplot() +
stat_summary(fun.data = give.n, geom = "text")
But I want those sample sizes to be displayed at position y = 0, not in the boxes of the boxplots. How do I do this?
答案1
得分: 1
The function give.n()
returns both, the y-coordinate at which to display the number and the number to be displayed (i.e., the label). You simply need to change the y-coordinate returned by give.n()
:
give.n <- function(x){
return(c(y = 0, label = length(x)))
}
英文:
The function give.n()
returns both, the y-coordinate at which to display the number and the number to be displayed (i.e., the label). You simply need to change the y-coordinate returned by give.n()
:
give.n <- function(x){
return(c(y = 0, label = length(x)))
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论