`cex.lab` Axis label exceeds plot region - r

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)

Related

How to expand your plot so all labels can be seen without overlapping in R

I have a plot with 50 categories(states) that show on my X axis, but in my output they are on top of each other. I want my plot to be spread out engough/large enough that there is no overlap and you could determine the state value from the next.
NOTE: i used the coord_flip command, so I know that my X-axis is actually my Y in image and vice versa. I am just wondering what function I would use to fix problem.
You can always change the size of the text via themes(axis.text.x=element_text(size=...))...
But the easy answer here is that your plot will change appearance based on the aspect ratio. When you view in Rstudio, you can adjust the size of your plot and you'll see the rearrangement. Additionally, when you save, the plot, play around in particular to the height and width to get the ratio you want. ggsave('filename.png', width=??, height=??).

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 units of margins, text and points in a figure

I am trying to plot some data in a plot where I leave a big margin free to add other information, namely text and points.
I am now struggling with keeping the size of the margin, text and points in a fixed ratio. I want this so that the layout of the figure does not change every time I plot new data.
I have:
a<-8
counter<-1
spacing<-a/(3*a)
adding<-a/(3*a)
start<-a*(a/3)
alphabet<-c("A","A","A","A","A","A","A","A")
x<-c(1,2,3,4,5,6,7,8)
y<-c(10,20,30,40,50,60,70,80)
png(file="TESTING.png", units="in", width=a, height=a, res=a*100)
par(xpd=NA,mar=c(0,0,0,0),oma=c(0,0,0,(3*a))) #bottom, left,top, right
plot.new()
plot(x,y)
points(pch=20,10, 10, cex=5)
text(10,10, alphabet, cex=5, col="blue")
this creates the image below.
What I do not understand is why the size of the point and the text is not the same and why the margin can be "bigger" than the width of the figure.
BASICALLY, the units of the margins, the points and the text are not the same...
What I need is a way to make the size of the point and text AND the margin independent of the data I plot so that the figure always looks the same although there is more data in it in some cases (for example 10 or 20 points with text in the margin).
This could be done by setting the units of points, text and margin to inches so that a is the same for all of them...
Or to know the ratio between the different units used by R for margin, points and text...
Any ideas on how to solve that?
Please let me know if clarifications are needed!

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

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.

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.

Resources