Unable to get plots displayed in Rstudio graphical viewer. - r

When I run my code all my graphs (both ggplot2 and plot) are displayed in an external "Quartz 2 [*]" graphical viewer.
I would like them to be displayed in the R studio GUI plot area to I can better save and view my files, along with the previous versions.
Is there anyway to stop this?
I recently updated my version of R, along with the X11 and xQuartz on my mac (also up to date), and I am guessing these updates are behind it.
I have seen many forums explaining how to get rstudio to export to an external viewer (e.g. "quartz()"), but not the other way.
I have looked, but these threads have not helped:
ggplot plots in scripts do not display in Rstudio
plot panel does not produce plots Rstudio
dev.off() even when hidden hide <- dev.off() is not working either.
Any help would be great,
Thanks.

If you upgrade R without upgrading RStudio, the graphics engine may not be compatible. To fix the "Quartz 2" popout, upgrade RStudio to a newer version that supports the graphics engine in the version of R you have installed.
I had the same problem, and noticed the following output to the console:
Warning message:
R graphics engine version 15 is not supported by this version of RStudio. The Plots tab will be disabled until a newer version of RStudio is installed.

Looks like I forgot to reinstall Rstudio as well.. That sorted my problem.

Related

Rmarkdown fails to render inline plots when opened within an R project on GoogleDrive

I have an R project held onto a Google Drive. I access both the R project and associated markdowns using the Google Drive desktop app. I recently updated my macOS to Monterey 12.2.1 and since then, I haven't been able to render plots inline within a markdown. I get the following error message when trying to print any plot:
Error in dev.off() :
QuartzBitmap_Output - unable to open file '/Volumes/GoogleDrive/Shared drives/.../.Rproj.user/shared/notebooks/-.../1/s/cqgw7b5dagxzw_t/_rs_chunk_plot_001.png'
This seems to be specific when opening a markdown, within an R project, onto a Google Drive. I have tried having a project on my local machine and opening the same markdown, plots display inline fine. I have tried opening the markdown outside of a project, again, can display plots inline fine. The plots also display in the viewer pane fine regardless and knitting is also not an issue.
The only clue I have is that when I go within the .Rproj.user directory, I can find a folder with the naming 'cqgw7b5dagxzw' (see path above), but it is missing the '_t'. Not sure what that could mean though.
Since updating the OS I have also reinstalled XQuartz.
I can still get to the plots, so it's not a HUGE issue, but the inline display feature is rather handy to make quick modifications to my visualisations.
Below are some session info.
Thanks!!!
PS: Plot twist! I can display plots inline with ggplotly?!?!
Workaround
I found this workaround which displays the plots in the viewer pane instead. It is definitely an improvement, but displaying plots inline allows you to get an idea of the proportions of the plot you will eventually knit.
> sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Monterey 12.2.1
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib
locale:
[1] en_GB.UTF-8/en_GB.UTF-8/en_GB.UTF-8/C/en_GB.UTF-8/en_GB.UTF-8
I found an issue someone logged on Rstudio github relates to this, linked here.
It seems you're right about the niche scenario of Rmarkdown + R Project + Google Drive + Inline plotting.
Someone in the comments suggested going to Preferences>General>Graphics and changing the back end option to Cairo instead of Quartz. Tried that on my end and seems to work when I tried a basic histogram with GGplot2.
Not sure if using Cairo makes anything else worse though.
Using MacOS Monteray (12.3.1) if that helps.

R ubuntu evince

