Hildrun Walter
Hildrun Walter

Reputation: 27

Why does there occur an a in my legend color boxes? (pie charts using coord_polar() and facet_wrap() )

I've created pie charts using geom_bar() and coord_polar(). Finally, I've got my graph as I wanted it besides of this:

There occurs an letter (a small "a") in my legend boxes and I don't know why. How can I avoid this?

Here's my data:

table.connexuniv.location
df.connexuniv.location <- data.frame(
          location = factor( rep(c("university", "cinema"),each=4), levels=c("university", "cinema")),
          uniconnex = factor(rep(c("study", "work", "no connex", "no indication"), 2), levels=c("study", "work", "no connex", "no indication")),
          amount = c(33,15,8,6,3,3,24,3),
          percentage = c(53,24,13,10,9,9,73,9)
        )
df.connexuniv.location


df.connexuniv.location <- df.connexuniv.location %>%
  group_by(location) %>%
  mutate(pos=cumsum(percentage) - 0.5*percentage)
head(df.connexuniv.location)

uniconnex <- rep(c("study", "work", "no connex", "no indication"), 2)

And here's my code for the pie charts:

ggplot(df.connexuniv.location, aes(x="", y=percentage, group=factor(uniconnex, levels=uniconnex, labels=uniconnex), 
                                   color=uniconnex,fill=uniconnex)) + 
  geom_bar(width=1, stat="identity")  +
  coord_polar("y", start=0, direction=-1) + facet_wrap(~location) +
  scale_fill_manual(values=rep(c("grey20","grey60", "grey90","grey99"),2),name = "Connection to university", labels=uniconnex) +
  scale_color_manual(values=rep(c("grey20"),8),name = "Connection to university") +
  labs(color = "Connection to university", shape = "Connection to university", x=" ", y="percentage of audience") +
  theme(panel.border = element_rect(linetype = "solid", colour="black", linewidth=.5, 
                                 fill = NA), 
        panel.background=element_rect(fill="grey97"), 
        strip.background = element_rect(colour = "black", fill = NA, size = .5), 
        axis.text.x = element_blank(),
        axis.ticks = element_blank(),
        panel.grid  = element_blank()) +
  geom_text(aes(x = 1.7, label = paste0(round(percentage, digits=0), " %")), size=3, 
      position = position_stack(vjust = 0.5))

enter image description here

It would be great if you could give me some advice.

Upvotes: 0

Views: 24

Answers (0)

Related Questions