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!
Related
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.
I'm plotting in julia for the first time and have installed the Juno IDE. I'm plotting with Plots.jl and every time I plot, the y-axis tics have lots of decimals.
I've tried multiple backends, like GR, Plotly, PlotlyJS, but none have changed the behavior I'm seeing.
This is the code I have currently producing my results:
using Plots
gr()
x = 1:10; y = rand(10)
p = plot(x,y)
And the figure that's output:
https://github.com/bojohnson02/Random/blob/master/fig.pdf
That's a temporary bug caused by some changes to Showoff, the package that Plots uses to create the axis ticks. It should be fixed already, so updating your packages should work (]up). If it doesn't work yet, and you're in a hurry, installing master of the two packages should do the trick (] add Plots#master followed by ] add Showoff#master).
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.
I'm having some trouble plotting with ggplot2. When trying to use 2 different scale functions, they won't act at the same time, that is, only one command will actually work, depending on the order. For example, if I do plot + scale_x_discrete(...) and then plot + scale_fill_discrete(...), only the later will work (editing the legend), while the other wont, leaving the x axis unedited. If I switch the order of commands, then the axis is edited, while the legend is neglected.
Could you please explain why this is happening and how I should be doing this?
Did you try
plot + scale_x_discrete(...) + scale_fill_discrete(...)
This should be a simple question... I'm just trying to make a barplot from a vector in R, but want the values to be shown on a log scale, with y-axis tick marks and labelling. I can make the normal barplot just fine, but when I try to use log or labelling, things go south.
Here is my current code:
samples <- c(10,2,5,1,2,2,10,20,150,23,250,2,1,500)
barplot(samples)
Ok, this works. Then I try to use the log="" function defined in the barplot manual, and it never works. Here are some stupid attempts I have tried:
barplot(samples, log="yes")
barplot(samples, log="TRUE")
barplot(log=samples)
Can someone please help me out here? Also, the labelling would be great too. Thanks!
The log argument wants a one- or two-character string specifying which axes should be logarithmic. No, it doesn't make any sense for the x-axis of a barplot to be logarithmic, but this is a generic mechanism used by all of "base" graphics - see ?plot.default for details.
So what you want is
barplot(samples, log="y")
I can't help you with tick marks and labeling, I'm afraid, I threw over base graphics for ggplot years ago and never looked back.
This should get your started fiddling around with ggplot2.
d<-data.frame(samples)
ggplot(data=d, aes(x=factor(1:length(samples)),y=samples)) +
geom_bar(stat="identity") +
scale_y_log10()
Within the scale_y_log10() function you can define breaks, labels, and more. Similarly, you can label the x-axis. For example
ggplot(data=d, aes(x=factor(1:length(samples)),y=samples)) +
geom_bar(stat="identity") +
scale_y_log10(breaks=c(1,5,10,50,100,500,1000),
labels=c(rep("label",7))) +
scale_x_discrete(labels=samples)