Hi,
I am trying to use Maxent to do some species distribution mapping using 10 predictor variables (9 continuous and 1 categorical). When I import my categorical raster into R, it treats it as continuous. I am including the factors argument in the model to indicate that variable should be treated as categorical, but when I look at the responses curves, the output for this variable is a line graph rather than a bar graph.
mod = maxent(x=pred.vars, p=pb, factors = "Soiltext",
args=c("hinge",
"threshold=FALSE",
"noautofeature",
"noremoveduplicates",
"-P","-J",
"writeplotdata",
"outputformat=logistic",
"threads=4",
"randomseed=FALSE"),
path=paste("S:/Thesis_Chapter_1/data/Output/Maxent/species")) ## folder for maxent output;
I've tried setting the raster as a factor after I import and this appears to work. However, I get an error when I try to plot it, and it still seems to be getting treated as a continuous variable in the model (i.e. response curve is still a line graph, not a bar graph).
> # Set soil raster layer as a factor (categorical variable)
> Soiltext.f <- asFactor(Soiltext)
> # Check soil is set to factor
> is.factor(Soiltext.f)
[1] TRUE
> plot(Soiltext.f)
Error in .checkLevels(levels(x)[[1]], value) :
the first column name of the raster attributes (factors) data.frame should be "ID"
> structure(Soiltext.f)
class : RasterLayer
dimensions : 2270, 3252, 7382040 (nrow, ncol, ncell)
resolution : 250, 250 (x, y)
extent : 2126684, 2939684, 2259553, 2827053 (xmin, xmax, ymin, ymax)
crs : +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +units=m +no_defs
source : S:/SEFS Research Data/Restricted/Fire Ecology & Biodiversity/Students/PhD/Current/Sarah/Thesis_Chapter_1/data/Soil Texture/soil_text_v4_clip3.tif
names : soil_text_v4_clip3
values : 1, 7 (min, max)
attributes :
VALUE
from: 1
to : 7
Any suggestions for how I can fix this issue?
many thanks,
Sarah