You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改R语言Biodiversity包中accumcomp函数的绘图形状?

How to Customize Point Shapes in Biodiversity Package's 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:

  1. First, view the function's source code to find where pch is 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)), ...)
  1. Replace that section with code that checks for your custom pch first, 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, ...)
  1. Re-define the modified accumcomp function in your R environment. Now you can call it directly with pch=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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 10:18:02