I am unable to use ggplot2 to produce any graphs - r

When I try to plot anything using ggplot2, I fail to produce a graph. The output changes, and is inconsistent, but in place of a graph, I receive a blank, white image, or axis without data, or all of the data, axis, and labels smushed into the center of the graph.
When making a scatter plot, like this:
ggplot(iris, aes(x=Petal.Length, y=Petal.Width)) + geom_point()
I get the following error message:
Error in UseMethod("depth") :
no applicable method for 'depth' applied to an object of class "NULL"
and a blank graph with labelled axes (note the range of errors above though).
This happens both when I use ggplot and when I use qplot.
Currently, I am using:
OSX 10.11.6
R: 3.3.2
XQuartz: 2.7.11
All of the above have been re-installed.

Try to resize plot boundaries. I got the same error in Rstudio and was able to fix just by doing that.

Related

ggplot boxplot labels not showing

I am creating a boxplot and can get the plot to show, but the x and y axis ticks and labels do not show up. This occurs with my own data as well as with example data. Here is the example data (from http://www.cookbook-r.com/Graphs/Axes_(ggplot2)/:
bp <- ggplot(PlantGrowth, aes(x=group, y=weight)) +
geom_boxplot()
bp
And the resulting figure
Setting the discrete x axis doesn't change anything either
bp + scale_x_discrete(limits=c("trt1","trt2","ctrl"))
results in changing the order of the boxplots but no labels show. Why aren't the ticks and labels showing up and how do I get them to show?
Question was solved in the comments by #chemdork123 but wanted to post the answer here to close the question. I uninstalled all of the packages but the base and recommended packages, following the instructions found here https://www.r-bloggers.com/how-to-remove-all-user-installed-packages-in-r/. After uninstalling all packages, I reinstalled ggplot2 and the captions appeared. After reinstalling each previous problem one by one I learned ggtern was the issue here. Removing ggtern and reinstalling ggplot2 again fixed the issue and code runs perfectly.

ggplot: axes lines, values, and labels not plotting

I recently noticed that when I try plotting anything in ggplot2, both the x and y axes data (values, labels, lines, everything) are missing. I have tried to manually specify and enter the missing data using scale and theme commands, but ggplot still won't display the axes.
For example, the following simple code produces this plot on my computer:
ggplot(mpg, aes(x=class,y=hwy)) + geom_boxplot()
I have been using R and ggplot regularly for a few years and never encountered this problem until recently, but I don't know what computer/R/ggplot settings could have changed.
Interestingly, when I use base plotting functions there are no issues (both axes plot normally), so it seems like it's only an issue in ggplot.
E.g., the base code below produces this plot on my computer:
boxplot(mpg$hwy ~ mpg$class)
I have tried uninstalling and reinstalling ggplot multiple times to no avail.
Any advice for how to fix ggplot?
Thanks!

Reproducing R Art/ Error: Aesthetics must be either length 1 or the same as the data

I am trying to reproduce this graph. There parameter "line = element_blank()" appears twice; I commented one occurrence. When one runs the code (with current versions of the packages, in RStudio) one gets the error message: "Error: Aesthetics must be either length 1 or the same as the data (900): colour, alpha."
My ggplot experience is limited. I could not fix the error by following solutions to similar errors. Any help would be appreciated.
The provided code has an extra color aesthetic in your ggplot command. If you remove the color = element_blank() from the geom_area command I believe your plot will render.

Making pie chart's contours smoother on Shiny

I am trying to have a nice looking plot for two (or possibly more) continuous values in the form of a pie chart using ggplot2.
The code is the following :
library("ggplot2")
library("ggthemes") ## for theme_economist
df <- data.frame(origin=c('with','without'),value=c(24536,50456))
pie <- ggplot(df, aes(x = "",y=value, fill = origin))+
geom_bar(width = 1,stat="identity")+
coord_polar(theta = "y",start=pi/3)+
theme_economist()
The pie is relatively fine except that the contours of the pie seems to be a bit irregularly drawn.Of course when you export it as a pdf it looks fine but displayed in RStudio or Shiny it doesn't look nice at all.
Is there a way to change the resolution of the ggplot object directly or to make renderplot() aware that we want to display the image at a high resolution ?
I tried modifying the res argument of the renderPlot() function but it distorts the image and do not get rid of the irregularity of the border.
How to make the contours of the pie smoother on Shiny or RStudio directly ? Thanks.
To improve the resolution of the plot on Shiny you have to set the res argument to its default value of 72. It does not make a lot of sense to me but it worked just fine the resolution went from really bad to really nice !
However increasing its value further can lead to distortion of the image.
It seems that for now you cannot change the resolution of the plotting object itself before exporting it or rendering it into Shiny.

Why does ggplot give a blank page with the message "Regions defined for each Polygons"?

After reading a shapefile, I am using plot(), and am getting a plot.
But when I am using q=ggplot(), am getting a blank plot along with the message
Regions defined for each Polygons
Any idea why?
Use fortify() to plot shapefiles using ggplot.

Resources