lao_zhang lao_zhang - 5 months ago 41
R Question

Plotting device with RStudio

I have issue with plotting

over my existing plot in
in RStudio. I ran the code within the code chunk in
(⌘ + return) and the
gives me a graph within the
(new feature of RStudio v1.0), however when I ran the second code
, an error shows up.

ylim = c(0.00, 0.02),
xlab = "Glucose Level",
main = "Figure",
lwd = 2)
col = "red",
lwd = 2)
Error in plot.xy(xy.coords(x, y), type = type, ...) : has not been called yet

On the other hand, if I copy and paste the codes into the console, I could get the plot I want, in the plot viewer within RStudio.
enter image description here

In addition, when I ran some other codes within the
(⌘ + return), my plots in the plot viewer in RStudio disappear. This means I have to do copy-paste into the console instead of using the (⌘ + return) shortcut.

Does anyone have the same problem?


This is a known problem, but you can solve it very easy: Press Ctrl+Shift+Enter to run the complete chunk, then everything works fine and you don't have to copy-and-paste all thing to the console. So do all your plots in one chunk and run this chunk. This will produce you the plot within the RMD file (as you mentioned: new feature of RStudio 1.0)