R plotting proportions problem - ggplot making plot that looks like a table

79 views Asked by At

I am trying to make a plot of proportions of a binomial distribution (yes/no) depending on one ordinal and one continuous variable. Somehow when including the continuous one as color of the dots the appearance of the plot radically changes. Can someone help me with how to include the third variable without having the plot turn into below table-looking result?

Code as follows:

#making table with proportions of people who switch (1),
## after arsenic level and education.

educ_switch <- prop.table(table(welldata$educ[welldata$switch==1],
                                welldata$arsenic[welldata$switch==1],  
                                welldata$switch[welldata$switch==1]))
educ_switch <- as_data_frame(educ_switch, make.names=TRUE)

#remove observations where the proportion is 0

educ_switch1 <- educ_switch[which (educ_switch$proportion>0),]
p <- ggplot(educ_switch1, aes(x = educ, y=proportion))

If I do p + geom_point()

I get the following picture:

ggplot with overlapping points

But when I try to distinguish the third variable by coloring it with p + geom_point(aes(colour = arsenic))

I get this weird looking thing instead:

ggplot, only legend visible

0

There are 0 answers