这是我的第一个问题:
使用ggplot2
问:图例键中是否可以有水平线?
library(ggplot2)
dat <- data.frame(vs=c(0,0,1,1),
stat = c("25%", "75%", "25%", "75%"),
value = c(quantile(mtcars$disp[mtcars$vs==0],0.25),
quantile(mtcars$disp[mtcars$vs==0],0.75),
quantile(mtcars$disp[mtcars$vs==1],0.25),
quantile(mtcars$disp[mtcars$vs==1], 0.75)))
p <- ggplot(mtcars, aes(disp)) +
coord_flip() +
facet_grid(vs~.) +
geom_histogram(aes(y = ..density..), stat="bin") +
geom_vline(mapping=aes(xintercept=value, colour=stat), linetype="solid", size=0.6, alpha=0.7, data=dat) +
guides(col = guide_legend(nrow = 2, title="Quantile")) +
theme(legend.position = "bottom")
p