I want to plot data in a graph with larger font-size for the lables.
x = c(0:10)
y = sin(x) + 10
plot (
x, y, type="o",
xlab = "X values",
ylab = "Y values",
cex.axis = "2",
cex.lab = "2",
las = 1
)
Unfortunately the numbers on the y-axis overlap the label for the y-axis. I tried to use mar, but that did not work (By the way, how can I find out which graphic parameters can be directly used in the plot command and which have to be set with the par()-method? ).
How can I avoid that labels overlap?
Thanks for your help.
Sven
Enter the ggrepel package, a new extension of ggplot2 that repels text labels away from one another. Just sub in geom_text_repel() in place of geom_text() and the extension is smart enough to try to figure out how to label the points such that the labels don't interfere with each other.
Data Visualization using R Programming When we create a plot in R, the Y-axis labels are automatically generated and if we want to remove those labels, the plot function can help us. For this purpose, we need to set ylab argument of plot function to blank as ylab="" and yaxt="n" to remove the axis title.
To alter the labels on the axis, add the code +labs(y= "y axis name", x = "x axis name") to your line of basic ggplot code. Note: You can also use +labs(title = "Title") which is equivalent to ggtitle .
The quick and dirty way would be to use par
and add a newline in ylab
, even though it's conceptually terrible.
x = 0:10
y = sin(x) + 10
par(mar=c(5,7,4,2))
plot (
x, y, type="o",
xlab = "X values",
ylab = "Y values\n",
cex.axis = "2",
cex.lab = "2",
las = 1
)
Concerning which parameters you can set directly in plot
have a look at ?plot.default
and ?plot.xy
as they will recieve the ...
arugments. There's also a couple of calls to undocumented functions (as far as I can find) like localWindow
and localBox
but I don't know what happens to them. I'd guess they're just ignored.
Use par(mar)
to increase the plot margins and par(mgp)
to move the axis label.
par(mar = c(6.5, 6.5, 0.5, 0.5), mgp = c(5, 1, 0))
#Then call plot as before
In the help page ?par
it explains which parameters can be used directly in plot
and which must be called via par
.
There are several parameters can only be set by a call to ‘par()’:
• ‘"ask"’, • ‘"fig"’, ‘"fin"’, • ‘"lheight"’, • ‘"mai"’, ‘"mar"’, ‘"mex"’, ‘"mfcol"’, ‘"mfrow"’, ‘"mfg"’, • ‘"new"’, • ‘"oma"’, ‘"omd"’, ‘"omi"’, • ‘"pin"’, ‘"plt"’, ‘"ps"’, ‘"pty"’, • ‘"usr"’, • ‘"xlog"’, ‘"ylog"’ The remaining parameters can also be set as arguments (often via ‘...’) to high-level plot functions such as ‘plot.default’, ‘plot.window’, ‘points’, ‘lines’, ‘abline’, ‘axis’, ‘title’, ‘text’, ‘mtext’, ‘segments’, ‘symbols’, ‘arrows’, ‘polygon’, ‘rect’, ‘box’, ‘contour’, ‘filled.contour’ and ‘image’. Such settings will be active during the execution of the function, only. However, see the comments on ‘bg’ and ‘cex’, which may be taken as _arguments_ to certain plot functions rather than as graphical parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With