I have a variable.A in a dataset:
variable.A = c('Dem', 'Rep', 'Ind', 'NA')
My objective: I want to plot the means from another variable (variable.X) for 1) 'Dem', 2) 'Rep' and 3) the whole sample (so 'Dem' + 'Rep' + 'Ind').
My first step is to filter out the 'NA' elements in variable.A:
new_dataset = dataset %>%
filter(variable.A != 'NA')
Next, I create a bar plot for both variables using the ggplot command:
ggplot(new_dataset, aes(x=variable.A, y=variable.X)) +
stat_summary(aes(y = variable.X),
fun = mean, na.rm = TRUE,
geom = "bar",
size = 3)
It plots the means for all three group elements. Here is an image of the plot output:

My questions now are:
- How can I remove group element 'neutral' from the bar plot?
- How can I, in addition to plotting the mean for 'Dem' and 'Rep', create a third group in the bar plot (let's call it 'sample.mean'), that represents the mean to variable.X for the entire sample ('Dem' + 'Rep' + 'Ind')?
Thanks for any help!
