作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 ggplot vline 和 hline 在折线图上显示截距,但希望线条在图上的截取点处停止。这可能在 ggplot 中还是有其他解决方案
library(ggplot2)
pshare <- data.frame()
for (i in 1:365) {
pshare <- rbind(pshare,c(i, pbirthday(i,365,coincident=3)))
}
names(pshare) <- c("number","probability")
x25 <- qbirthday(prob = 0.25, classes = 365, coincident = 3) #61
x50 <- qbirthday(prob = 0.50, classes = 365, coincident = 3)
x75 <- qbirthday(prob = 0.75, classes = 365, coincident = 3)
p <- qplot(number,probability,data=subset(pshare,probability<0.99))
p <- p + geom_vline(xintercept = c(x25,x50,x75))
p <- p + geom_hline(yintercept = c(0.25,0.5,0.75))
p
最佳答案
将@joran 的评论扩展为答案和示例geom_vline
绘制整个情节;这就是它的目的。 geom_segment
只会在特定端点之间绘制。它有助于使用绘制线条的相关信息制作数据框。
probs <- c(0.25, 0.50, 0.75)
marks <- data.frame(probability = probs,
number = sapply(probs, qbirthday, classes=365, coincident=3))
qplot(number,probability,data=subset(pshare,probability<0.99)) +
geom_segment(data=marks, aes(xend=-Inf, yend=probability)) +
geom_segment(data=marks, aes(xend=number, yend=-Inf))
关于r - 有没有办法限制 ggplot2 中的 vline 长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9085104/
我是一名优秀的程序员,十分优秀!