I can't plot this graphic

I've been trying to plot this graph all night. Please, could someone give me a hand ?

enter image description here

This is what I've done so far. The constant function is in the medium of the graph, not sure why and I can't add the smaller ticks in the bottom and above the graph.

theta = c(0,0.5,1)
pthetaGivenData = c(1,1,1)

win.graph(4,4)
par(mar=c(4.5,3.5,3,1))
par(mgp=c(1.5,0.3,0))

plot( theta, pthetaGivenData, xaxt= "n" , yaxt= "n" , type= "l" , lwd = 2 ,
      xlab=bquote("Prior: " * "p" * (theta)) , ylab=expression("p" * (theta ~ "|" ~ D)) ,
      cex.axis=1 , cex.lab=1, axes = FALSE)
axis(1, at=c(0,0.5,1), tck= 0.03)
axis(2, at= c(0,1), labels= c(0,1), tick=FALSE)
axis(3, at=c(0,0.5,1), labels=FALSE, tck= 0.03)
box()

#plot( theta, pthetaGivenData, )
#axis.Date(1, at=1:11, labels=FALSE, tck= 0.01)
#axis.Date(3, at= 1:11, labels=FALSE, tck= 0.01)

text( .99 , .99 , cex=1.0 ,
     expression(0) , adj=c(0,.5) )

Upvotes: 2

Views: 204

Answers (1)

jay.sf
jay.sf

Reputation: 72593

You may use mtext for the labels. xaxs/yaxs="i" pulls the origin at the corner.

win.graph(4, 4)

op <- par(mar=c(4.5, 3.5, 3, 1), mgp=c(1.5, 0.3, 0))

plot(theta, pthetaGivenData, type="l", xlab="", ylab="",
     xaxt="n", yaxt="n", lwd=2, ylim=c(0, 1)*1.2,
     cex.axis=1, cex.lab=1, xaxs="i", yaxs="i")
sapply(c(1, 3), function(a) axis(a, at=theta, tck=0.04, labels=F))
sapply(c(1, 3), function(a) axis(a, at=0:10/10, tck=0.02, labels=F))
mtext(theta, 1, .5, at=theta)
mtext(0:1, 2, .5, at=0:1, las=1)
mtext(bquote("Prior: " * "p" * (theta)), 1, 2)
mtext(expression("p" * (theta ~ "|" ~ D)), 2, 1)
text(.95, 1.1, 0)

par(op)

enter image description here


Data:

theta <- c(0, 0.5, 1)
pthetaGivenData <- c(1, 1, 1)

Upvotes: 1

Related Questions