stat_summary()在ggplot中的垂直位置

huangapple go评论85阅读模式
英文:

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 &lt;- function(x){
   return(c(y = mean(x), label = length(x)))
}
ggplot(diamonds, aes(cut, price)) + 
   geom_boxplot() + 
   stat_summary(fun.data = give.n, geom = &quot;text&quot;)

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 &lt;- 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 &lt;- function(x){
   return(c(y = 0, label = length(x)))
}

huangapple
  • 本文由 发表于 2023年5月17日 23:56:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76274014.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定