R add line breaks to expressions - r

I have very long expressions stored in a .txt file. By copying this epxression into R, it is represented in one line. When I try to run it, it doesn't work and errors like "unexpected symbol" or "unexpected numeric constant" appear. However, if I insert line breaks at arbitrary places, e.g. after every 3000 characters, it works smoothly.
Does anyone know how to handle this problem? In particular, is it possible to make these line breaks automatically or are there other possible solutions?
alpha <- 0.025; d1 <- 0.027; d2 <- 0.037; mu1 <- 0.024; mu2 <- 0.026; Z1 <- 0.6; Z2 <- 0.7; rho11 <- 0.076;
rho12 <- 0.074; rho21 <- 0.073; rho22 <- 0.072; S11 <- 0.086; S12 <- 0.087; S21 <- 0.084; S22 <- 0.083; u <- 2
exp(mu1*(mu1*u*d1^2 + d2*mu2*u*d1) - log(1 - 2*S22*d2^2*u - 2*S12*d1*d2*u - 2*S21*d1*d2*u - 2*S11*d1^2*u)/2 + mu2*(mu2*u*d2^2 + d1*mu1*u*d2) - (S21*((2*(S12*u*d2^2 + S11*d1*u*d2)*(d1^2*mu1*u + alpha*d1*u + d1*d2*mu2*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((d2^2*mu2*u + alpha*d2*u + d1*d2*mu1*u)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((2*(S21*u*d1^2 + S22*d2*u*d1)*(d2^2*mu2*u + alpha*d2*u + d1*d2*mu1*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((d1^2*mu1*u + alpha*d1*u + d1*d2*mu2*u)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))*(2*d1^2*mu1*u + 2*alpha*d1*u + 2*d1*d2*mu2*u) - (S22*((2*(S12*u*d2^2 + S11*d1*u*d2)*(d1^2*mu1*u + alpha*d1*u + d1*d2*mu2*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((d2^2*mu2*u + alpha*d2*u + d1*d2*mu1*u)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((2*(S21*u*d1^2 + S22*d2*u*d1)*(d2^2*mu2*u + alpha*d2*u + d1*d2*mu1*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((d1^2*mu1*u + alpha*d1*u + d1*d2*mu2*u)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))*(2*d2^2*mu2*u + 2*alpha*d2*u + 2*d1*d2*mu1*u) + Z1*(rho11*(2*d1^2*mu1*u + 2*alpha*d1*u + 2*d1*d2*mu2*u) - rho21*(d2^2*u*(S22*((2*(S12*u*d2^2 + S11*d1*u*d2)*(4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((2*(S21*u*d1^2 + S22*d2*u*d1)*(4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S21*((2*(S12*u*d2^2 + S11*d1*u*d2)*(4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((2*(S21*u*d1^2 + S22*d2*u*d1)*(4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) - rho11*(d1^2*u*(S21*((2*(S12*u*d2^2 + S11*d1*u*d2)*(4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((2*(S21*u*d1^2 + S22*d2*u*d1)*(4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S22*((2*(S12*u*d2^2 + S11*d1*u*d2)*(4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((2*(S21*u*d1^2 + S22*d2*u*d1)*(4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) + rho21*(2*d2^2*mu2*u + 2*alpha*d2*u + 2*d1*d2*mu1*u) + 2*alpha*d1*u) + Z2*(rho12*(2*d1^2*mu1*u + 2*alpha*d1*u + 2*d1*d2*mu2*u) - rho22*(d2^2*u*(S22*((2*(S12*u*d2^2 + S11*d1*u*d2)*(4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((2*(S21*u*d1^2 + S22*d2*u*d1)*(4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S21*((2*(S12*u*d2^2 + S11*d1*u*d2)*(4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((2*(S21*u*d1^2 + S22*d2*u*d1)*(4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) - rho12*(d1^2*u*(S21*((2*(S12*u*d2^2 + S11*d1*u*d2)*(4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((2*(S21*u*d1^2 + S22*d2*u*d1)*(4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S22*((2*(S12*u*d2^2 + S11*d1*u*d2)*(4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((2*(S21*u*d1^2 + S22*d2*u*d1)*(4*d2^2*mu2*u + 4*alpha*d2*u + 4*d1*d2*mu1*u))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - ((4*d1^2*mu1*u + 4*alpha*d1*u + 4*d1*d2*mu2*u)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) + rho22*(2*d2^2*mu2*u + 2*alpha*d2*u + 2*d1*d2*mu1*u) + 2*alpha*d2*u) + 2*alpha^2*u + Z1*(Z1*(rho11*(rho11*u*d1^2 + d2*rho21*u*d1) + rho21*(rho21*u*d2^2 + d1*rho11*u*d2) - rho11*(d1^2*u*(S21*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho11*u*d1^2 + d2*rho21*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho21*u*d2^2 + d1*rho11*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho21*u*d2^2 + d1*rho11*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho11*u*d1^2 + d2*rho21*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S22*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho11*u*d1^2 + d2*rho21*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho21*u*d2^2 + d1*rho11*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho21*u*d2^2 + d1*rho11*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho11*u*d1^2 + d2*rho21*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) - rho21*(d2^2*u*(S22*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho11*u*d1^2 + d2*rho21*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho21*u*d2^2 + d1*rho11*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho21*u*d2^2 + d1*rho11*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho11*u*d1^2 + d2*rho21*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S21*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho11*u*d1^2 + d2*rho21*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho21*u*d2^2 + d1*rho11*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho21*u*d2^2 + d1*rho11*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho11*u*d1^2 + d2*rho21*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) + d1^2*u) + Z2*(rho11*(rho12*u*d1^2 + d2*rho22*u*d1) + rho21*(rho22*u*d2^2 + d1*rho12*u*d2) - rho11*(d1^2*u*(S21*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho12*u*d1^2 + d2*rho22*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho22*u*d2^2 + d1*rho12*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho22*u*d2^2 + d1*rho12*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho12*u*d1^2 + d2*rho22*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S22*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho12*u*d1^2 + d2*rho22*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho22*u*d2^2 + d1*rho12*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho22*u*d2^2 + d1*rho12*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho12*u*d1^2 + d2*rho22*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) - rho21*(d2^2*u*(S22*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho12*u*d1^2 + d2*rho22*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho22*u*d2^2 + d1*rho12*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho22*u*d2^2 + d1*rho12*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho12*u*d1^2 + d2*rho22*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S21*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho12*u*d1^2 + d2*rho22*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho22*u*d2^2 + d1*rho12*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho22*u*d2^2 + d1*rho12*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho12*u*d1^2 + d2*rho22*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) + d1*d2*u)) + Z2*(Z2*(rho12*(rho12*u*d1^2 + d2*rho22*u*d1) + rho22*(rho22*u*d2^2 + d1*rho12*u*d2) - rho12*(d1^2*u*(S21*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho12*u*d1^2 + d2*rho22*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho22*u*d2^2 + d1*rho12*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho22*u*d2^2 + d1*rho12*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho12*u*d1^2 + d2*rho22*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S22*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho12*u*d1^2 + d2*rho22*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho22*u*d2^2 + d1*rho12*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho22*u*d2^2 + d1*rho12*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho12*u*d1^2 + d2*rho22*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) - rho22*(d2^2*u*(S22*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho12*u*d1^2 + d2*rho22*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho22*u*d2^2 + d1*rho12*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho22*u*d2^2 + d1*rho12*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho12*u*d1^2 + d2*rho22*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S21*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho12*u*d1^2 + d2*rho22*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho22*u*d2^2 + d1*rho12*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho22*u*d2^2 + d1*rho12*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho12*u*d1^2 + d2*rho22*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) + d2^2*u) + Z1*(rho12*(rho11*u*d1^2 + d2*rho21*u*d1) + rho22*(rho21*u*d2^2 + d1*rho11*u*d2) - rho12*(d1^2*u*(S21*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho11*u*d1^2 + d2*rho21*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho21*u*d2^2 + d1*rho11*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho21*u*d2^2 + d1*rho11*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho11*u*d1^2 + d2*rho21*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S22*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho11*u*d1^2 + d2*rho21*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho21*u*d2^2 + d1*rho11*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho21*u*d2^2 + d1*rho11*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho11*u*d1^2 + d2*rho21*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) - rho22*(d2^2*u*(S22*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho11*u*d1^2 + d2*rho21*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho21*u*d2^2 + d1*rho11*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S12*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho21*u*d2^2 + d1*rho11*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho11*u*d1^2 + d2*rho21*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1))) + d1*d2*u*(S21*((4*(S12*u*d2^2 + S11*d1*u*d2)*(rho11*u*d1^2 + d2*rho21*u*d1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho21*u*d2^2 + d1*rho11*u*d2)*(2*S11*u*d1^2 + 2*S12*d2*u*d1 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)) + S11*((4*(S21*u*d1^2 + S22*d2*u*d1)*(rho21*u*d2^2 + d1*rho11*u*d2))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1) - (2*(rho11*u*d1^2 + d2*rho21*u*d1)*(2*S22*u*d2^2 + 2*S21*d1*u*d2 - 1))/(2*S11*d1^2*u + 2*S22*d2^2*u + 2*S12*d1*d2*u + 2*S21*d1*d2*u - 1)))) + d1*d2*u)) + 2*alpha*d1*mu1*u + 2*alpha*d2*mu2*u)

The cause of this is described well in the answer to this question
In your case, since you've got the expression in a file, you can source() the file from R, rather than copying and pasting. Either you need to add an assignment in your text file, or you can do:
source("filename.txt")$value
to get the result of the computation
You mention in the comments that you want to be able to use this in an optimisation - a simple example over one dimension to find an alpha that minimise the expression would be:
f <- function(alpha){source("o:\\test.txt")$value}
optim(1, f, lower=0.5, upper=1.5, method="L-BFGS-B")
#$par
#[1] 1
#
#$value
#[1] 1.011915
#
#$counts
#function gradient
# 1 1
#
#$convergence
#[1] 0
#
#$message
#[1] "CONVERGENCE: NORM OF PROJECTED GRADIENT <= PGTOL"

Related

How to add italic values in ggplot

I have the following df:
df <- data.frame(Species = c("C. lupus", "C. latrans", "C. lupaster"),
pi = c('0.03', '0.04', '0.02'))
and I made a plot with ggplot
df %>%
mutate(Species= fct_reorder(Species, pi )) %>%
ggplot(aes(x=Species, y=pi)) +
geom_bar(stat="identity", fill="#f68060", alpha=.6, width=.4) +
coord_flip() +
xlab("") +
theme_bw() +
ylab("Nucleotide diversity (π)")
How can I write the species names in italic?
Thanks!
Just add theme(axis.text.y = element_text(face = 3)):
df %>%
mutate(Species= fct_reorder(Species, pi )) %>%
ggplot(aes(x=Species, y=pi)) +
geom_bar(stat="identity", fill="#f68060", alpha=.6, width=.4) +
coord_flip() +
xlab("") +
theme_bw() +
theme(axis.text.y = element_text(face = 3)) +
ylab("Nucleotide diversity (π)")

Problem adding a trendline to a graph in R ggplot2

I tried to use geom_smooth(method = "lm") and it doesn't work...
percentage.no.work <- cleanData %>% group_by(AREA) %>%
summarise(percentage = mean(ESTIMATED.CITY.UNEMPLOYMENT))
ggplot() +
geom_point(data=percentage.no.work, aes(x=AREA, y=percentage), alpha=0.6, color="purple", size=2) +
geom_smooth(method = "lm") +
theme_minimal() + ggtitle("Percentage Estimated City Unemployment") +
ylab("Percentage")
You need to provide the aesthetics for the geom_smooth as well. Either by including it in the ggplot() or in the geom_smooth() :
ggplot() +
geom_point(data=percentage.no.work, aes(x=AREA, y=percentage), alpha=0.6, color="purple", size=2) +
geom_smooth(aes(x=AREA, y=percentage), method = "lm") +
theme_minimal() + ggtitle("Percentage Estimated City Unemployment") +
ylab("Percentage")
You can avoid repeating section of the code putting it in the ggplot()
ggplot(data=percentage.no.work, aes(x=AREA, y=percentage)) +
geom_point(alpha=0.6, color="purple", size=2) +
geom_smooth(method = "lm") +
theme_minimal() + ggtitle("Percentage Estimated City Unemployment") +
ylab("Percentage")

how to overlay geom_rect and geom_boxplot in ggplot?

I am trying to use ggplot in order to overlay geom_rect under some boxplots.
I want the grey rectangle will be behind the box plots but I can't do it for some reason.
This is the code that I'm using:
ggplot(data, aes(x = reorder(genotype, -Shann.div, FUN = median), y = Shann.div)) +
geom_jitter(color="black", size=0.3, alpha=0.9) + geom_boxplot(outlier.shape = NA, coef = 0) +
geom_hline(yintercept = avg, color="red") +
#geom_hline(yintercept = (avg + 2 * SE), linetype='dashed', color="black") +
#geom_hline(yintercept = (avg - 2 * SE), linetype='dashed', color="black") +
geom_rect(aes(xmin=0, xmax=Inf, ymin=avg - SD, ymax=avg + SD), fill="grey", alpha=0.01) +
theme(panel.background = element_blank()) +
theme(axis.text.x=element_blank(), axis.ticks.x=element_blank()) +
ggtitle('Microbial UTO - Shannon diversity median') + xlab('genotype')
The ggplot package draws the geom layers in the order that you declare them. If you want the geom_rect layer in the back, put it before the other layers in the code:
ggplot(data, aes(x = reorder(genotype, -Shann.div, FUN = median), y = Shann.div)) +
geom_rect(aes(xmin=0, xmax=Inf, ymin=avg - SD, ymax=avg + SD), fill="grey", alpha=0.01) +
geom_jitter(color="black", size=0.3, alpha=0.9) + geom_boxplot(outlier.shape = NA, coef = 0) +
geom_hline(yintercept = avg, color="red") +
#geom_hline(yintercept = (avg + 2 * SE), linetype='dashed', color="black") +
#geom_hline(yintercept = (avg - 2 * SE), linetype='dashed', color="black") +
theme(panel.background = element_blank()) +
theme(axis.text.x=element_blank(), axis.ticks.x=element_blank()) +
ggtitle('Microbial UTO - Shannon diversity median') + xlab('genotype')

Sage does not recognize a unit ideal

I am trying to learn a bit of sage and I have tried playing with ideals in p-adic rings. But I don't understand how ideals work in polynomial rings. I have tried writing the following
A=Zp(5)
R.<x>=A[]
g1=(1+x)^(25)-1;
g2=6^(-25)*((1+x)^(25)-6^(25));
J=R.ideal(37,g1)
I=R.ideal(37,g2)
U=R.unit_ideal();
I==U
I==J
J==U
Since 37 is a 5-adic unit, I would expect the answer to be
True
True
True
because both I and J contain 37. But it is
False
False
False
What am I missing? I also apologise for not being able to understand how to TeX in stackoverflow.
Well, apparently Sage isn't checking that automatically.
print(U)
print(I)
print(J)
Principal ideal (1 + O(5^20)) of Univariate Polynomial Ring in x over 5-adic Ring with capped relative precision 20
Ideal (2 + 2*5 + 5^2 + O(5^20), (1 + 4*5^3 + 2*5^4 + 4*5^7 + 2*5^8 + 3*5^9 + 3*5^10 + 3*5^12 + 5^13 + 4*5^15 + 4*5^16 + 2*5^17 + 5^18 + 5^19 + O(5^20))*x^25 + (5^2 + 4*5^5 + 2*5^6 + 4*5^9 + 2*5^10 + 3*5^11 + 3*5^12 + 3*5^14 + 5^15 + 4*5^17 + 4*5^18 + 2*5^19 + O(5^20))*x^24 + (2*5^2 + 2*5^3 + 3*5^5 + 3*5^6 + 5^7 + 5^8 + 3*5^9 + 3*5^10 + 2*5^11 + 4*5^12 + 3*5^13 + 2*5^14 + 4*5^15 + 3*5^16 + 3*5^17 + 2*5^18 + O(5^20))*x^23 + (2*5^2 + 3*5^3 + 3*5^4 + 3*5^5 + 2*5^6 + 5^7 + 3*5^10 + 2*5^11 + 5^12 + 3*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 3*5^17 + 2*5^18 + 2*5^19 + O(5^20))*x^22 + (5^2 + 5^3 + 3*5^5 + 2*5^6 + 3*5^7 + 5^8 + 4*5^10 + 5^11 + 3*5^12 + 3*5^14 + 4*5^15 + 4*5^16 + 5^17 + 4*5^19 + O(5^20))*x^21 + (5 + 4*5^4 + 4*5^5 + 3*5^6 + 2*5^8 + 3*5^10 + 4*5^12 + 2*5^14 + 3*5^15 + 5^16 + 3*5^17 + 2*5^19 + O(5^20))*x^20 + (4*5^2 + 5^3 + 3*5^4 + 2*5^5 + 5^6 + 4*5^7 + 3*5^8 + 4*5^9 + 5^10 + 2*5^12 + 4*5^13 + 3*5^14 + 4*5^15 + 3*5^16 + 2*5^17 + 2*5^19 + O(5^20))*x^19 + (3*5^2 + 4*5^4 + 4*5^6 + 3*5^7 + 4*5^8 + 2*5^9 + 4*5^10 + 3*5^11 + 2*5^12 + 4*5^14 + 2*5^16 + O(5^20))*x^18 + (3*5^2 + 2*5^3 + 3*5^5 + 5^7 + 3*5^8 + 5^9 + 3*5^14 + 5^16 + 2*5^17 + 5^18 + 5^19 + O(5^20))*x^17 + (4*5^2 + 3*5^3 + 3*5^4 + 4*5^5 + 3*5^6 + 3*5^7 + 2*5^8 + 2*5^9 + 4*5^10 + 2*5^11 + 5^13 + 5^14 + 2*5^15 + 3*5^17 + 5^18 + 5^19 + O(5^20))*x^16 + (2*5 + 3*5^4 + 5^5 + 2*5^7 + 5^9 + 3*5^10 + 4*5^11 + 3*5^12 + 4*5^13 + 2*5^14 + 3*5^15 + 4*5^16 + 2*5^17 + 4*5^19 + O(5^20))*x^15 + (5^2 + 4*5^3 + 5^4 + 4*5^6 + 2*5^7 + 3*5^10 + 3*5^11 + 5^12 + 3*5^13 + 2*5^14 + 3*5^15 + 3*5^16 + 5^17 + 5^19 + O(5^20))*x^14 + (2*5^2 + 2*5^3 + 2*5^5 + 5^6 + 3*5^7 + 5^10 + 4*5^11 + 2*5^12 + 3*5^14 + 5^15 + 4*5^16 + 2*5^17 + 4*5^18 + 2*5^19 + O(5^20))*x^13 + (2*5^2 + 2*5^3 + 2*5^5 + 5^6 + 3*5^7 + 5^10 + 4*5^11 + 2*5^12 + 3*5^14 + 5^15 + 4*5^16 + 2*5^17 + 4*5^18 + 2*5^19 + O(5^20))*x^12 + (5^2 + 4*5^3 + 5^4 + 4*5^6 + 2*5^7 + 3*5^10 + 3*5^11 + 5^12 + 3*5^13 + 2*5^14 + 3*5^15 + 3*5^16 + 5^17 + 5^19 + O(5^20))*x^11 + (2*5 + 3*5^4 + 5^5 + 2*5^7 + 5^9 + 3*5^10 + 4*5^11 + 3*5^12 + 4*5^13 + 2*5^14 + 3*5^15 + 4*5^16 + 2*5^17 + 4*5^19 + O(5^20))*x^10 + (4*5^2 + 3*5^3 + 3*5^4 + 4*5^5 + 3*5^6 + 3*5^7 + 2*5^8 + 2*5^9 + 4*5^10 + 2*5^11 + 5^13 + 5^14 + 2*5^15 + 3*5^17 + 5^18 + 5^19 + O(5^20))*x^9 + (3*5^2 + 2*5^3 + 3*5^5 + 5^7 + 3*5^8 + 5^9 + 3*5^14 + 5^16 + 2*5^17 + 5^18 + 5^19 + O(5^20))*x^8 + (3*5^2 + 4*5^4 + 4*5^6 + 3*5^7 + 4*5^8 + 2*5^9 + 4*5^10 + 3*5^11 + 2*5^12 + 4*5^14 + 2*5^16 + O(5^20))*x^7 + (4*5^2 + 5^3 + 3*5^4 + 2*5^5 + 5^6 + 4*5^7 + 3*5^8 + 4*5^9 + 5^10 + 2*5^12 + 4*5^13 + 3*5^14 + 4*5^15 + 3*5^16 + 2*5^17 + 2*5^19 + O(5^20))*x^6 + (5 + 4*5^4 + 4*5^5 + 3*5^6 + 2*5^8 + 3*5^10 + 4*5^12 + 2*5^14 + 3*5^15 + 5^16 + 3*5^17 + 2*5^19 + O(5^20))*x^5 + (5^2 + 5^3 + 3*5^5 + 2*5^6 + 3*5^7 + 5^8 + 4*5^10 + 5^11 + 3*5^12 + 3*5^14 + 4*5^15 + 4*5^16 + 5^17 + 4*5^19 + O(5^20))*x^4 + (2*5^2 + 3*5^3 + 3*5^4 + 3*5^5 + 2*5^6 + 5^7 + 3*5^10 + 2*5^11 + 5^12 + 3*5^13 + 4*5^14 + 4*5^15 + 4*5^16 + 3*5^17 + 2*5^18 + 2*5^19 + O(5^20))*x^3 + (2*5^2 + 2*5^3 + 3*5^5 + 3*5^6 + 5^7 + 5^8 + 3*5^9 + 3*5^10 + 2*5^11 + 4*5^12 + 3*5^13 + 2*5^14 + 4*5^15 + 3*5^16 + 3*5^17 + 2*5^18 + O(5^20))*x^2 + (5^2 + 4*5^5 + 2*5^6 + 4*5^9 + 2*5^10 + 3*5^11 + 3*5^12 + 3*5^14 + 5^15 + 4*5^17 + 4*5^18 + 2*5^19 + O(5^20))*x + 4*5^3 + 2*5^4 + 4*5^7 + 2*5^8 + 3*5^9 + 3*5^10 + 3*5^12 + 5^13 + 4*5^15 + 4*5^16 + 2*5^17 + 5^18 + 5^19 + O(5^20)) of Univariate Polynomial Ring in x over 5-adic Ring with capped relative precision 20
Ideal (2 + 2*5 + 5^2 + O(5^20), (1 + O(5^20))*x^25 + (5^2 + O(5^20))*x^24 + (2*5^2 + 2*5^3 + O(5^20))*x^23 + (2*5^2 + 3*5^3 + 3*5^4 + O(5^20))*x^22 + (5^2 + 5^3 + 4*5^5 + O(5^20))*x^21 + (5 + 2*5^5 + 3*5^6 + O(5^20))*x^20 + (4*5^2 + 5^3 + 3*5^4 + 5^5 + 5^6 + 2*5^7 + O(5^20))*x^19 + (3*5^2 + 4*5^4 + 3*5^5 + 5^7 + 5^8 + O(5^20))*x^18 + (3*5^2 + 2*5^3 + 5^5 + 4*5^6 + 3*5^7 + 2*5^8 + O(5^20))*x^17 + (4*5^2 + 3*5^3 + 3*5^4 + 3*5^5 + 5^7 + 5^9 + O(5^20))*x^16 + (2*5 + 5^5 + 4*5^6 + 5^7 + 3*5^8 + 5^9 + O(5^20))*x^15 + (5^2 + 4*5^3 + 5^4 + 5^5 + 2*5^7 + 5^8 + 2*5^9 + O(5^20))*x^14 + (2*5^2 + 2*5^3 + 4*5^5 + 2*5^6 + 5^7 + 3*5^8 + 2*5^9 + O(5^20))*x^13 + (2*5^2 + 2*5^3 + 4*5^5 + 2*5^6 + 5^7 + 3*5^8 + 2*5^9 + O(5^20))*x^12 + (5^2 + 4*5^3 + 5^4 + 5^5 + 2*5^7 + 5^8 + 2*5^9 + O(5^20))*x^11 + (2*5 + 5^5 + 4*5^6 + 5^7 + 3*5^8 + 5^9 + O(5^20))*x^10 + (4*5^2 + 3*5^3 + 3*5^4 + 3*5^5 + 5^7 + 5^9 + O(5^20))*x^9 + (3*5^2 + 2*5^3 + 5^5 + 4*5^6 + 3*5^7 + 2*5^8 + O(5^20))*x^8 + (3*5^2 + 4*5^4 + 3*5^5 + 5^7 + 5^8 + O(5^20))*x^7 + (4*5^2 + 5^3 + 3*5^4 + 5^5 + 5^6 + 2*5^7 + O(5^20))*x^6 + (5 + 2*5^5 + 3*5^6 + O(5^20))*x^5 + (5^2 + 5^3 + 4*5^5 + O(5^20))*x^4 + (2*5^2 + 3*5^3 + 3*5^4 + O(5^20))*x^3 + (2*5^2 + 2*5^3 + O(5^20))*x^2 + (5^2 + O(5^20))*x + O(5^20)) of Univariate Polynomial Ring in x over 5-adic Ring with capped relative precision 20
Perhaps more troubling,
U>=I
False
However, I'm not an expert in the implementation of these rings. However, Sage does give
R(37).is_unit()
True
On the other hand,
K = R.ideal(A(37))
K==U
gives True but
L = R.ideal(1,g1)
L == U
gives False.
I feel like there must be something obvious I'm missing here, but if so maybe the documentation needs some work, so I've opened Trac 28692. If we're off base, I'm sure we'll hear - you may also wish to ask on ask.sagemath where a lot more devs hang out.

Meaningless Y-axis values in ggplot2 dot plot

I am trying to replicate Fivethirtyeight's Tarantino movie plot. This plot is using ggplot2's dotplot. The data can be found here.
My code is following:
tara <- read.csv("tarantino.csv")
dim(tara)
names(tara)
table(tara$movie)
rd <- subset(tara, movie=="Reservoir Dogs")
du <- subset(tara, movie=="Django Unchained")
ib <- subset(tara, movie=="Inglorious Basterds")
jb <- subset(tara, movie=="Jackie Brown")
kb1 <- subset(tara, movie=="Kill Bill: Vol. 1")
kb2 <- subset(tara, movie=="Kill Bill: Vol. 2")
pf <- subset(tara, movie=="Pulp Fiction")
plot1 <- ggplot(rd, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() + theme(legend.position="none") +
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
ggtitle(" RESERVIOR DOGS") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot2 <- ggplot(pf, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="top")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
theme(legend.position="none") +
ggtitle(" PULP FICTION") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot3 <- ggplot(du, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="top")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
theme(legend.position="none") +
ggtitle(" DJANGO UNCHAINED") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot4 <- ggplot(ib, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="top")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
theme(legend.position="none") +
ggtitle(" INGLORIOUS BASTARDS") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot5 <- ggplot(jb, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="top")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
theme(legend.position="none") +
ggtitle(" JACKIE BROWN") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot6 <- ggplot(kb1, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="top")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
theme(legend.position="none") +
ggtitle(" KILL BILL: VOL 1") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("")
plot7 <- ggplot(kb2, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth=0.5, method="histodot") +
theme_bw() +theme(legend.position="none")+
ylim(0,20)+
# Set the entire chart region to a light gray color
theme(panel.background=element_rect(fill="#F0F0F0")) +
theme(plot.background=element_rect(fill="#F0F0F0")) +
theme(panel.border=element_rect(colour="#F0F0F0")) +
ggtitle(" KILL BILL: VOL 2") +
theme(plot.title=element_text(face="bold",hjust=-.08,vjust=2,colour="#535353",size=12)) +
ylab("") +
xlab("minutes")
library(grid)
grid.newpage()
pushViewport(viewport(layout = grid.layout(7, 1)))
vplayout <- function(x, y)
viewport(layout.pos.row = x, layout.pos.col = y)
print(plot1, vp = vplayout(1, 1))
print(plot2, vp = vplayout(2, 1))
print(plot3, vp = vplayout(3, 1))
print(plot4, vp = vplayout(4, 1))
print(plot5, vp = vplayout(5, 1))
print(plot6, vp = vplayout(6, 1))
print(plot7, vp = vplayout(7, 1))
The output looks like this:
The plot has several issues:
Y axis is uncontrollable. I can use coord_fixed(ratio=X); but it's not helping much.
The dots are not same size. I have tried to use dotsize; but it's not working.
Failed to keep background grey in the legends.
Here's an approach:
# download data
download.file('https://raw.githubusercontent.com/fivethirtyeight/data/master/tarantino/tarantino.csv', '~/Desktop/tarantino.csv', method = 'curl')
# read in data
tara <- read.csv('~/Desktop/tarantino.csv')
library(ggplot2)
library(ggthemes) # has theme_fivethirtyeight, which will save a lot of work
ggplot(tara, aes(x=minutes_in, fill=type)) +
geom_dotplot(binwidth = 1, method = "histodot") +
theme_fivethirtyeight() +
ylim(0, 20) +
ggtitle('Deaths and Swearing in Tarantino Films') +
theme(strip.text = element_text(hjust = 0)) + # left justify facet titles
ylab("") +
xlab("") +
# facet_wrap defaults to titles on top. The labeller capitalizes movie titles.
facet_wrap(~movie, ncol = 1, labeller = labeller(movie = toupper))
# bin width/dot size is CRAZY SENSITIVE to aspect ratio. width 4:height 5:binwidth 1 lines up with your y-axis
ggsave('~/Desktop/Rplot.png', width = 8, height = 10, units = 'in')
What you get:

Resources