我附上圖形,image.jpg,我想在其中為 x<3 繪制 y=0 線,為 x>=8 繪制 y=1 線,即結果將是 image2.jpg。
這些是 image.jpg 的說明。
df <- data.frame(x=Asignaturas, y=solF)
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
geom_text(aes(label = paste0(solF,''),vjust = -0.5), color = "black")
ylab("Función de distribucción")
xlab("Asignaturas"))
p
有誰知道怎么做?
謝謝


uj5u.com熱心網友回復:
使用基礎 R 的選項。
plot(df$x, df$y, xlim=c(2.5, max(df$x) .5), ylim=c(0, 1.075), pch=19)
points(df$x 1, df$y, pch=1)
segments(df$x, df$y, df$x 1)
text(df$x, df$y .05, df$y)
sapply(0:1, \(x) lines(2:3 x*6, rep(x, 2), col='red'))

要不就
plot(df$x, df$y, type='s', xlim=c(2.5, max(df$x) .5), ylim=c(0, 1.075))
text(df$x, df$y .05, df$y)
sapply(0:1, \(x) lines(2:3 x*6, rep(x, 2), col='red'))

資料:
df <- structure(list(y = c(0, 0.14, 0.31, 0.48, 0.67, 0.82, 1), x = c(2,
3, 4, 5, 6, 7, 8)), class = "data.frame", row.names = c(NA, -7L
))
uj5u.com熱心網友回復:
如果您想堅持使用 ggplot2,geom_segment()它將提供您正在尋找的內容。制作引數的 data.frame,然后添加geom_segment().
extraLines <- data.frame(x = c(-Inf, max(df$x)), xend = c(min(df$x), Inf), y = c(2, max(df$y)), yend = c(2, max(df$y)))
p
geom_segment(data = extraLines, aes(x = x, xend = xend, y = y, yend = yend), colour = "red")
geom_point(data = filter(extraLines, x > 0), aes(x = x, y=y), colour = "red")
geom_point(data = filter(extraLines, x < max(df$x)), aes(x=xend, y=y), shape = 1, colour = "red")

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/363896.html
上一篇:Python實作一個函式來回傳一個串列,其中y[i]是質數<=到i的個數
下一篇:S3.putObject無法執行
