I have a dataset comprising participants binary answers to certain questions. This questions can have 3 different base conditions, and one 0/1 variation; that is, questions can be designated as 1.0, 1.1, 2.0,... and 3.1. My dataset holds each answer in a different row, including a column for the base condition and one for the modifier (plus an interaction column determining the combinations; see the example below).
What I would like to plot are the proportions of answers for each question, preferentially grouped by basic levels: i.e. three 2-bars groups showing the frequency of a certain outcome.
Here's a reproducible example dataset to work on, where Base_con
, Var
, and Dec
represent the base condition, the variation, and the decision (answer), respectively:
# load example dataset with relevant columns
require(RCurl)
my_csv = getURL(
"https://docs.google.com/spreadsheets/d/1x9PUZwPGmye6QDk7_4M_HslrmbgEC3DZ-v-VMvFkE6U/pub?output=csv")
df1 = read.csv(textConnection(my_csv))
# set columns as factors because they are numerically coded
df1$Base_con = as.factor(df1$Base_con)
df1$Var = as.factor(df1$Var)
df1$Dec = as.factor(df1$Dec)
df1$Int = interaction(df1$Base_con, df1$Var)
I have seen that the cdplot
function does something very close to what I am looking for, but only accepts one continuous independent variable. I hope someone can help with this, it does not look as something very difficult to do, but I haven't found an answer here or elsewhere. I know I could build the graph in other software but I would prefer to learn to do it in R, and moreover it would help me to check the data along with the statistical analysis.