R barplot nearby and stacked

I am trying to create a barplot that uses and folds at the same time. I have something similar to what I want with a line:

Similar to the searched feature

tmp <- morley
tmp$loc <- paste("No", tmp$Run %/% 2, sep="")
tmp$group <- as.logical(tmp$Run %% 2)
tmp$year <- tmp$Expt + 2000
tmp$value <- tmp$Speed
tmp <- subset(tmp, loc %in% c("No1", "No2", "No3"))

ggplot(tmp, aes(x=loc, y=value, fill=group)) + 
  geom_bar(stat ='identity', position ='stack') + 
  facet_grid (~year)

I would like that without faces and two legends (green: No1, Red: No2, Blue: No3 and TRUE: 0% transparency, FALSE 40% transparency) with years on the x axis, in some places the groups are combined. Also a legend with 6 inserts # 1 true, # 1 false, # 2 true ... will be fine.

Is there any way to do this?

+4
source share
1 answer
ggplot(tmp, aes(x=loc, y=value, fill=loc, alpha=group)) + 
  geom_bar(stat ='identity', position ='stack') +
  scale_alpha_manual(values=c('TRUE'=1, 'FALSE'=0.6)) +
  facet_grid(~year, switch='x') +
  theme(axis.title.x=element_blank(), strip.placement='outside')

And then customize the themes and fill in the scale accordingly.

enter image description here

+3
source

Source: https://habr.com/ru/post/1688897/


All Articles