Is there any way out here?
Evince is the standard PDF viewer of Ubuntu. The immensely popular platform for statistics, R, started its life as a Linux package. But when I do a plot in R -- vanilla, no frills, no user options -- and save it to PDF, I can never see axis labels, titles etc. In evince, even though they appear in every possible viewer (Acrobat, Foxreader, Sumatra, qpdfview) on any OS. I have included qpdfview as default in memeapps.list, but when I double-click a PDF file, I get evince. Is there any help except uninstall evince (which I don't want to do as it helps with other file formats).

How to plot in RStudio and not have a new window pop up (R Graphics: Device (ACTIVE)?

Whenever I plot any plot in RStudio, I get a new device window that pops up. This was not always the case. I must have changed some settings. How do I change the settings back to have plots go to the RStudio plot window?
I have explored the dev.off() and other dev functions without success. For example:
# Clear workspace
rm(list=ls())
# create data
set.seed(1)
x <- rnorm(100, 0, 1)
y <- rnorm(100, 3, 1)
plot(x,y)
produces the popped up window in the screenshotted image:
I want the device to stay in the RStudio plot window in the lower righthand corner. Does anyone have any help? I saw a similar question here that claims that an update will fix the issue. I updated within the last week. When I use sessionInfo() I am running R version 3.3.2, what I believe to be the latest version of R.
I know that this has been answered but the problem can arise in multiple ways. My issue had been much simpler. The plots were not showing up in the Rstudio plot pane simply because the default null GD was turned off via dev.off(). I'm running Rstudio Version 1.1.442 with R Version R-3.4.4
I ran dev.off() a few times until all windows including hidden ones were closed and I received the following response in the console window.
null device
1
I then ran this and the plot appeared in the RStudio plot pane
dev.new()
plot(mtcars$mpg~mtcars$disp)
For others who like me may still encounter this issue:
This is probably caused by an R update to 3.3.2 and is fixed by installing a newer version of RStudio. In my case 1.0.136 did the trick.
I solved this problem by updating RStudio (Help--> check for updates). The new version of RStudio I updated to is Version 1.1.383 and this problem was fixed. Currently I have version 3.4.3 for R.
Go to R studio menu bar and Tools->Global options->R Mark down
In that phase select "window" from that list in the "show output preview in:" then apply

R studio graph not appearing in plots window

I am having trouble getting my graphs to appear in the 'plots' window of R studio - once I run the script they appear in a separate R graphics window, separate to R Studio, with the 'plots' tab blank.
Is there a setting or code I should use to change this?
Thank you in advance,
This has been a consistent problem for many users ever since the last couple updates, myself included. It was apparently fixed with 3.5 version of R, which I haven't updated to, but you didn't mention which version you are running.
Either way, if you're running the most updated version or not, try getOption("device") and check the output of that. Per an R support community post, if the output does not say RStudioGD, you can use options(device = "RStudioGD").
The NEXT, and more annoying, solution was to uninstall and reinstall RStudio. Many people found that this solved their problem.
If neither of those work work, the only other solution that people were finding is to downgrade your R version to a compatible version unfortunately! It's really annoying, I know!
Hope I could help!

How do I get RStudio to publish R-markdown to the rpubs.org site?

According to a response from the RStudio team, the "standard" solution would be to follow the instructions for "Using R Markdown with RStudio", and notice the button on the third screenshot with the "Publish" button. A wonderfully simple solution that I'm quite grateful they have built.
However, the "Publish" button with the nice arrow and picture of the earth doesn't show up in my preview window, no matter how badly I want it to.
I am using RStudio (RStudio.version() 0.96.231) in Mac OS X Lion (10.7), with latest R version and updated markdown and knitr packages. I have an RPubs account, and have followed the RPubs instructions for creating and previewing the html rendered from an R markdown file from within RStudio.
This seems to be related to a post on the RStudio support blog about not-seeing a Publish button.
However, this question is different, as it requires actually getting content up onto RPubs. I have posted an analogous question on the RStudio Support blog.
The Rstudio team already answered how to get graphics embedded in html rendered by RStudio from R Markdown source; especially by pointing me to this extremely useful page explaining the way RStudio renders and packages R Markdown using knitr:
Using RStudio to render R Markdown
Finally, if you haven't heard about R-markdown (I just learned of it),
go here for details about R-markdown.
Confirmed by Josh Paulson at RStudio, this was a bug with RStudio in OS X Lion and not some weird extra set of unstated dependencies or unclear instructions.
Just install v0.96.233 or greater and this should work on Mac OS X Lion (10.7).
Actually, the implementation and instructions are quite straightforward.

Resources