I am intending to create a funnel plot with an effective sample size. I am using funnel.default() function of metafor package. I tried the following code to create such a funnel plot
Soil_mineral_nitrogen$inv_n_tilda <- with(Soil_mineral_nitrogen, (control_mean + treatment_mean) / (control_mean*treatment_mean))
par(mfrow = c(1, 2))
funnel(Soil_mineral_nitrogen$lnrr, Soil_mineral_nitrogen$inv_n_tilda, yaxis="ninv",
#xlim = c(-3, 3),
ylab = "Effective sample size (ñ)",
xlab = "Effect size (RR)", col =Soil_mineral_nitrogen$unique_id, atransf = exp)
But this code is returning me an error as follows
Error in funnel.default(Soil_mineral_nitrogen$lnrr, Soil_mineral_nitrogen$inv_n_tilda, :
No sample size information available.
Does anyone know how to deal with this error?
It worked for me with the following code
par(mfrow = c(1, 2))
funnel(Soil_mineral_nitrogen$lnrr, Soil_mineral_nitrogen$v, ni = Soil_mineral_nitrogen$inv_n_tilda,
yaxis="ni",
#xlim = c(-3, 3),
ylab = "Effective sample size (ñ)",
xlab = "Effect size (RR)", col =Soil_mineral_nitrogen$unique_id, atransf = exp)
Related
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))
)
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.
I'm new to R and my question might be a little silly, but any help is appreciated. I want to graphically explore a sample to find an appropriate distribution from which the sample could have been drawn. But when I plot a histogram of the sample, the density of the sample exceeds the theoretical maximum value of 1 :
How do I adjust this error? Do I need to transform the data or do I have to adjust the bins of the histogram?
My R code:
dataSample = read.table("sample6.txt", fill = TRUE)
sampleMatrix = as.matrix(dataSample)
sampleVector = as.vector(sampleMatrix)
h = hist(sampleVector, plot=F)
x =c(min(sampleVector, na.rm=T), max(sampleVector, na.rm=T))
ylim = range(0, max(get("density", h), max(density)))
hist(sampleVector, prob = T, col = "lightgreen", xlim = x,
ylim = ylim, main = "Histogram of data sample", xlab = "sample", ylab = "density")
This is my data sample:
0.5604785 0.0231508 0.2715692 0.2464922 0.2743465
0.434444 0.1779845 1.163666 0.5195378 0.08565649
0.2003622 0.3372351 0.02383633 0.2765776 0.1596984
0.3688299 0.2727399 0.3578011 0.4405475 0.07207568
0.424764 1.406219 1.12157 2.170512 0.6944183
2.429551 0.889546 0.1930762 0.579666 0.06834702
0.03690897 0.391838 1.019549 0.272865 0.1993042
0.02951076 0.3739699 0.2612313 1.988982 1.100386
0.9509101 1.978394 0.2469858 0.1256963 1.645895
0.1024105 0.336701 0.1322722 0.3881196 1.152153
0.6207026 1.506684 0.2826296
Thanks in advance!
I know there are strong opinions about mixing plot types in the same figures, especially if there are two y axes involved. However, this is a situation in which I have no alternative - I need to create a figure using R that follows a standard format - a histogram on one axis (case counts), and a superimposed line graph showing an unrelated rate on an independent axis.
The best I have been able to do is stacked ggplot2 facets, but this is not as easy to interpret for the purposes of this analysis as the combined figure. The people reviewing this output will need it in the format they are used to.
I'm attaching an example below.
Any ideas?
For etiquette purposes, sample data below:
y1<-sample(0:1000,20,rep=TRUE)
y2<-sample(0:100,20,rep=TRUE)
x<-1981:2000
I feel your pain - have had to recreate plots before. even did it in SAS once
if it's a once off, I'm be tempted to go old-school. something like this:
# Generate some data
someData <- data.frame(Year = 1987:2009,
mCases = rpois(23, 3),
pVac = sample(55:80, 23, T))
par(mar = c(5, 5, 5, 5))
with(someData, {
# Generate the barplot
BP <- barplot(mCases, ylim = c(0, 18), names = Year,
yaxt = "n", xlab = "", ylab = "Measles cases in Thousands")
axis(side = 2, at = 2*1:9, las = 1)
box()
# Add the % Vaccinated
par(new = T)
plot(BP, pVac, type = "l", ylim = c(0, 100), axes = F, ylab = "", xlab = "")
axis(side = 4, las = 1)
nudge <- ifelse(pVac > median(pVac), 2, -2)
text(BP, pVac + nudge, pVac)
mtext(side = 4, "% Vaccinated", line = 3)
par(new = F)
})
Try library(plotrix)
library(plotrix)
## Create sample data
y2<-sample(0:80,20,rep=TRUE)
x2<-sort(sample(1980:2010,20,rep=F))
y1<-sample(0:18,20,rep=TRUE)
x1<-sort(sample(1980:2010,20,rep=F))
x<-1980:2010
twoord.plot(x1,y1,x2,y2,
lylim=c(0,18),rylim=c(0,100),type=c("bar","l"),
ylab="Measles Cases in thousands",rylab="% Vaccinated",
lytickpos=seq(0,18,by=2),rytickpos=seq(0,100,by=10),ylab.at=9,rylab.at=50,
lcol=3,rcol=4)
I am running following code from help files of VGAM:
library(VGAM)
fit4 <- vgam(BMI ~ s(age, df = c(4, 2)), lms.bcn(zero = 1), data = bmi.nz, trace = TRUE)
qtplot(fit4, percentiles = c(5,50,90,99), main = "Quantiles", las = 1, xlim = c(15, 90), ylab = "BMI", lwd = 2, lcol = 4)
How can I just prevent putting points on the plot so that the graph shows only percentile curves? Is there some option in qtplot where I can suppress points on this graph, so that I do not need to resort to long ggplot route as done on this page: Percentiles from VGAM ? In my earlier question there were other issues also so this point got ignored. Thanks for your help.
There is no qtplot help page so I went to the package help Index and saw qtplot.lmscreg listed. It had a 'pcol.arg' to control points color so I set it to "transparent":
qtplot(fit4, percentiles = c(5,50,90,99), main = "Quantiles", las = 1,
xlim = c(15, 90), ylab = "BMI", lwd = 2, lcol = 4,
pcol.arg="transparent")