I am using this code to make a scatter plot with data organized by species:
(dput([winglength v weight melitaeini sex use.csv][1]))
plot(chlosyne.janis$total.weight..mg.[chlosyne.janis$sex == "female"],
chlosyne.janis$forewing.length..mm.[chlosyne.janis$sex == "female"],
col = "red",
pch = 16,
xlim = c(0, 30),
ylim = c(0, 30),
xlab = "weight (mg)",
ylab = "forewing length (mm)",
main = "Reltaionship of weight to forewing length in the genus Chlosyne")
points(chlosyne.janis$total.weight..mg.[chlosyne.janis$sex == "male"],
chlosyne.janis$forewing.length..mm.[chlosyne.janis$sex == "male"],
col = "red",
pch = 17)
points(chlosyne.erodyle$total.weight..mg.[chlosyne.erodyle$sex == "female"],
chlosyne.erodyle$forewing.length..mm.[chlosyne.erodyle$sex == "female"],
col = "red",
pch = 16)
points(chlosyne.hippochrome$total.weight..mg.[chlosyne.hippochrome$sex == "male"],
chlosyne.hippochrome$forewing.length..mm.[chlosyne.hippochrome$sex == "male"],
col = "red",
pch = 17)
points(c.acastus.neumoegenio$total.weight..mg.[c.acastus.neumoegenio$sex == "male"],
c.acastus.neumoegenio$forewing.length..mm.[c.acastus.neumoegenio$sex == "male"],
col = "red",
pch = 17) `
but the result is this error:
Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ
Both the x
and y
variables are numeric, and I have set both axis limits xlim
and ylim
to c(0, 30)
, so that both axes have the same length.
The plot will not run even if I do not run the rest of the points.
I have tried changing and even unsetting xlim
and ylim
, but the error remains. How should I change the code to generate the scatter plot without errors?