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.
Related
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!
I have been creating a hexagonal binning plot with rbokeh, which worked wonderfully. However, I would really like to a color legend into my plot, which does not seem to work.
library(rbokeh)
figure(legend_location = "top_right") %>% ly_hexbin(x=hp,y=mpg,data=mtcars)
To clarify what I would like to achieve to have a similar legend as in ggplot2 with the geom_hex() command
library(ggplot2)
ggplot(data=mtcars, aes(x=hp,y=mpg)) + geom_hex()+theme_minimal()
This is currently not possible with rbokeh but will be soon in a future release that is underway. I would recommend opening an issue on github to track this further.
I am currently trying to reorder the stacks in a stacked bargraph with ggplot2 using the order argument. This works like a charm when not using facetting, but upon running facet_grid, only one of the pannels works. It is important to realize that I want to use a custom order, rather than based on size (as suggested in this topic or others concerning the use of order=desc(variable)).
You should be able to reproduce this issue using the code below
require(dplyr)
require(tidyr)
require(ggplot2)
prod<-1:8
timing<-1:4
variab<-letters[1:3]
nobserv<-length(prod)*length(timing)*length(variab)
values<-runif(nobserv)
plotset<-data.frame(product=rep(prod,each=4,length=nobserv),
timepoints=rep(timing,length=nobserv),
variable=rep(variab,each=nobserv/3),
values=values)
sorter<-rep(c(-2,-1,-3),each=nobserv/3)
p <- ggplot(plotset,aes(fill=variable,order=sorter,x=product,y=as.numeric(as.character(values))))
p <- p + geom_bar(stat='identity', position='stack')
p <- p + facet_grid(~ timepoints)
p
This will generate this graph, clearly showing only timepoint three (3) does what I want.
I do not know why this is and if and how it could be fixed.
Thanks in advance for your input!
EDIT: I made a typo, now the issue should be reproducible
ps: I could reproduce the problem on both a linux and a windows machine with R 3.1.1 and ggplot2 1.0.0
I am following up on previous posts regarding similar questions. I am trying to change the y axis limits on a simple bar graph and what has been suggested in previous posts does not seem to work. The first graph below displays the different bars, but the second one, specifying the y-axis limits does not. Any idea why? Thanks.
group1=rep(1:5,5)
df=cbind(cars,group1)
means<-aggregate(speed~group1,df, mean)
ggplot(data=means,aes(x=group1,y=speed))+geom_bar(stat="identity",position="dodge")
ggplot(data=means,aes(x=group1,y=speed))+geom_bar(stat="identity",position="dodge")+
scale_y_continuous(limits=c(10,20))
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(...)