如何修改R语言Biodiversity包中accumcomp函数的绘图形状?
accumcomp Function It looks like the error you're seeing happens because the accumcomp function internally specifies the pch parameter when calling its underlying plotting function (accumplot), and your custom pch=c() passed via the ... argument conflicts with this pre-set value—hence the "multiple actual arguments" error.
Here are two practical solutions to fix this and match your manuscript's plot style:
Solution 1: Calculate First, Plot Manually (Most Straightforward)
First, run accumcomp without generating the plot, then use the resulting data to build your plot with full control over point shapes:
# Step 1: Compute the accumulation curve data, skip plotting accum_data <- accumcomp(fungi, y=fungi.env, factor='Stand.Composition', method='exact', legend=TRUE, conditioned=TRUE, ylim=c(0,50), xlim=c(0,110), xlab="Seedlings", ylab="Species richness", rainbow=FALSE, labelit=FALSE, plotit=FALSE) # Step 2: Plot using accumplot with custom pch values accumplot(accum_data, xlab="Seedlings", ylab="Species richness", xlim=c(0,110), ylim=c(0,50), rainbow=FALSE, labelit=FALSE, pch=c(16, 17)) # Replace with your desired point codes (e.g., 1=circle, 17=triangle)
This bypasses the internal pch assignment in accumcomp and lets you specify exactly what shapes you want.
Solution 2: Modify the accumcomp Function Source (For Repeated Use)
If you need to use this custom styling regularly, you can tweak the accumcomp function to respect your pch input:
- First, view the function's source code to find where
pchis hardcoded:
print(accumcomp)
2.Look for the line where accumplot is called inside accumcomp—it will likely have something like:
accumplot(result1, addit = addit, xlab = xlab, ylab = ylab, xlim = xlim, ylim = ylim, type = type, pch = 1:length(levels(factor)), ...)
- Replace that section with code that checks for your custom
pchfirst, falling back to the default if none is provided:
# Check if user provided pch; use default if not custom_pch <- list(...)$pch if (is.null(custom_pch)) { custom_pch <- 1:length(levels(factor)) } # Call accumplot with the resolved pch value accumplot(result1, addit = addit, xlab = xlab, ylab = ylab, xlim = xlim, ylim = ylim, type = type, pch = custom_pch, ...)
- Re-define the modified
accumcompfunction in your R environment. Now you can call it directly withpch=c()like you originally tried:
accumcomp(fungi, y=fungi.env, factor='Stand.Composition', method='exact', legend=TRUE, conditioned=TRUE, ylim=c(0,50),xlim=c(0,110), xlab="Seedlings",ylab="Species richness",rainbow=FALSE,labelit=FALSE, pch=c(16,17))
内容的提问来源于stack exchange,提问作者Natalie Scott

