R 将绘图转换为ggplot并添加水平线,直到指定点

R 将绘图转换为ggplot并添加水平线,直到指定点,r,ggplot2,plot,R,Ggplot2,Plot,我已经使用base Rplot()函数创建了下面的绘图,但我想将其转换为ggplot(),并添加水平线,如示例图片中所示,但直到与图形相交,直到结束时才添加完整的连续水平线 #图3.1和3.2 #曲线(logistic(pnorm(x),a=1,d=0),-3,3,ylab=“x的概率”, #main=“x的逻辑变换”,xlab=“z分数单位”) ##a=1.702的逻辑几乎与pnorm相同 #曲线(逻辑(pnorm(x),d=1,add=TRUE) #设置x轴值 θ也许是这样的 theta它

我已经使用base R
plot()
函数创建了下面的绘图,但我想将其转换为
ggplot()
,并添加水平线,如示例图片中所示,但直到与图形相交,直到结束时才添加完整的连续水平线

#图3.1和3.2
#曲线(logistic(pnorm(x),a=1,d=0),-3,3,ylab=“x的概率”,
#main=“x的逻辑变换”,xlab=“z分数单位”)
##a=1.702的逻辑几乎与pnorm相同
#曲线(逻辑(pnorm(x),d=1,add=TRUE)
#设置x轴值

θ也许是这样的


theta它看起来很漂亮很干净,但不完全确定线条的上部。我已经制作了黄色,可以删除,也可以添加。如果中间线是黑色也很好,可能吗?红线可以添加*就像在我的编辑中一样。@firmo23在原问题完全按照要求回答后,OP改变了他们的要求,这有点令人沮丧,但希望我的更新现在能提供您所需要的,并且您应该能够从中看到如何添加您喜欢的任何片段。您是对的。我已经创建了一个新的Q.Tnx。我会努力理解代码,如果需要的话,我会在将来创建新的Q。也许你也可以帮我
# Figure 3.1 & 3.2

# curve(logistic(pnorm(x), a=1, d=0),-3,3,ylab="Probability of x",
#       main="Logistic transform of x",xlab="z score units") 
# #logistic with a=1.702 is almost the same as pnorm 
# curve(logistic(pnorm(x), d=1),add=TRUE)


# Set x-axis values
theta <- seq(from = -10, to = 10, by = 0.001)

# Code for plot1

B_i <- 1
B_j <- -1
P_item1_rasch <- NULL
P_item2_rasch <- NULL
for (i in 1:length(theta)){
      P_item1_rasch[i] <- (exp((theta[i]-B_i)))/(1+(exp((theta[i]-B_i))))
      P_item2_rasch[i] <- (exp((theta[i]-B_j)))/(1+(exp((theta[i]-B_j))))
  }

#select the colors that will be used
library(RColorBrewer)
#all palette available from RColorBrewer
display.brewer.all()
#we will select the first 4 colors in the Set1 palette
cols<-brewer.pal(n=4,name="Set1")
#cols contain the names of four different colors



plot(theta, P_item1_rasch, xlim=c(-4,4), ylim=c(0,1))
lines(theta, P_item2_rasch,col=cols[2])

# Add lines at the values below, but only half as in the example Figures
# abline(h=0.5)
# abline(v=-1)
# abline(v=1)