1

我想只考虑我的data.frame中的百分位数来制作这样的图。所以我的 data.frame 中的一行会是这样的:

Name; q0.05; q0.25; q0.45; q0.55; q0.75; q0.95
Italy;   76;    88;    95;   109;   112;   123

这就是我直接想转化为情节的内容。任何帮助或建议表示赞赏!

4

1 回答 1

11

一个完整的可重现的例子(就像你可以提供的......):

dat <- data.frame(Name = factor(sample(letters[1:5],1000,replace = TRUE)),
                    val = runif(1000))

datSum <- ddply(dat,.(Name),summarise,q05 = quantile(val,0.05),
                                    q25 = quantile(val,0.25),
                                    q45 = quantile(val,0.45),
                                    q55 = quantile(val,0.55),
                                    q75 = quantile(val,0.75),
                                    q95 = quantile(val,0.95))
datSum$NameAlt <- 1:5

和情节:

ggplot(datSum,aes(ymin = NameAlt - 0.2,ymax = NameAlt + 0.2)) + 
    geom_rect(aes(xmin = q05,xmax = q95),fill = "white",colour = "black") + 
    geom_rect(aes(xmin = q25,xmax = q75),fill = 'lightblue',colour = "black") +
    geom_rect(aes(xmin = q45,xmax = q55),fill = 'blue',colour = "black") +
    scale_y_continuous(breaks = 1:5,labels = datSum$Name)

在此处输入图像描述

于 2012-04-25T15:03:10.010 回答