gpt4 book ai didi

r - 仅用水平线绘制阶跃函数

转载 作者:行者123 更新时间:2023-12-04 11:27:11 25 4
gpt4 key购买 nike

我使用 ggplot2 绘制阶跃函数 geom_step() .
我现在需要的是摆脱垂直线。
至少这应该是数学中一个相当普遍的问题......
docs不要提这种可能性。
某处是否有隐藏的参数,或者我是否需要以某种方式转换数据以便我可以为每个数据点打印单独的行?
特尔;博士:
ggplot(data,aes(x,y))+geom_step()想要ggplot(data,aes(x,y))+geom_step(lines=horizontal)

最佳答案

通读这个例子。您可能想要删除 vline 并使用各种参数——参见 http://docs.ggplot2.org/current/ .

library(ggplot2)
df <- data.frame(x=seq(0, 10), y=cumsum(rnorm(11)))
df$xend <- c(df$x[2:nrow(df)], NA)
df$yend <- df$y
p <- (ggplot(df, aes(x=x, y=y, xend=xend, yend=yend)) +
geom_vline(aes(xintercept=x), linetype=2, color="grey") +
geom_point() + # Solid points to left
geom_point(aes(x=xend, y=y), shape=1) + # Open points to right
geom_segment()) # Horizontal line segments
p

output from ggsave

关于r - 仅用水平线绘制阶跃函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30729678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com