I can't get this plot to work

Here is my data:

image

Here is my code and I can't seem to find what's wrong.

library(lattice)
xyplot(ChangeBPM ~ Gender, data=Data, group=Cigaretts.smoked, type=c("p","a"), auto.key=TRUE)
aggregate(ChangeBPM ~ Cigaretts.smokedGender, data=Data, mean)
summary(aov(ChangeBPM ~ Cigaretts.smoked
Gender, data=Data))

Here is my error message:

xyplot(ChangeBPM ~ Gender, data=Data, group=Cigaretts.smoked, type=c("p","a"), auto.key=TRUE)
Error in eval(substitute(groups), data, environment(x)) :
object 'Cigaretts.smoked' not found

Is the headings in cigarettes smoked wrong? is it a "." ? or is it the group part

Thanks :slight_smile:

Without a reproducible example, it's hard to say for sure.

Check the names of your data frame

What is the output from?

names(Data)

The name of your grouping parameter should be drawn from that. If the name of your grouping var has spaces, wrap it in backticks, e.g. group=`My Color Group`

Why isn't the data showing, here is the code and the error message, thanks

xyplot(ChangeBPM ~ Gender, data=Data, group=CigaretteType, type=c("p","a"), auto.key=TRUE)
aggregate(ChangeBPM ~ CigaretteTypeGender, data=Data, mean)
summary(aov(ChangeBPM ~ CigaretteType
Gender, data=Data))

Screen Shot 2020-01-21 at 10.58.51 am|658x106
Screen Shot 2020-01-21 at 10.59.01 am !

Very likely the problem is with the structure of your dataset, that is why people are asking you to show your variable names, a better option would be for you to provide sample data on a copy/paste friendly format or, ideally, a proper reproducible example illustrating your issue as explained in this guide

I was making a quick Reprex while andresrcs was posting. The following shows your plot code working with a data set similar to what you posted. If this example does not help you solve your problem, please make a Reprex as has been suggested.

ChangeBPM <- c(-2,2,1,-2,0,0,0,0,1,-1,-2,-2,-3,2,0,-1,0,-1,-1,-1,0,0,-2,-1,-2,-1,1,-1,-1,-1)
Cigaretts.smoked <- c(rep("C", 10), rep("M", 10), rep("N", 10))
Gender <- rep(c("F", "M"), 15)
Data <- data.frame(Cigaretts.smoked, ChangeBPM, Gender)
library(lattice)
xyplot(ChangeBPM ~ Gender, data=Data, group=Cigaretts.smoked, type=c("p","a"), auto.key=TRUE)

Created on 2020-01-20 by the reprex package (v0.3.0)

here is my code:

Data$Change = Data$BPMbefore - Data$BPMafter
xyplot(Change ~ Gender, data=Data, group=CigaretteType, type=c("p","a"), auto.key=TRUE)
aggregate(Change ~ CigaretteTypeGender, data=Data, mean)
summary(aov(Change ~ CigaretteType
Gender, data=Data))

here is my error message:

Screen Shot 2020-01-21 at 11.19.57 am

here is my output, i cant get the data to show up:

Screen Shot 2020-01-21 at 10.59.01 am

thanks :slight_smile:

Where is your sample data? we can't reproduce your issue without data so that is not a reprex.

Provide Data

Try copy pasting the output of the following into a post here.

dput(head(Data, 20))

That should give people twenty rows of the data set that they can use to reproduce what you're experiencing.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.