I have combined several ggplots with arrangeGrob.
Now i'm searching for a way to plot a image over the whole plot.
For example a watermark which lies over the combined plots.
As the result of arrangeGrob isn't a standard plot or a ggplot object i cant do it the usual way.
Is there a possibility?
Related
I would like to make the output graphs wider. How do I accomplish this with the grid.arrange() function?
I have 4 scatter plots but they are a bit scrunched when I run the function. I just simply want to increase their width so they aren't scrunched and the values on the x axis read cleanly.
Can I easily manipulate dimensions with the grid.arrange() function?
I tried width()...but that didn't work.
I am making plots that have categorical x variables with multiple factors for each category. I use geom_point and position_dodge similar to this post: ggplot2: geom_point() dodge shape but NOT color. If you look closely at the plot created in that post you can see that when xVar=C the "+" points are not symetrical, in that the right and bottom lines are longer than the top and left. Perhaps this is not a big deal for simple plots, but I have a fairly complex plot. I have a 3*3 multi-plot using grid_arrange. This multi-plot has a total of 81 points and error bars for each of the points. The distorted points are not centered on many of the error bars, so this problem really stands out in my case. Perhaps this has something to do with using position_dodge with grid_arrange.
I've tried exporting the image as different file types (e.g., jpg, png, pdf).
Here is some code from the aforementioned link:
x=tibble(Color=c(rep('A',12),rep('B',12),rep('C',12)),
Shape=rep(c(rep('A',3),rep('B',3),rep('C',3),rep('D',3)),3),
xVar=rep(c('A','B','C'),12),
Value=rnorm(36))
ggplot(x,aes(xVar,Value,color=Color,shape=Shape))+
geom_point(position=position_dodge(width=.5))
ggplot(x,aes(xVar,Value,color=Color,shape=Shape,group=Shape))+
geom_point(position=position_dodge(width=.5))
I would like to have geom_point shapes that are not distorted.
I have a bar graph which looks like the following:
Problem: If I facet it by the same variable as the color, the x-axis has space for plotting all the bars even though I don't need them.
My Solution: I used multiplot function from the Rmisc to separately make bar graphs for each partner but then a lot of individual customization is needed to make the graphs go cohesively together.
Question: Is there another way that I can use to get closer to plot 2 without the extra spaces for the variables that don't apply.
I'm using ggplot to plot.
use:
+ facet_wrap(~variable_to_facet_by,
scales = 'free')
as part of your ggplot code and that should get you what you want.
I have the following plot where part of the data is being obscured by the legend:
using Plots; gr()
using StatPlots
groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)))
I can see that using the "legend" attribute, the legend can be moved to various locations within the plotting area, for example:
groupedbar(rand(1:100,(10,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)
Is there any way of moving the plot legend completely outside the plotting area, for example to the right of the plot or below it? For these kinds of stacked bar plots there's really no good place for the legend inside the plot area. The only solution I've been able to come up with so far is to make some "fake" empty rows in the input data matrix to make space with some zeros, but that seems kind of hacky and will require some fiddling to get the right number of extra rows each time the plot is made:
groupedbar(vcat(rand(1:100,(10,10)),zeros(3,10)),bar_position=:stack, label="item".*map(string,collect(1:10)),legend=:bottomright)
I can see that at there was some kind of a solution proposed for pyplot, does anyone know of a similar solution for the GR backend? Another solution I could imagine - is there a way to save the legend itself to a different file so I can then put them back together in Inkscape?
This is now easily enabled with Plots.jl:
Example:
plot(rand(10), legend = :outertopleft)
Using layouts I can create a workaround making a fake plot with legend only.
using Plots
gr()
l = #layout [a{0.001h}; b c{0.13w}]
values = rand(1:100,(10,10))
p1 = groupedbar(values,bar_position=:stack, legend=:none)
p2 = groupedbar(values,bar_position=:stack, label="item".*map(string,collect(1:10)), grid=false, xlims=(20,3), showaxis=false)
p0=plot(title="Title",grid=false, showaxis=false)
plot(p0,p1,p2,layout=l)
Is there any way to position a legend inside the plot area while minimizing its overlap with data points? I realize that legend.position can be tuned manually, and that the package ggrepel handles similar behavior for text labels, but I'm looking for an existing/new programmatic method to put the legend in a non-busy location of the plot.
I'd like to use it with plots made using ggplot2, although a general solution would also be welcome.