Combined ggplot and plotrix - r

I need to add a Y axis break to a plot I made in ggplot. Is it possible to use the gap.barplot function in plotrix in a graph in ggplot? When I try, it cancels everything I did in ggplot and plots just the gap.barplot bit.
Thank you
Barbara

Unfortunately NO.
They work on two different "worlds".
I've been trying a lot but it seems (just like #Mark Peterson wrote) that doing this in ggplot is nearly impossible on purpose
You should look into these questions and answers which are very similiar:
Using ggplot2, can I insert a break in the axis?
Broken barplot using R/ggplot2

Related

Is it possible to use hatching in geom_bar

I came across this post: Texture in barplot for 7 bars in R? which suggests that you can use hatching in R, and I've been looking for this type of thing for a long time... However, I then realised that this post is about barplot, rather than geom_bar (or any ggplot2 function), and that any attempt to use "density" as a parameter in geom_bar just results in the parameter being ignored.
So my question is, is it possible to use the hatching density in ggplot? I know there are things like geom_patterns, but I'm not able adapt it to my needs, I just want to use hatching because I have too many colours to use distinguishible shades. And if so, how do I implement it? Whenever I google density geom_bar it shows me density plots which is not what I'm after so I'm turning to this forum for help...
Thanks
EDIT: I figured out ggpattern! I'm pretty sure I tried it before but maybe I wasn't as determined (read: desperate). so thanks for the suggestion

2D filled.contour plot with 1D histograms by axes [duplicate]

This question already has an answer here:
2D filled.contour plot with 1D histograms by axes by R
(1 answer)
Closed 9 years ago.
My task is simple, just to plot the following, but the plot in the middle should be a filled.contour plot:
http://gallery.r-enthusiasts.com/graph/Scatterplot_with_marginal_histograms_78
Background: I prefer filled.contour rather than hist2d. Because, I could use kernel smooth, so the plot for discrete data won't be too ugly. I also tried image() and then contour(), but the number on contour is not clear and no indication about the color.
My problem: in filled.contour function, it uses layout() for filledcontour() plot and rect() plot (color bar). However, I use layout() in outside code to organize 2 histograms and one filled.contour plot. Looks like, the layout outside is shadowed by filled.contour(). I am not sure how R deal with this problem. Should I rewrite filled.contour() somehow?
If we can plot in R like matplotlib in python, something like the following link will make life much easier:
http://matplotlib.org/examples/pylab_examples/scatter_hist.html
This looks like an identical question to this one on CrossValidated. See the answer there (which is to use .filled.contour instead of filled.contour.

Stacked dot plot using ggplot2

I am interested in making a stacked dotplot like the one in link below in ggplot2.
The following was made using dotPlot function in BHH2 package but does not have the coloring and faceting ease of ggplot2.
There is a geom_dotplot which create dotplots. Update your ggplot2 if you don't have it. It is a relatively recent addition.
See this for examples.

How do I draw a violin plot using ggplot2?

Can I use ggplot2 to produce a violin plot? Perhaps using some variation of geom_boxplot()?
Version 0.9.0 includes the geom_violin: http://docs.ggplot2.org/current/geom_violin.html
A quick googling returns this site, which uses geom_ribbon to draw violin plots for Figure 3.14.
Note to anyone catching up
As #Ben points out below, geom_violin() is now the preferred method for producing violin plots in ggplot2.

How does one plot a 3D stacked histogram in R?

I want to plot stacked histograms in R; i.e. stack individual histograms in the third dimension.
thank you all for your suggestions, especially the one by Shane.
#hadley, I agree with your points, however, my situation is different: the main point I'm trying to convey by plotting four stacked histograms is that the tails vary significantly....the part that will get obscured is of no consequence in the data I'm presenting....also, being able to read the frequency axis is also not important since I'll be plotting the relative frequencies...
One doesn't. This is a terrible display of data because the front histograms obscure the rear histograms and the perspective makes it just about impossible to read the values off the y-axis.
You could try using either rgl (see here) or 3dscatterplot (as in this example). Lattice also supports this:
library(lattice)
library(latticeExtra)
?panel.3dbars
You can see an example of this on the Learnr blog.
I don't believe that's technically a stacked histogram (a stacked histogram stacks the bars on top of each other). Moreover, a different kind of histogram could be more informative: look at the ggplot2 the documentation here for some examples.
hist_cut <- ggplot(diamonds, aes(x=price, fill=cut))
hist_cut + geom_bar() # defaults to stacking
Another option is to use latticing instead, with facet_wrap in ggplot2 (see this post as an example).

Resources