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.
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 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 am working on a diametric class distribution data, with over 10,000 individuals, and I wanted to make a histogram to show the results, but I am having a problem when I try to plot it.
When I tried using the histogram function
histogram(data)
I get a histogram that is calculating the percentage of individuals
Histogram using the histogram function
Then I tried using qplot function
qplot(data, geom = "histogram")
And got a histogram like the one you can see in image 2
qplot function
So I thought maybe is a problem with the y-axis scale so I tried using ylim() and the plot I got was only the axis with no data
Could someone please tell me what I'm doing wrong?
I'm trying to get a histogram like the one in image 3Histogram goal
I really appreciate your help to point out if I am not adding other codes or maybe redirect me to a cheat sheet that can clarify some things
thanks
Try to use the ggplot2 package, for example:
library(ggplot2)
ggplot(data = [YOUR_DATA], aes([YOUR_VARIABLE])) +
geom_histogram()
EDIT:
Looking at your desired result, I think you want to use barplot() instead of histogram().
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
Is there a way to convert ggplot2 plots into black-and-white versions without rewriting much of their code, so that the black-and-white versions remain readable?
For instance, to replace scale_fill_gradient with scale_fill_grey? Or automatically make photocopy-friendly transformations as sites like http://colorbrewer2.org/ advise. (Unfortunately, textures are not an option, as ggplot2 doesn't support them.)
It's clearly possible with if ... else and custom functions, but is there a more general solution?
My second line in every ggplot figure I make is
theme_bw()
so
qplot(mpg, wt, data = mtcars) +
theme_bw()