I hope I can explain this correctly... basically, what Im trying to do is to remove points on a grid where there is no data... but the issue is, Im trying to do this with 2 factors!
Hopefully I can explain more clearly below.
To begin I have 2 factors drink
and food
, as shown below. Then I'm creating a grid (which im using to calculate something else) but I'm trying to remove 'points' from the grid where there is no data... for example:
drink = as.factor(c("A","A","A","A","A","A","A","A","A","A","A","B"))
food = as.factor(c('pizza','pizza','pizza','fries','fries','taco','taco','pizza','taco','pizza','taco','fries'))
# looking at a contingency table
table(drink, food)
> food
drink fries pizza taco
A 2 5 4
B 1 0 0
Now Im creating the grid that spans the entire range of the data like so:
# create the grid
gridvals1 <- levels(drink)
gridvals2 <- levels(food)
gridvalsNew <- expand.grid(gridvals1, gridvals2)
If we plot the data and the grid side-by-side, we can see that the grid covers area where there is no data:
par(mfrow=c(1,2))
plot(drink, food)
plot(gridvalsNew)
What Im trying to do is resize the grid so it removes the area where there is no data (i.e., where the count iz zero) . But I cant figure it out.