Using group argument in aes() in ggplot2

melbez

I am trying to use the "group" argument in aes() in ggplot2, and I am not sure why it is not working as I currently have it.

I would like an image that groups my "maskalthalf" variable in the way that this image uses "sex" (found here).

enter image description here

This is what my graph currently looks like.

enter image description here

This is the code I have so far.

ggplot(groups, aes(x = message, y = mean, group = factor(maskalthalf))) + 
  geom_bar(stat = "identity", width = 0.5, fill = "003900") +
  geom_text(aes(label = round(mean, digits = 1), vjust = -2)) + 
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = .2, position = position_dodge(.9)) + 
  labs(title = "Evaluations of Personal and General Convincingness") + 
  ylab("Rating") + 
  xlab("Personal evaluation or general evaluation") + 
  ylim(0, 8)

This is a sketch of what I am aiming for:

enter image description here

Data:

structure(list(maskalthalf = c("High", "High", "Low", "Low"), 
    message = c("General", "Personal", "General", "Personal"), 
    mean = c(4.79090909090909, 6.38181818181818, 4.69879518072289, 
    4.8433734939759), se = c(0.144452868727642, 0.104112130946133, 
    0.149182255019704, 0.180996951567937)), row.names = c(NA, 
-4L), groups = structure(list(maskalthalf = c("High", "Low"), 
    .rows = structure(list(1:2, 3:4), ptype = integer(0), class = c("vctrs_list_of", 
    "vctrs_vctr", "list"))), row.names = 1:2, class = c("tbl_df", 
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"))
neilfws

The image in your first example uses facets to group by variable. So you could try that:

ggplot(df1, aes(x = message, y = mean)) + 
  geom_col(width = 0.5, fill = "003900") +
  geom_text(aes(label = round(mean, digits = 1), vjust = -2)) + 
  geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = .2, position = position_dodge(.9)) + 
  labs(title = "Evaluations of Personal and General Convincingness") + 
  ylab("Rating") + 
  xlab("Personal evaluation or general evaluation") + 
  ylim(0, 8) +
  facet_wrap(~maskalthalf)

enter image description here

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Using colors in aes() function in ggplot2

From Dev

latest version of ggplot2 creating issue with aes argument

From Dev

Different between colour argument and aes colour in ggplot2?

From Dev

What does group do in the aes parameter of ggplot2

From Dev

Using override.aes() in ggplot2 with layered symbols (R)

From Dev

setting trasparency in ggplot2 using aes_color_fill

From Dev

Problems when using ggplot aes_string, group, and linetype

From Dev

Single legend when using group, linetype and colour in ggplot2?

From Dev

How to group by month, quarter or year using ggplot2

From Dev

Single legend when using group, linetype and colour in ggplot2?

From Dev

How to group by month, quarter or year using ggplot2

From Dev

colors for two geom_point() in ggplot2 when using aes_string

From Dev

ggplot2: Using `fill = …` in aes(..) and geom_bar(..). The colors repeat

From Dev

ggplot2 with fill and group

From Dev

lend argument equivalent for ggplot2?

From Dev

ggplot2() bar chart fill argument

From Dev

Using Table to Group: invalid 'type' (character) of argument

From Dev

Using aes_ instead of aes_string for ggplot

From Dev

How to pass chosen input values of checkboxGroup to be used as an argument in ggplot2 interaction of geom_col() when using shiny?

From Dev

ggplot: geom_text with group argument for positioning

From Dev

Hodogram using ggplot2

From Dev

Multiplot using ggplot2

From Dev

Graphs using ggplot2

From Dev

Multiplot using ggplot2

From Dev

Plot using ggplot2

From Dev

ggplot2 - Overlay Mean of Each Group

From Dev

Group similar factors - fills ggplot2

From Dev

ggplot2 color gradient per group

From Dev

ggplot2 - Overlay Mean of Each Group

Related Related

HotTag

Archive