我在R中绘制了直方图,并在垂直间隔中使用abline()
标记了分位数。但是,我想绘制一个图例,它显示分位数的相应值以及分位数区间本身。
当前的图例几乎就在那里,您可以看到下面是否运行示例代码。但我似乎无法成功地将图例间隔与其对应的值和彩色线符号对齐。我尝试使用data.frame()
来实现这一点,但它没有成功。
非常感谢任何提示或建议。
x<-1:100
quantiles_x<-quantile(x)
hist(x)
abline(v=quantiles_x, col=c("blue", "green","red","yellow","black"))
legend('topright', legend=c(names(quantiles_x), levels(factor(quantiles_x))), lwd=1, col=c("blue","green","red","yellow","black"))
答案 0 :(得分:0)
这样的东西?
x<-1:100
quantiles_x<-quantile(x)
hist(x)
abline(v=quantiles_x, col=c("blue", "green","red","yellow","black"))
labels <- paste(names(quantiles_x), "[",quantiles_x,"]")
legend('topright', legend=labels, lwd=1,
col=c("blue","green","red","yellow","black"))