Unsure how to code this into R



I have a large data set in R which I am currently analysing. I'm trying to plot confounding variables and have one which considers the patients household equipment (2=none, 1= stove, 3= charcoal).

How would I tell R to make a graph which considers each of these categories, so I want to correlate malaria ("Malaria...giemsa") against each of the household equipment.

I basically want to see if there are higher counts for malaria if the patient has no household equipment, than if they had a stove/ charcoal etc.

Any suggestions on how to code this into R?


You might take a look at Michael Friendly's guide: Working with categorical daa with R with the vcd and vcdExtra packages, which will take you through several options.

Another guide to Contingency tables in R here:


Maybe you're looking for faceting?

data(Cars93, package = "MASS")
ggplot(data = Cars93, aes(MPG.city, Horsepower)) +
  geom_point() +
  facet_wrap( ~ Origin)

The generic format is:

ggplot(df, aes(x, y)) +
  geom_point() +
  facet_wrap( ~ f)

where df is your data frame, x and y are your data field for the x and y fields and f is a factor (or character) field that defines the facets.

Created on 2019-01-10 by the reprex package (v0.2.1)


Here is an interesting answer on Stack Exchange that explains why you can't get correlation between continuous and categorical variables, and gives you another analogous measures of strength of association with examples in R.

closed #5

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.