R 如何在ggplot中显示分面箱线图中的中值?

R 如何在ggplot中显示分面箱线图中的中值?,r,ggplot2,R,Ggplot2,继续我以前的问题 现在我喜欢在刻面的箱线图中显示值标签。我又有点困了。 问题更多的是让geom_text()识别二维数组或数据帧 p <- structure(list(PROVIDER = structure(c(4L, 3L, 4L, 4L, 3L, 4L, 3L, 4L, 4L, 3L, 4L, 3L, 4L, 3L, 3L, 4L, 3L, 4L, 3L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 3L, 3L, 4L, 1

继续我以前的问题 现在我喜欢在刻面的箱线图中显示值标签。我又有点困了。 问题更多的是让geom_text()识别二维数组或数据帧

p <- structure(list(PROVIDER = structure(c(4L, 3L, 4L, 4L, 3L, 4L, 
3L, 4L, 4L, 3L, 4L, 3L, 4L, 3L, 3L, 4L, 3L, 4L, 3L, 4L, 3L, 3L, 
3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 3L, 3L, 4L, 1L, 1L, 1L, 1L, 
1L, 4L, 1L, 3L, 4L, 4L, 4L, 4L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 2L, 4L, 3L, 3L, 4L, 4L, 4L, 3L, 2L, 2L, 3L, 3L, 
3L, 4L, 3L, 4L, 3L, 4L, 3L, 4L, 3L, 3L, 4L, 1L, 3L, 3L), .Label = c("Other", 
"Skinny Mobile", "TNZMobile", "Vodafone NZ Mobile"), class = "factor"), 
    TYPE = structure(c(3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 2L, 3L, 3L, 
    3L, 3L, 3L, 2L, 3L, 3L, 2L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 2L, 3L, 3L, 3L, 1L, 2L, 3L, 3L, 2L, 3L, 3L, 3L, 1L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 1L
    ), .Label = c("PM BUSINESS", "PM CONSUMER", "PREPAY"), class = "factor"), 
    AVGREV = c(10.426, 4.4175, 33.0408333333333, 49.71, 0, 6.778, 
    15.2858333333333, 0, 14.5558333333333, 13.3955555555556, 
    51.6075, 14.25, 11.85, 6.42833333333333, 4.1725, 14.7383333333333, 
    12.97375, 66.65, 11.4866666666667, 15.6533333333333, 16.7541666666667, 
    2.38428571428571, 77.475, 16.3316666666667, 3.414, 13.2466666666667, 
    13.905, 0.740833333333333, 36.2158333333333, 6.91, 16.4141666666667, 
    65.3116666666667, 18.0225, 127.831666666667, 15.2888888888889, 
    4.35166666666667, 7.38416666666667, 13.904, 4.34833333333333, 
    30.685, 11.6575, 42.844, 13.6216666666667, 24.6241666666667, 
    26.6441666666667, 93.391, 66.3966666666667, 9.89333333333333, 
    0, 34.998, 12.8836363636364, 7.44571428571429, 10.4772727272727, 
    35.5233333333333, 11.7911111111111, 12.82, 0.161111111111111, 
    0.36, 14.0775, 4.96571428571429, 20.7675, 8.4375, 7.3075, 
    1.71833333333333, 0.0725, 1.44916666666667, 0, 2.875, 10.9466666666667, 
    0, 11.8255555555556, 25.745, 0, 0, 21.3858333333333, 38.9108333333333, 
    6.32142857142857, 28.2625, 5.95166666666667, 22.5675, 12.1541666666667, 
    55.8766666666667, 15.5883333333333, 14.2175, 12.7991666666667, 
    1.8075, 13.845, 8.08333333333333, 8.7, 43.0991666666667, 
    19.2316666666667, 7.055, 7.47571428571429, 33.2175, 14.1625, 
    0, 5.204, 0, 77.39, 77.39)), .Names = c("PROVIDER", "TYPE", 
"AVGREV"), row.names = 23961:24060, class = "data.frame")

ar_meds <-ddply(p,.(list(TYPE,PROVIDER)), summarise, med = median(AVGREV))
ar.m <- ggplot(p,aes(x=TYPE, y=TOTALREV))+geom_boxplot() +facet_wrap(~TYPE)
ar.m+geom_text(data = ar_meds, aes(x = TYPE, y = med, label = round(med)),size = 3, vjust = -0.5)

p你的问题充满了语法错误和对不存在的变量和对象的引用

如果要在绘制面时为每个箱线图提供中值,则需要确保面化变量存在于每次调用
geom...

一个简单的、可重复的例子

set.seed(1)
library(plyr)
DF <- data.frame(TYPE = sample(letters[1:3], 500, replace = TRUE), 
  PROVIDER = letters[1:5], VALUE = rnorm(500))

# get the medians by type and provider (both columns
# will exist in the new data.frame

meds <- ddply(DF, .(TYPE, PROVIDER), summarize, med = median(VALUE))

ggplot(DF, aes(x=PROVIDER,y=  VALUE)) + 
   geom_boxplot() + facet_wrap(~TYPE) + 
   geom_text(data = meds, aes(y = med, label = round(med,2)),size = 3, vjust = -0.5)
set.seed(1)
图书馆(plyr)

如果你的例子不可复制,那么什么是
portout
,我也认为
ar\u meds