0

I am building plot using ggplot2 and trelliscope packages in R:

Sample data:

name=letters[1:26]
avg_rating=sample(1:10,26, replace=TRUE)
position <- toupper(name[sample(1:9, size = 26, replace=TRUE)])
club <- "inter"
df=data.frame(name, avg_rating, position, club)

Plot:

plot1 <- ggplot(data1, aes(x=name, y=avg, fill=pos))+
  geom_bar(stat="identity")+
  theme(legend.position = "right")+
  ylim(-5,10)+
  coord_polar(start=0)+
  facet_trelliscope(~club, nrow = 4, ncol = 5, scales = "free_x")

Problem is the trelliscope facet only allows me to either include legend to all the subplots (as with the code above) or not include at all (legend.position = "null"). I would like to include only one legend for all the subplots as it is the same for all of them and I can save a lot of space. Is there a way to do this?

Pawels
  • 192
  • 2
  • 12
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 25 '22 at 19:49
  • @MrFlick I added some sample dataframe for reproduction. The only difference is that in full dataset I have more clubs. Therefore there will be more sublpots and I would like to have just one common legend for all of them. – Pawels Jan 26 '22 at 16:10

0 Answers0