Adding individual X and Y axis labels when using facet_wrap() - r

I am attempting to plot lots of graphs on the fly and I chanced upon the facet_wrap functionality. It produced the desired results until I realised that it was not assigning individual axes headings. There was just a single X and Y axis heading for a whole set of graphs. What I'm looking for is a way to assign individual axes headings for each graph.
Is this possible using the facet_wrap functionality at all?
Looking forward to any suggestions and advice.

EDIT:
(removed previous, incorrect, answer)
It is my understanding that if the axes of your plots are not the same (i.e. require different labels), the way to go would be with multiple separate plots (on the same page), and not with facet_wrap.

Related

How can I fix my grouping and legend in R?

I'm really new to R and i'm trying to group the x axis together instead it being separate like it it and also move the legend.
Graph and Code http://127.0.0.1:41763/graphics/plot_zoom_png?width=1200&height=455
Ran<-table(data$class, data$feeling)
Raw<-barplot(Ran, main="Class Feeling",xlab="Feeling", col=c("darkblue","red"), legend = rownames(Ran), beside=TRUE)
I would help with moving the legend and have the x-axis grouped as one. on the group its two separate, like Great and Great, where i just want one great on the group with the data together by the different times
You can specify legend position and others by using args.legend(). Unfortunately I can't tell you exactly what to do without knowing what data set would looks. However, I think this page might help you.

How do I Create a Faceted Bar Graph with Different Discrete X Axis in R ggplot

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.

How to move the legend to outside the plotting area in Plots.jl (GR)?

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)

Add trend line for every facet using ggplot?

I have created a similar plot following the instructions from this link regarding the plot with facets:
(source: statmethods.net)
I would like to add a trend line for every facet of the chart and also would like to arrange the facets for the y axis (3 gears, 4gears and 5 gears) manually. Same thing for x axis (4cyl, 6vyl and 8cyl) facets so they are arranged the way I want it rather than being sorted/arranged automatically.
I tried looking for a solution here in StackExchange and Googling around and found ways to add trendiness for charts that do not involve facets, but not how add trend lines for charts with multiple facets.

In Stata, how do I modify axes of dot chart?

I'm trying to create a dot chart in Stata, splitting it into two categories
Running a chunk of code:
sysuse nlsw88, clear
drop if race == 3
graph dot (mean) wage, over(occ) by(race)
Creates such output:
So far so good but I'd like to remove labels of Y axis from the right graph to give the data some more space.
The only way I've been able to do that was to manually edit graph and hide the axis label object:
Is there a way to do it programmatically? I do know I could use one more over() but in some graphs of mine that is already taken.
I believe the solution is buried in help bystyle and help by_option. However, I can't get it to work with your example (I'm on Stata 12). But the description is clear. For example:
A bystyle determines the overall look of the combined graphs,
including
whether the individual graphs have their own axes and labels or if instead the axes and labels are shared across graphs arrayed in the
same row and/or in the same column;
...
There are options that let you control each of the above attributes --
see [G-3] by_option --
And also
iyaxes and ixaxes (and noiyaxes and noixaxes) specify whether the y axes and x axes are
to be displayed with each graph. The default
with most styles and
schemes is to place y axes on the leftmost graph of each row and to place x axes on
the bottommost graph of each column. The y and
x axes include the
default ticks and labels but exclude the axes titles.
If for some reason that doesn't work out, something like
sysuse nlsw88, clear
drop if race == 3
graph dot (mean) wage, over(occ) by(race)
gr_edit .plotregion1.grpaxis[2].draw_view.setstyle, style(no)
does (but I don't really like the approach). You can mess with at least the axis number [#] to do a bit of customization. I guess recording changes in the graphical editor and then recycling the corresponding code, may be one way out of difficult situations.

Resources