Lattice in R: Bottom of bar charts not aligned with x=0 - r

I tried making a simple bar chart using the barchart function from the Lattice library with the following code
plot_sum_h <- barchart(event~value|incidence, data=msum_h_combo,
groups=variable,
ylab="Event", xlab="", layout=c(2,1),
main="Total Number of Casualities",
scales=list(y=list(relation="same"),
x=list(relation="free"))
)
and got
this graph. Links not working anymore.
The bottoms of the bars, which should be aligned with the zero mark on the x-axis are behind x=0. Does anyone have any idea what might have gone wrong? Any advice would be appreciated.

You can set that by setting limits on the x-axis. In your scales argument you can do
x=list(relation="free", limits= list(c(0,2000),c(0.20000)) )
In the limits list this will set the scales for each panel (when you use relation="free")
That will put the edge of the graph at 0, and I just guessed what would be good for the upper limits. You could also set limits like =c( 0,( 1.1*max(values) )) Which would set the max at 110% of the maximum of its Value in each panel.

Related

R corrplot crops bottom axis label

When I use corrplot::corrplot() to plot a correlation matrix, the bottom label (1) on the y-axis is half cut off, because the bottom of the plot is at the very bottom of the plotting area, and the 1 is centered on the bottom axis. I'd like to use the plot for publication. How do I give a bit more space at the bottom so that this bottom y-axis label is not cut off?
Thanks in advance for the plot and for help with the above. This is a very nice plot except for the above issue.
Larry Hunsicker
Although no reproducible example was provided, we can show here a generic example of how to deal with this. Here a corrplot, in which the bottom label on the color scale is cut off:
M = cor(mtcars)
corrplot(M)
We can solve this by increasing the margin size using mar parameter in corrplot, to give enough space around the figure for labels. We also need to specify par(xpd=TRUE) to allow labels to be printed within the margin areas. Note that the behaviour of corrplot with respect to graphical parameters is somewhat inconsistent. Some parameters need to be specified in a par statement preceding corrplot, otherwise they are not respected if specified within the corrplot statement itself. Other parameters only work if they are specified within the corrplot statement. ?corrplot will tell you which graphical parameters get over-ridden by default values if not specified in corrplot - these are the ones that will have to be specified inside corrplot.
par(xpd=TRUE)
corrplot(M, mar = c(2, 0, 1, 0))

R: Boxplot - how to move the x-axis label down?

#RGR ~ Treatment:Geno boxplot
fit <- aov(Total.RGR~Treatment:Geno, data=For.R)
summary(fit)
t <- TukeyHSD(fit)
t
boxplot(Total.RGR~Treatment:Geno,
data=For.R,las=2,ylim=c(-20,100),xlab="Treatment:Geno",ylab="RGR (mg/day)")
text(1:8, 95 ,c("a","ac","a","a","a","bd","bcd","ad"))
Is my code, it does the job, but when I rotate my x-axis labels the obstruct the x-axis title.
Does any of you know of a way to move the title down?
It must be easy but I cant find anything in the reference.
Thanks.
Mathias
I would set xlab="" and add it afterwards using mtext. So, either you play with line parameter an put it the bottom under your lables Or change completely the side to put it in the top of the plot.
mtext("Treatment:Geno", side=1, line=5)
mtext("Treatment:Geno", side=3)

How to draw abline() that doesn't intersect the Y-axis in R?

I have a location quotient plot drawn in R and want to draw a horizontal line along the plot where Y = 1. I have the code abline(h=1, col="black") but when the line is drawn, it intersects the Y-axis and crosses out my Y-axis labels.
Does anyone know how to terminate the line at the Y-axis rather than having it intersect?
Many thanks.
As mentioned in the comments, it looks like the parameter xpd has been changed, so one option is to change it back to FALSE, see ?par. you can control the clipping region using the clip function to further limit the range that abline and other functions plot within. This may also be affected by you plotting device (different devices can deal with clipping differently).

qcc pareto.chart: bars are squashed - how to adjust the y axis?

I've produced a pareto.chart using the QCC package in R. In the default plot, the Y axis is scaled too large & for that reason the bars are too small. Most of the plot is wasted to empty white space. I assume this is a result of the long tail (right-skew) in the data ?
How is it possible to re-scale the Y-Axis so that the bars of the chart will be taller and more prominent (and differences between the bars more visible) ?
This is my first question and I can't post images yet. Please follow the link to an illustration of the problem:
https://www.dropbox.com/s/t8bwhmoxmwl1aic/pareto-axis.png
Thanks!
Keith
If you type help(pareto.chart) you will see there is an option ylim to specify the limits if the y-axis. If you provide some sample data I could try it out.
Otherwise, try including in your function call
pareto.chart(..., ylim=c(0,10000))
and see if that rescales your y-axis.

`cex.lab` Axis label exceeds plot region

I want to create a plot with magnified axis labels using cex.lab=2 but the label exceeds the plot region. Any ideas on how can I solve this?
Here is an example of the issue:
plot(1:10,1:10,ylab=~gamma,cex.lab=2)
Which produces a graph with a beheaded $\gamma$
I have done some search before asking the question both in google and in this site but my google foo betrayed me this time.
You have to set larger margin of your plot window. That can be achieved with function par() and argument mar=. Numbers correspond to margin starting with bottom, then left margin, upper and right margin.
par(mar=c(5,5,1,1))
plot(1:10,1:10,ylab=~gamma,cex.lab=2)

Resources