Font size in mirt plots - r

I'm trying to increase font size in mirt plots, however, so far I'm able to increase size of ticks only:
library(mirt)
x <- mirt(Science, 1, SE=TRUE)
plot(x)
plot(x, scales = list(cex = c(1.4)))
How can I increase size of the axis and main title? I tried to add xlab = list(cex = 1.4), however I'm getting an error:
Error in xyplot.formula(score ~ Theta, plt, ylim = c(sum(mins) - ybump_full, :
formal argument "xlab" matched by multiple actual arguments
**EDIT: **
Some parts can be increased with trellis.par.set() as suggested by #user20650, however it does not include font size of legend.
trellis.par.set(par.xlab.text = list(cex = 1.4), par.ylab.text = list(cex = 1.4))
plot(x, type = "trace", facet_items = FALSE, scales = list(cex = 1.4),
par.strip.text = list(cex = 1.4), main = FALSE)
Moreover, this does not have impact on the following plot:
plot(x, type = "infoSE", facet_items = FALSE, scales = list(cex = 1.4),
par.strip.text = list(cex = 1.4), main = FALSE)

You can set parameters globally with trellis.par.set or pass to the individual plot using the par.settings parameter. trellis.par.get() can be used to get a list of the names of the objects that can be updated.
So for example the following can be used to update specific parameters within a plot
plot(x, type = "trace",
par.settings=list(
par.xlab.text=list(cex=3, col="red"),
par.main.text=list(cex=2)))
Or to update globally use
trellis.par.set(par.xlab.text=list(cex=3, col="red"),
par.main.text=list(cex=2)
)
Using grid.pars=list(cex=3)) seems to update all text sizes

Related

How to get the same ratio of plot and the picture in R? [duplicate]

I am plotting correlation coefficients (values = 0.0:1.0) for two isotopes measured in each individual from two populations. I would like to have a fixed aspect-ratio for my scatter-plot so that the x- and y-axis are exactly the same size no matter the graphics device. Suggestions?
This is my first plot in R, any comments on refinements to my code is appreciated? Finally, is it worth investing in learning the basic plotting techniques or should I jump right to ggplot2 or lattice?
My plot script:
## Create dataset
WW_corr <-
structure(list(South_N15 = c(0.7976495, 0.1796725, 0.5338347,
0.4103769, 0.7447027, 0.5080296, 0.7566544, 0.7432026, 0.8927161
), South_C13 = c(0.76706752, 0.02320767, 0.88429902, 0.36648357,
0.73840937, 0.0523504, 0.52145159, 0.50707858, 0.51874445), North_N15 = c(0.7483608,
0.4294148, 0.9283554, 0.8831571, 0.5056481, 0.1945943, 0.8492716,
0.5759033, 0.7483608), North_C13 = c(0.08114805, 0.47268136,
0.94975596, 0.06023815, 0.33652839, 0.53055943, 0.30228833, 0.8864435,
0.08114805)), .Names = c("South_N15", "South_C13", "North_N15",
"North_C13"), row.names = c(NA, -9L), class = "data.frame")
opar <- par()
## Plot results
par(oma = c(1, 0, 0, 0), mar = c(4, 5, 2, 2))
plot(1,1,xlim=c(0:1.0), ylim=c(0:1.0), type="n", las=1, bty="n", main = NULL,
ylab=expression(paste("Correlation Coefficient (r) for ", delta ^{15},"N ",
"\u0028","\u2030","\u0029")),
xlab=expression(paste("Correlation Coefficient (r) for ", delta ^{13},"C ",
"\u0028","\u2030","\u0029")))
points(WW_corr$South_N15, WW_corr$South_C13, pch = 23, cex = 1.25,
bg ="antiquewhite4", col = "antiquewhite4")
points(WW_corr$North_N15, WW_corr$North_C13, pch = 15, cex = 1.25,
bg ="black")
axis(1, at = seq(0, 1.0, by = 0.1), labels = F, tick = TRUE, tck = -0.01)
axis(2, at = seq(0, 1.0, by = 0.1), labels = F, tick = TRUE, tck = -0.01)
abline(h=.86, v=.86, col = "gray60", lty = 2)
legend("topleft", c("North", "South"), pch = c(15, 23),
col = c("black", "antiquewhite4"), pt.bg = c("black", "antiquewhite4"),
horiz=TRUE, bty = "n")
par(opar)
par(pty="s")
plot(...)
sets the plot type to be square, which will do the job (I think) in your case because your x and y ranges are the same. Fairly well hidden option documented in ?par.
Using asp=1 as a parameter to plot will get interpreted by the low-level plot.window call and should give you a unitary aspect ratio. There is the potential that a call using ylim and xlim could conflict with an aspect ratio scpecification and the asp should "prevail". That's a very impressive first R graph, by the away. And an excellent question construction. High marks.
The one jarring note was your use of the construction xlim=c(0:1.0). Since xlim expects a two element vector, I would have expected xlim=c(0,1). Fewer keystrokes and less subject to error in the future if you changed to a different set of limits, since the ":" operator would give you unexpected results if you tried that with "0:2.5".

Change size of the axis text in r

I have model created by train function from caret. I want to plot this object and increase size of text and title of axis. I found how to change size of titles, but I couldn't find how to do it for text on the axis. Example code for my problem below:
library(caret)
m <- train(mpg~., data = mtcars, tuneGrid = expand.grid(.mtry=c(2,4,5)))
plot(m, xlab = list(font=3, cex = 5), ylab = list(font=3, cex = 5))
I tried using cex.axis and ps parameters but none of them worked.
Adding the scales argument with a list for the x and y axes works for me. The items in the list for scales would be able to be customized like the axis labels were.
library(caret)
m <- train(mpg~., data = mtcars, tuneGrid = expand.grid(.mtry=c(2,4,5)))
plot(m, xlab = list(font=3, cex = 5),
ylab = list(font=3, cex = 5),
scales = list(x = list(font=2,cex=2),y=list(font=2,cex=2))
)

Remove axes ticks using plot3d in R

I am trying to render a 3D cube with spheres plotted inside.
I am using RGL library in R and rendering with plot3d
I would like to keep all 12 axes lines, but remove the tick marks.
This is the code I have:
library(rgl)
rgl.open()
rgl.bg(color='white')
a <- c(0.9, 0.9, 0.1)
b <- c(0.1, 0.9, 0.9)
c <- c(0.9, 0.1, 0.1)
xlab="z"
ylab="y"
zlab="x"
type="s"
col="red"
size=3
plot3d(a, b, c, xlab, ylab, zlab, type, col, size, xlim=c(0,1), ylim=c(0,1), zlim=c(0,1), aspect=c(3,3,3), main="", sub="", ann=FALSE, axes=TRUE)
Output:
I have tried using this POST as a solution, but I cannot get the axes lines to appear, while making sure the cube is transparent.
The code below is based off the aforementioned post:
plot3d(xvar, yvar, zvar, type = 's', col = colgroup, size = 0.05, alpha = 0.50,
radius = 0.2, xlab = 'Cost Leader', ylab = 'Performance Leader',
zlab = 'Fashion Leader', axes = FALSE)
rgl.bbox(xlen = 0, ylen = 0, zlen = 0, color = c('grey100'), alpha=0.5, axes=TRUE)
text3d(x = xvar, y = yvar, z = zvar, text = brands, adj = c(2.5,2.5), cex = 0.7)
I have tried adding alpha arguement but this is the output (one of them):
Any input is appreciated. This seemingly simple issue has caused a fair amount of head scratching.
TLDR: How to make transparent cube with points and xyz axes labeled. (No ticks).
R version: 3.5.1
Platform: x86_64-apple-darwin15.6.0 (64-bit)
P.S. Couldn't make new tag for plot3d .. hence they are split...
This is unrelated to your question, but it's important: don't use rgl.open() or rgl.bg() or rgl.bbox(). They will just cause trouble for you. Use open3d() and bg3d() and bbox3d().
Also unrelated, but I think this is good advice: don't use functions with long argument lists without naming the arguments. It's too easy to have unnamed args matched to the wrong thing.
As to your question: do the plot with no axes, then add the nonstandard axes you want. Since you don't really want anything there, use just box3d() to draw the box. For example,
library(rgl)
open3d()
bg3d(color = "white")
a <- c(0.9, 0.9, 0.1)
b <- c(0.1, 0.9, 0.9)
c <- c(0.9, 0.1, 0.1)
xlab <-"z"
ylab <- "y"
zlab <- "x"
type <- "s"
col <- "red"
size <- 10
plot3d(a, b, c,
xlab = xlab, ylab = ylab, zlab = zlab,
type = type, col = col,
xlim = c(0,1), ylim = c(0,1), zlim = c(0,1),
aspect = c(3,3,3),
size = size,
main = "", sub = "", ann = FALSE, axes = FALSE)
box3d()
This produces

Manually set fontsize of axis titles in native-R plot and lattice graphing functions

I am trying to prepare a graph for a poster presentation, but am getting very frustrated by how difficult things that should be simple are in plot. I want to plot a qq-plot of residuals from a mixed-effects model. All I want to do is change the font size of the axis title
. Here's a reproducible example.
library(lme4)
library(lattice)
fm1 <- lmer(Reaction ~ Days + (Days | Subject), sleepstudy)
qqmath(fm1,
main = list("QQ-Plot", cex = 2),
id=0.05,
cex = list(x = 2),
scales = list(x = list(cex = 2), y = list(cex = 2)))
This all works fine. But when I try to increase the font size of the axis title
qqmath(fm1,
main = list("QQ-Plot", cex = 2),
xlab = list("x-axis", cex = 2),
id=0.05,
cex = list(x = 2),
scales = list(x = list(cex = 2), y = list(cex = 2)))
I get
Error in qqmath.formula(x = ~x, ylab = "Standardized residuals", xlab = "Standard normal quantiles", :
formal argument "xlab" matched by multiple actual arguments
I gather from this post that this is due to competing arguments in the function call and some ellipsis in the original qqmath.formula object, but surely there has to be an easier way to set the fontsize of the axis titles than reprogramming the original function?!
The lattice system has functions trellis.par.get and trellis.par.set and this can be used to control the fontsize of the xlab and ylab components:
?trellis.par.get
names( trellis.par.get() )
trellis.par.set(par.ylab.text=list(cex=.5))
qqmath(fm1,
main = list("QQ-Plot", cex = 2), id=0.05,
cex=list(left=.55,bottom=.5),
scales = list(x = list(cex = 1), y = list(cex = 1)))
... reduces the size of the ylab. You can find a more complete list of the components and features that can be set from a chart onpage 127 in the "Lattice" book by Sarkar.

Setting graph attributes in qqmath from the lattice package?

Can anyone tell me how to set attributes within qqmath from the lattice package. Specifically how do I increase the font size of axis titles, axis text etc? None of the native plot arguments seem to work.
library(lattice)
lattice::qqmath(~ rnorm(100), distribution = function(p) qt(p, df = 10),
id=0.05,
main = "this is a title",
ylab = "this is a y-axis",
xlab = "this is an x-axis",
cex = 2,
cex.axis = 4,
font = 2,
cex.lab = 4)
Found a solution in the labyrinth that is the help page for lattice. In order to specify attributes of axis labels in lattice graphs you need to use the x and y argument within the scales argument, all wrapped in list(). To change the font size of titles you also need to wrap everything in a list():
lattice::qqmath(~ rnorm(100), distribution = function(p) qt(p, df = 10),
id=0.05,
main = list("this is a title", cex = 2),
ylab = list("this is a y-axis", cex = 3),
xlab = list("this is an x-axis", cex = 4),
scales = list(x = list(cex = 4)))

Resources