 # Help plotting base R plot to ggplot2 code

Hello,

I'm working through a stats course and one of the figures which is plotted is fairly complex and I would love to be able to find a ggplot solution for the plot but I haven't been able to figure it out.

Below is a reprex to produce the plot. All I want is an identical plot, just in ggplot.

Many thanks

``````url <- "https://drive.google.com/uc?export=download&id=1ofWEHtl3raVlQuZS38ljyyuzfjcMEsXN"

d\$treatment <- 1 + d\$prosoc_left + 2*d\$condition

pl <- by( d\$pulled_left , list( d\$actor , d\$treatment ) , mean )

plot( NULL , xlim=c(1,28) , ylim=c(0,1) , xlab="" ,
ylab="proportion left lever" , xaxt="n" , yaxt="n" )
axis( 2 , at=c(0,0.5,1) , labels=c(0,0.5,1) )
abline( h=0.5 , lty=2 )
for ( j in 1:7 ) abline( v=(j-1)*4+4.5 , lwd=0.5 )
for ( j in 1:7 ) text( (j-1)*4+2.5 , 1.1 , concat("actor ",j) , xpd=TRUE )
for ( j in (1:7)[-2] ) {
lines( (j-1)*4+c(1,3) , pl[j,c(1,3)] , lwd=2 , col=rangi2 )
lines( (j-1)*4+c(2,4) , pl[j,c(2,4)] , lwd=2 , col=rangi2 )
}
points( 1:28 , t(pl) , pch=16 , col="white" , cex=1.7 )
points( 1:28 , t(pl) , pch=c(1,1,16,16) , col=rangi2 , lwd=2 )
yoff <- 0.01
text( 1 , pl[1,1]-yoff , "R/N" , pos=1 , cex=0.8 )
text( 2 , pl[1,2]+yoff , "L/N" , pos=3 , cex=0.8 )
text( 3 , pl[1,3]-yoff , "R/P" , pos=1 , cex=0.8 )
text( 4 , pl[1,4]+yoff , "L/P" , pos=3 , cex=0.8 )
mtext( "observed proportions\n" )
``````

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.