Reputation: 5828
I'm following along with an R book and some of the examples aren't actually plotting anything for me in R Studio (I'm running 3.6.1 of R). Here is the code I'm running:
dose <- c(20, 30, 40, 45, 60)
drugA <- c(16, 20, 27, 40, 60)
drugB <- c(15, 18, 25, 31, 40)
opar <- par(no.readonly = TRUE)
par(pin=c(2, 3))
par(lwd=2, cex=1.5)
par(cex.axis=.75, font.axis=3)
plot(dose, drugA, type="b", pch=19, lty=2, col="red")
plot(dose, drugB, type="b", pch=23, lty=6, col="blue", bg="green")
par(opar)
But I can't see any errors, nothing shows up in the Plots pane, and troubleshooting has been shooting in the dark... I found by trial and error that this code actually produces a chart:
dose <- c(20, 30, 40, 45, 60)
drugA <- c(16, 20, 27, 40, 60)
drugB <- c(15, 18, 25, 31, 40)
plot(dose, drugA, type="b", pch=19, lty=2, col="red")
plot(dose, drugB, type="b", pch=23, lty=6, col="blue", bg="green")
So removing all the par()
related lines makes a plot actually show up... My assumption is that the book I'm following is for a different version of R, but I'm such a noob that I don't know.
Any ideas what I'm doing wrong?
Upvotes: 0
Views: 444
Reputation: 5828
I figured out what my problem was. I was trying to run all the lines of a file in the upper left pane by hitting command + enter BUT that would only run the last line, not everything in the file. For it to work like I expected, I needed to do Shift+Command+P, That runs everything in the file. Sigh there went 2 hours banging my head against the wall!
I'm a total noob at RStudio!
Thanks @thelatemail for the hint that put me on the right track.
Upvotes: 1