0

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?

J Phelps
  • 1
  • 1
  • 3
    where exactly does the error occur? Does the first plot work? If you provide the data you are more likely to receive helpul assistance. (`dput(mydata)`) – dandrews Mar 23 '23 at 16:39
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input that can be used to test and verify possible solutions. – MrFlick Mar 23 '23 at 16:39
  • I added my dataset – J Phelps Mar 23 '23 at 17:35

0 Answers0