make a dotplot of differences in variables

48 Views Asked by At

I cant figure out how to plot the difference between two variables, female and male, I want to make a dotplot of female - male.

my attempts so far are:

MyData$earn_diff <- MyData$female - MyData$male
gf_point( ~(female - male), data=MyData)
gf_point( ~(myData$female - myData$male)

both plots resulted in Error: Invalid formula type for gf_point.

1

There are 1 best solutions below

0
On

The issue is that ggformula::gf_point provides a formula interface for geom_point and hence requires both an x and a y aesthetic aka a two sided formula, using 1 ~ ... or factor(1) ~ ... will do:

library(ggformula)

gf_point(~ mpg - hp, data = mtcars)
#> Error: Invalid formula type for gf_point.

gf_point(factor(1) ~ mpg - hp, data = mtcars)