-1

I am trying to create a bar graph in ggplot, I'm not getting an error, and the labels are all showing but the inside of the graph is completely blank - the bars just aren't there. I first tried filtering the two variables I was interested in for specific levels. I'm not sure if that's where my mistake is? I didn't get an error though, so it might be something else. This is my code. Hope you can help.

I'm just adding some data below the R code for my bar chart - sorry, not done this before, not sure if this is too much data. And hope I've included it in the correct format?

 gest %>%
  select(yForm3, gestBROAD) %>% 
  filter(yForm3 == "nominal" | yForm3 == "verbal"| yForm3 =="other", gestBROAD 
             == "iconic" | gestBROAD == "enact")%>%
  #drop_na(gestBROAD) %>%
  ggplot(aes(yForm3, fill=gestBROAD))+ 
  geom_bar(position ="dodge")+
  theme_bw()+
  labs(title="Enactment vs. Iconic Gestures", subtitle = "by form",
       x="Form", y="count", fill="",
       caption="")+
  scale_fill_manual(values=met.brewer("Cassatt1", 2)) 

    structure(list(yForm3 = c("verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "zero", "verbal", "verbal", "verbal", "verbal", 
"other", "verbal", "verbal", "verbal", "verbal", "nominal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "zero", 
"verbal", "verbal", "verbal", "other", "other", "verbal", "verbal", 
"verbal", "verbal", "other", "verbal", "verbal", "other", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"other", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "nominal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "nominal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "other", "zero", 
"nominal", "other", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "other", "verbal", "other", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "nominal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "nominal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"other", "other", "zero", "other", "pers_pronominal", "nominal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "other", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"verbal", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"zero", "verbal", "verbal", "verbal", "verbal", "verbal", "verbal", 
"other", "zero", "other", "other", "other", "nominal", "nominal", 
"pers_pronominal", "zero", "zero", "other", "zero", "other", 
"zero", "other", "zero", "other", "nominal", "nominal", "nominal", 
"nominal", "nominal", "pers_pronominal", "pers_pronominal", "nominal", 
"zero", "verbal", "verbal", "other", "nominal", "other", "other", 
"other", "verbal", "nominal", "nominal", "nominal", "verbal", 
"verbal", "verbal", "pers_pronominal", "verbal", "verbal", "verbal", 
"nominal", "other", "verbal", "verbal", "nominal", "pers_pronominal", 
"other", "other", "other", "other", "other", "other", "other", 
"other", "other", "nominal", "other", "other", "other", "nominal", 
"nominal", "other", "zero", "other", "other", "nominal", "verbal", 
"nominal", "other", "nominal", "nominal", "nominal", "verbal", 
"nominal", "other", "verbal", "other", "verbal", "other", "nominal", 
"other", "verbal", "verbal"), gestBROAD = c("Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Enact", "Enact", 
"Enact", "Enact", "Enact", "Enact", "Enact", "Iconic", "Iconic", 
"Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", 
"Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", 
"Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", 
"Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", 
"Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", 
"Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", 
"Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", 
"Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", "Iconic", 
"Iconic")), row.names = c(NA, -500L), class = c("data.table", 
"data.frame"), .internal.selfref = <pointer: 0x0000018e3d886e90>)

Here is my blank bar chart: my blank blot

maro
  • 63
  • 6
  • 3
    Without a snippet of your data to run and check your code one can only guess. But from your description of the issue my first guess would be that your filtered data does not contain any observations. Hence I would check that. For more help I would suggest to provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. – stefan Dec 03 '22 at 08:09
  • sidenote: you can test the existence of an element in set of choices with the `%in%` operator: `yForm3 == "foo" | yForm3 == "bar" | yForm3 == "baz"` etc. becomes `yForm3 %in% c("foo", "bar", "baz")` etc. – I_O Dec 03 '22 at 12:38
  • To check if stefan is right, look at `table(gest$yForm3)` and `table(gest$gestBROAD)` to see if the values in your `filter()` argument are actually there. – jrcalabrese Dec 03 '22 at 14:53
  • I voted to close this as non-reproducible based on the typo @jrcalabrese points out (you have "Enact" and "Iconic" but filter for "enact" and "iconic", so your filter returns nothing). Because that reason was in the minority, it doesn't show up in the banner at top – camille Dec 05 '22 at 21:33

1 Answers1

1

R is a case-sensitive language. Because you used "iconic" instead of "Iconic" in your filter argument, it was filtering out everything from the variable gestBROAD.

library(tidyverse)
library(MetBrewer)

table(gest$gestBROAD)
#> 
#>  Enact Iconic 
#>    441     59

gest %>%
  select(yForm3, gestBROAD) %>% 
  filter(yForm3 == "nominal" | yForm3 == "verbal"| yForm3 =="other", 
         gestBROAD == "Iconic" | gestBROAD == "Enact") %>% # now capitalized
  #drop_na(gestBROAD) %>%
  ggplot(aes(yForm3, fill = gestBROAD))+ 
  geom_bar(position ="dodge")+
  theme_bw()+
  labs(title="Enactment vs. Iconic Gestures", subtitle = "by form",
       x="Form", y="count", fill="",
       caption="")+
  scale_fill_manual(values=met.brewer("Cassatt1", 2)) 

enter image description here

jrcalabrese
  • 2,184
  • 3
  • 10
  • 30
  • If the issue is just a capitalization mistake, it's better to vote to close the question as non-reproducible instead of answering it – camille Dec 05 '22 at 21:31