Not seeing any plots showing up in RStudio - r

I suspect my inability to see any results from my attempts to plot (using ggplot in RStudio) are related to the fact that when I check dev.cur I get null device. Would love help figuring out how to get plotting working in RStudio on my M1 Macbook Pro running Monterey.

I had been assigning my plots to variables, in which case they are not rendered at assignment time (and don't show up.) E.g.
plt <- ggplot(mpg, aes(x = displ, y = hwy)) + geom_point()
In which case rendering the plot simply required evaluating the variable
plt
Problem solved. Thanks to the commenters for getting me on the right path.

Related

R low quality graph in graphic device

I'm trying to figure out what is going on with my plot render.
Yesterday I produced a geom_smooth with ggplot2 but the output was very low.
for the example when I render this code:
library(ggplot2)
ggplot(mpg, aes(displ, hwy)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE)
I got this graph, and the line is not "sharp" at what it always does:
Crude render
Moreover, when I use the command ggsave () to produce the plot, the line renders look great as ever.
the render is the same if I use R GUI or Rstudio
I try to reinstall R and Rstudio, nothing do
I could not reproduce this "bug" on another computer and my Linux server
Did someone have any clue?

continue color scale is not working in ggplot2_2.0.0 in windows remote desktop [duplicate]

I'm running R version 3.0.1 and ggplot2 version 0.9.3.1 on a Windows machine and getting aberrant behavior from color bar legends -- the legend labels appear but the color bar mysteriously does not.
For example, if I run the following code:
d <- data.frame(x=rnorm(100), y=rnorm(100), z=rnorm(100))
ggplot(d, aes(x, y, color=z)) + geom_point()
I get this plot:
whereas on my other machine (a Mac running R version 2.15.2 and ggplot 0.9.3.1) the same code gives me this:
The behavior seems to apply only to color bars for continuous numerical variables -- legends for discrete factors appear as expected. I've tried reinstalling ggplot2. Anybody have thoughts on what's going on here? Thanks!
I found the problem, and a working solution, here. It's an issue with color rendering when accessing a server via Remote Desktop, and can be fixed in host settings.

R - ggplot2 poor quality of charts generated on Windows

Why lines in a chart generated from ggplot2 on Mac looks so smooth and round, but on Windows they look so sharp and edgy. Is there any option to fix that on Windows instead of going to the Apple Store?
For example, chart generated on Mac:
and a chart generated on Windows:
Edit:
Due to #thestatnoob answer, this is a plot generated from iris dataset on R 3.0.2, RStudio 0.99.486, chart resolution: 640x480.
data(iris)
library(ggplot2)
ggplot(data = iris) +
geom_density(aes(x = Sepal.Length, y = ..scaled.., fill = Species), alpha = 0.5)
Anti-aliasing options from the Cairo package in R solved the issue
This might be due to a rendering error rather than anything else. R graphics do look more low res and "edgy". Try plotting the exact same dataset in both OS's with the same settings, e.g. PNG/PS/PDF with identical resolution. If it turns out that the Windows plot doesn't look great, an alternative solution would be to:
Use RStudio, which is a GUI for R and produces "smooth" graphics, even on Windows
Use R in a MS PowerShell/command prompt

How can I prevent ggplot2 from overflowing window?

I'm running R 3.1.1 with ggplot2_1.0.0. I'm having trouble with the default layout. I would expect ggplot to do a better job avoiding the overflow you see here. It feels like ggplot thinks that my device is much larger than it actually is. I'm running this on Ubuntu 14.04, FWIW.
For something more reproducible, I run this:
ggplot(mtcars, aes(x=cyl,y=hp,color=as.factor(mpg))) + geom_point()
And get this, where the legends have really huge boxes.
Here is one solution. I used the cut argument to specify ranges over mpg. Using cut will automatically coerce the variable to a factor as well.
library(ggplot2)
ggplot(mtcars, aes(x=cyl,y=hp,color=cut(mpg,quantile(mpg,seq(0,1,by=.25))))) +
geom_point() + scale_color_discrete(name="Legend Title (mpg breaks)")

Color bar missing in ggplot legend, Windows Remote Desktop

I'm running R version 3.0.1 and ggplot2 version 0.9.3.1 on a Windows machine and getting aberrant behavior from color bar legends -- the legend labels appear but the color bar mysteriously does not.
For example, if I run the following code:
d <- data.frame(x=rnorm(100), y=rnorm(100), z=rnorm(100))
ggplot(d, aes(x, y, color=z)) + geom_point()
I get this plot:
whereas on my other machine (a Mac running R version 2.15.2 and ggplot 0.9.3.1) the same code gives me this:
The behavior seems to apply only to color bars for continuous numerical variables -- legends for discrete factors appear as expected. I've tried reinstalling ggplot2. Anybody have thoughts on what's going on here? Thanks!
I found the problem, and a working solution, here. It's an issue with color rendering when accessing a server via Remote Desktop, and can be fixed in host settings.

Resources