0

I'm currently trying to figure out how to add frequency percentages with ggplot. The data frame is 2x2 and I'm trying to visualize one of my CrossTables. Here's the code I have:

ggplot(Tatt_by_Lineup_Data_Frame, aes(x = Tatt.in.Any, y = Freq, fill = Lineup.Condition)) +
  geom_col(position = "dodge") +
  labs(title = "Memory for a Tattoo by Lineup Condition") +
  theme_classic() +
  scale_fill_manual(values=c("#008080", "#004D4D"))

I don't know where/how to insert the frequency %. I've added an image so you can see what my current viz looks like. Thank you in advance!

enter image description here

R Version 4.1.2 (2021-11-01) "Bird Hippie"

I've tried looking it up online but I can't seem to find exactly what I'm looking for. I've tried this code, which I found from another website, but it just returns "Error in sum(x) : invalid 'type' (closure) of argument". I don't know if this is even the right way to do it but it's what I've tried.

ggplot(Tatt_by_Lineup_Data_Frame, aes(x = Tatt.in.Any,
                                            y = prop.table(stat(count)),
                                            fill = Lineup.Condition),
                                            label = scales::percent(prop.table(stat(count)))) +
  geom_col(position = "dodge") +
  scale_y_continuous(labels = scales::percent) +
  labs(title = "Memory for a Tattoo by Lineup Condition", 
       x = "Report of Tattoo", 
       y = "Frequency", 
       fill = "Lineup Condition") +
  theme_classic() +
  scale_fill_manual(values=c("lightgreen", "darkgreen"))
  • It helps reproduce the problem when the post includes a data set. An effective way to include one is `dput()`. Run dput, then paste the output into your question. See [rdocumentation](https://www.rdocumentation.org/packages/base/versions/3.6.2/topics/dput). If your object is a vector, matrix, table, or data frame and is large, `object |> head() |> dput()` will help give manageably sized output. – Isaiah Oct 29 '22 at 08:13

0 Answers0