I want to make a plot of my samples and assign a different symbol according to the type of species it is. The packages that I have used are: library(vegan) library(reshape2) The scripts that I have made for the graph have been: starting from an extract of the dataframe that has
Datraframe
Site Date Habitat Season Year Taxa
Q1F 08_09_2015 Oak Autumn 2015-2016 Adonis_flammea
E2F 08_09_2015 Oak Autumn 2015-2016 Agrimonia_eupatoria
Q4F 08_09_2015 Oak Autumn 2015-2016 Ajuga_chamaepitys
L1P 08_09_2015 Oak Autumn 2015-2016 Ajuga
I convert it to an array:
Matrix_Rawdata<-acast(Datos,Site~Taxa,fill = 0 )
Matrix_Rawdata<-data.frame(Matrix_Rawdata)
The Matrix_Rawdata dataframe is as follows: dput(head(Matrix_Rawdata))
Adonis_flammea Agrimonia_eupatoria Ajuga_chamaepitys Ajuga
Q1F 1 0 0 0
E2F 0 1 0 0
Q4F 0 0 1 0
L1P 0 0 0 1
and another dataframe called Site, which has:
Plot Group
Q1F 1
E2F 2
Q4F 1
L1P 3
I try to plot it using these scripts:
DCA.Rawdata <- decorana(Matrix_Rawdata)
plot(DCA.Rawdata,
choices = c(1, 2),
origin = TRUE,
display = "sites",
type = "n",
cex = 0.5,
main = "Raw Data",
xlab = "DCA1 (0.353)",
ylab = "DCA2 (0.247)")
points (DCA.Rawdata, col = Site$Group, pch = Site$Group)
but the pch part of the points script gives me this error:
Error in plot.xy(xy.coords(x, y), type = type, ...) : símbolo de gráfico inválido
Could you tell me where is my mistake?
Adrián, I think that the problem, as I told you, has to do with the data type of
Site$Group
, possibly it isfactor
a data that is not one of those that are allowed for the parameterpch
. You could avoid the error by doing:In this way you force the factor to become an integer which is "mapped" to one of the available graphic symbols, or you can force the data to a character, by means
pch = as.character(Site$Group)
of , in which case that value will be drawn.